salt/strip-trailing-commas-on-linux-user-gecos-fields.patch
Jochen Breuer 0aa0223de4 Accepting request 601028 from systemsmanagement:saltstack:testing
- Fix minion scheduler to return a 'retcode' attribute (bsc#1089112)
- Fix for logging during network interface querying (bsc#1087581)
- Fix rhel packages requires both net-tools and iproute (bsc#1087055)
- Added:
  * initialize-__context__-retcode-for-functions-handled.patch
- Modified:
  * fix-for-errno-0-resolver-error-0-no-error-bsc-108758.patch

                                                                                    
- Fix patchinstall on yum module. Bad comparison (bsc#1087278)
- Added:
  * provide-kwargs-to-pkg_resource.parse_targets-require.patch

                                                                                    
- Strip trailing commas on Linux user's GECOS fields (bsc#1089362)
- Fallback to PyMySQL (bsc#1087891)
- Improved test for fqdns
- Update SaltSSH patch
- Fix for [Errno 0] Resolver Error 0 (no error) (bsc#1087581)
  * Lintfix: PEP8 ident
  * Use proper levels of the error handling, use proper log formatting.
  * Fix unit test for reversed fqdns return data
- Added:
  * strip-trailing-commas-on-linux-user-gecos-fields.patch
  * fall-back-to-pymysql.patch
  * fix-for-errno-0-resolver-error-0-no-error-bsc-108758.patch
- Modified:
  * add-saltssh-multi-version-support-across-python-inte.patch

OBS-URL: https://build.opensuse.org/request/show/601028
OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=119
2018-04-30 12:06:44 +00:00

56 lines
2.3 KiB
Diff

From f9fb3639bb3c44babd92d9499bdde83a0a81d6ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
<psuarezhernandez@suse.com>
Date: Wed, 18 Apr 2018 12:05:35 +0100
Subject: [PATCH] Strip trailing commas on Linux user GECOS fields
Add unit tests for GECOS fields
---
salt/modules/useradd.py | 2 +-
tests/unit/modules/test_useradd.py | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/salt/modules/useradd.py b/salt/modules/useradd.py
index 545fe2a6f1..a61ba0e960 100644
--- a/salt/modules/useradd.py
+++ b/salt/modules/useradd.py
@@ -81,7 +81,7 @@ def _build_gecos(gecos_dict):
return '{0},{1},{2},{3}'.format(gecos_dict.get('fullname', ''),
gecos_dict.get('roomnumber', ''),
gecos_dict.get('workphone', ''),
- gecos_dict.get('homephone', ''))
+ gecos_dict.get('homephone', '')).rstrip(',')
def _update_gecos(name, key, value, root=None):
diff --git a/tests/unit/modules/test_useradd.py b/tests/unit/modules/test_useradd.py
index eb983685bb..fa30a0df71 100644
--- a/tests/unit/modules/test_useradd.py
+++ b/tests/unit/modules/test_useradd.py
@@ -393,3 +393,21 @@ class UserAddTestCase(TestCase, LoaderModuleMockMixin):
mock = MagicMock(side_effect=[{'name': ''}, False, {'name': ''}])
with patch.object(useradd, 'info', mock):
self.assertFalse(useradd.rename('salt', 'salt'))
+
+ def test_build_gecos_field(self):
+ '''
+ Test if gecos fields are built correctly (removing trailing commas)
+ '''
+ test_gecos = {'fullname': 'Testing',
+ 'roomnumber': 1234,
+ 'workphone': 22222,
+ 'homephone': 99999}
+ expected_gecos_fields = 'Testing,1234,22222,99999'
+ self.assertEqual(useradd._build_gecos(test_gecos), expected_gecos_fields)
+ test_gecos.pop('roomnumber')
+ test_gecos.pop('workphone')
+ expected_gecos_fields = 'Testing,,,99999'
+ self.assertEqual(useradd._build_gecos(test_gecos), expected_gecos_fields)
+ test_gecos.pop('homephone')
+ expected_gecos_fields = 'Testing'
+ self.assertEqual(useradd._build_gecos(test_gecos), expected_gecos_fields)
--
2.15.1