summaryrefslogtreecommitdiff
path: root/server/config
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2009-12-09 06:51:01 -0500
committerStephen Gallagher <sgallagh@redhat.com>2009-12-09 10:05:18 -0500
commitaa83edba323ae398f89612afeb2f35566c6f7a5c (patch)
tree7b045a85954118c68d833c03a89696f682d09de1 /server/config
parentfb900c6ed1680f0fd9f0df6645c36e169ba756d4 (diff)
downloadsssd-aa83edba323ae398f89612afeb2f35566c6f7a5c.tar.gz
sssd-aa83edba323ae398f89612afeb2f35566c6f7a5c.tar.bz2
sssd-aa83edba323ae398f89612afeb2f35566c6f7a5c.zip
SSSDConfig API: fix deactivate_domain()
deactivate_domain() would crash if it attempted to deactivate an already-inactive domain
Diffstat (limited to 'server/config')
-rw-r--r--server/config/SSSDConfig.py5
-rw-r--r--server/config/SSSDConfigTest.py70
2 files changed, 73 insertions, 2 deletions
diff --git a/server/config/SSSDConfig.py b/server/config/SSSDConfig.py
index 3a9ab4b4..f00824d5 100644
--- a/server/config/SSSDConfig.py
+++ b/server/config/SSSDConfig.py
@@ -1343,8 +1343,9 @@ class SSSDConfig(SSSDChangeConf):
if domain_dict.has_key(''):
del domain_dict['']
- # Add a new key for the domain being activated
- del domain_dict[name]
+ # Remove the unwanted domain from the lest
+ if domain_dict.has_key(name):
+ del domain_dict[name]
# Write out the joined keys
self.set('sssd','domains', ", ".join(domain_dict.keys()))
diff --git a/server/config/SSSDConfigTest.py b/server/config/SSSDConfigTest.py
index 973ef07a..0d42d8a6 100644
--- a/server/config/SSSDConfigTest.py
+++ b/server/config/SSSDConfigTest.py
@@ -1247,6 +1247,76 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
sssdconfig = SSSDConfig.SSSDConfig("etc/sssd.api.conf",
"etc/sssd.api.d")
+ domain_name = 'PROXY'
+
+ # Negative test - Not initialized
+ self.assertRaises(SSSDConfig.NotInitializedError,
+ sssdconfig.activate_domain, domain_name)
+
+ sssdconfig.import_config("testconfigs/sssd-valid.conf")
+
+ # Positive test - Activate an inactive domain
+ self.assertTrue(domain_name in sssdconfig.list_domains())
+ self.assertFalse(domain_name in sssdconfig.list_active_domains())
+ self.assertTrue(domain_name in sssdconfig.list_inactive_domains())
+
+ sssdconfig.activate_domain('PROXY')
+ self.assertTrue(domain_name in sssdconfig.list_domains())
+ self.assertTrue(domain_name in sssdconfig.list_active_domains())
+ self.assertFalse(domain_name in sssdconfig.list_inactive_domains())
+
+ # Positive test - Activate an active domain
+ # This should succeed
+ sssdconfig.activate_domain('PROXY')
+ self.assertTrue(domain_name in sssdconfig.list_domains())
+ self.assertTrue(domain_name in sssdconfig.list_active_domains())
+ self.assertFalse(domain_name in sssdconfig.list_inactive_domains())
+
+ # Negative test - Invalid domain name
+ self.assertRaises(SSSDConfig.NoDomainError,
+ sssdconfig.activate_domain, 'nosuchdomain')
+
+ # Negative test - Invalid domain name type
+ self.assertRaises(SSSDConfig.NoDomainError,
+ sssdconfig.activate_domain, self)
+
+ def testDeactivateDomain(self):
+ sssdconfig = SSSDConfig.SSSDConfig("etc/sssd.api.conf",
+ "etc/sssd.api.d")
+
+ domain_name = 'IPA'
+
+ # Negative test - Not initialized
+ self.assertRaises(SSSDConfig.NotInitializedError,
+ sssdconfig.activate_domain, domain_name)
+
+ sssdconfig.import_config("testconfigs/sssd-valid.conf")
+
+ # Positive test -Deactivate an active domain
+ self.assertTrue(domain_name in sssdconfig.list_domains())
+ self.assertTrue(domain_name in sssdconfig.list_active_domains())
+ self.assertFalse(domain_name in sssdconfig.list_inactive_domains())
+
+ sssdconfig.deactivate_domain(domain_name)
+ self.assertTrue(domain_name in sssdconfig.list_domains())
+ self.assertFalse(domain_name in sssdconfig.list_active_domains())
+ self.assertTrue(domain_name in sssdconfig.list_inactive_domains())
+
+ # Positive test - Deactivate an inactive domain
+ # This should succeed
+ sssdconfig.deactivate_domain(domain_name)
+ self.assertTrue(domain_name in sssdconfig.list_domains())
+ self.assertFalse(domain_name in sssdconfig.list_active_domains())
+ self.assertTrue(domain_name in sssdconfig.list_inactive_domains())
+
+ # Negative test - Invalid domain name
+ self.assertRaises(SSSDConfig.NoDomainError,
+ sssdconfig.activate_domain, 'nosuchdomain')
+
+ # Negative test - Invalid domain name type
+ self.assertRaises(SSSDConfig.NoDomainError,
+ sssdconfig.activate_domain, self)
+
if __name__ == "__main__":
error = 0