[SSSD] [PATCH] SSSDConfigTest: Test real config without config_file_version

Lukas Slebodnik lslebodn at redhat.com
Thu Oct 15 09:16:28 UTC 2015


ehlo,

let's follow TDD :-)

attached are unit tests for regression in
https://fedorahosted.org/sssd/ticket/2837

LS
-------------- next part --------------
>From 2ba47cb1b132efd960cd771a9d78c8ba7aa59843 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Thu, 15 Oct 2015 10:32:09 +0200
Subject: [PATCH 1/2] SSSDConfigTest: Try load saved config

Python module SSSDConfig should be able to save configuration file
and later load the same configuration file without problem.

Unit test for:
https://fedorahosted.org/sssd/ticket/2837
---
 src/config/SSSDConfigTest.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py
index 5047bd7237188be4df83f76054afe6b43ceeec1d..620585eae5e233724a71e51de6f0ca67c40f7c3e 100755
--- a/src/config/SSSDConfigTest.py
+++ b/src/config/SSSDConfigTest.py
@@ -157,6 +157,11 @@ class SSSDConfigTestValid(unittest.TestCase):
         #non-owners, and should not be executable by anyone
         self.assertFalse(S_IMODE(mode) & 0o177)
 
+        # try to import saved configuration file
+        config = SSSDConfig.SSSDConfig(srcdir + "/etc/sssd.api.conf",
+                                       srcdir + "/etc/sssd.api.d")
+        config.import_config(configfile=of)
+
         #Remove the output file
         os.unlink(of)
 
@@ -191,6 +196,11 @@ class SSSDConfigTestValid(unittest.TestCase):
         #non-owners, and should not be executable by anyone
         self.assertFalse(S_IMODE(mode) & 0o177)
 
+        # try to import saved configuration file
+        config = SSSDConfig.SSSDConfig(srcdir + "/etc/sssd.api.conf",
+                                       srcdir + "/etc/sssd.api.d")
+        config.import_config(configfile=of)
+
         #Remove the output file
         os.unlink(of)
 
-- 
2.5.0

-------------- next part --------------
>From 770cd4df22988fc1eb2d71e14b38f99991e70670 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Thu, 15 Oct 2015 11:04:06 +0200
Subject: [PATCH 2/2] SSSDConfigTest: Test real config without
 config_file_version

src/config/testconfigs/sssd-valid.conf explicitly contains
config_file_version. Recently we changed the default value to 2
and therefore it needn't be listed in configuration file.
This patch add real ssds.conf without config_file_version
---
 src/config/SSSDConfigTest.py                       | 56 ++++++++++++++++++++++
 .../testconfigs/sssd-implicit-config-version.conf  | 30 ++++++++++++
 2 files changed, 86 insertions(+)
 create mode 100644 src/config/testconfigs/sssd-implicit-config-version.conf

diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py
index 620585eae5e233724a71e51de6f0ca67c40f7c3e..c0dcce3bc2a63afef825c4c4b626a9c3be78b7cc 100755
--- a/src/config/SSSDConfigTest.py
+++ b/src/config/SSSDConfigTest.py
@@ -1248,6 +1248,62 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
         self.assertRaises(SSSDConfig.AlreadyInitializedError,
                           sssdconfig.import_config, srcdir + "/testconfigs/sssd-valid.conf")
 
+    def testImportConfigWithout_config_file_version(self):
+        # Positive Test
+        sssdconfig = SSSDConfig.SSSDConfig(srcdir + "/etc/sssd.api.conf",
+                                           srcdir + "/etc/sssd.api.d")
+        sssdconfig.import_config(
+            srcdir + "/testconfigs/sssd-implicit-config-version.conf"
+        )
+
+        # Verify that all sections were imported
+        control_list = [
+            'sssd',
+            'nss',
+            'pam',
+            'domain/ad.example.com',
+        ]
+
+        for section in control_list:
+            self.assertTrue(sssdconfig.has_section(section),
+                            "Section [%s] missing" %
+                            section)
+        for section in sssdconfig.sections():
+            self.assertTrue(section['name'] in control_list)
+
+        # Verify that all options were imported for a section
+        control_list = [
+            'services',
+            'domains',
+        ]
+
+        for option in control_list:
+            self.assertTrue(sssdconfig.has_option('sssd', option),
+                            "Option [%s] missing from [sssd]" %
+                            option)
+        for option in sssdconfig.options('sssd'):
+            if option['type'] in ('empty', 'comment'):
+                continue
+            self.assertTrue(option['name'] in control_list,
+                            "Option [%s] unexpectedly found" %
+                            option)
+
+        domain_control_list = [
+            'cache_credentials',
+            'id_provider',
+            'auth_provider',
+            'access_provider',
+            'default_shell',
+            'fallback_homedir',
+            'cache_credentials',
+            'use_fully_qualified_names',
+        ]
+
+        domain = sssdconfig.get_domain("ad.example.com")
+
+        for option in domain.get_all_options():
+            self.assertTrue(option in domain_control_list)
+
     def testNewConfig(self):
         # Positive Test
         sssdconfig = SSSDConfig.SSSDConfig(srcdir + "/etc/sssd.api.conf",
diff --git a/src/config/testconfigs/sssd-implicit-config-version.conf b/src/config/testconfigs/sssd-implicit-config-version.conf
new file mode 100644
index 0000000000000000000000000000000000000000..b023ea8a4f652a810d6ff593c923f7f3bbd7d0e0
--- /dev/null
+++ b/src/config/testconfigs/sssd-implicit-config-version.conf
@@ -0,0 +1,30 @@
+[sssd]
+domains = ad.example.com
+services = nss, pam
+
+[nss]
+
+[pam]
+
+[domain/ad.example.com]
+cache_credentials = true
+
+id_provider = ad
+auth_provider = ad
+access_provider = ad
+
+# Uncomment if service discovery is not working
+# ad_server = server.ad.example.com
+
+# Uncomment if you want to use POSIX UIDs and GIDs set on the AD side
+# ldap_id_mapping = False
+
+# Comment out if the users have the shell and home dir set on the AD side
+default_shell = /bin/bash
+fallback_homedir = /home/%d/%u
+
+# Uncomment and adjust if the default principal SHORTNAME$@REALM is not available
+# ldap_sasl_authid = host/client.ad.example.com at AD.EXAMPLE.COM
+
+# Comment out if you prefer to user shortnames.
+use_fully_qualified_names = True
-- 
2.5.0



More information about the sssd-devel mailing list