]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
netcmd: tests: test that create objects make use of addCleanup
authorRob van der Linde <rob@catalyst.net.nz>
Thu, 28 Sep 2023 01:48:09 +0000 (14:48 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 29 Sep 2023 02:18:34 +0000 (02:18 +0000)
Since the samdb connection is on the class and hangs around between tests, we need to clean up what we created.

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/samba_tool/domain_auth_policy.py
python/samba/tests/samba_tool/domain_auth_silo.py
python/samba/tests/samba_tool/domain_claim.py

index 50e12fbbf08eb2d38e1e808a32b2dec6c46fc056..061cabae889a7fc620431b4b918760ed118e9c93 100644 (file)
@@ -93,6 +93,9 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
 
     def test_authentication_policy_create(self):
         """Test creating a new authentication policy."""
+        self.addCleanup(self.delete_authentication_policy,
+                        name="createTest", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "policy", "create",
                                        "--name", "createTest")
         self.assertIsNone(result, msg=err)
@@ -104,6 +107,9 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
 
     def test_authentication_policy_create_description(self):
         """Test creating a new authentication policy with description set."""
+        self.addCleanup(self.delete_authentication_policy,
+                        name="descriptionTest", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "policy", "create",
                                        "--name", "descriptionTest",
                                        "--description", "Custom Description")
@@ -119,6 +125,9 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
 
         Also checks the upper and lower bounds are handled.
         """
+        self.addCleanup(self.delete_authentication_policy,
+                        name="userTGTLifetime", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "policy", "create",
                                        "--name", "userTGTLifetime",
                                        "--user-tgt-lifetime", "60")
@@ -152,6 +161,9 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
 
         Also checks the upper and lower bounds are handled.
         """
+        self.addCleanup(self.delete_authentication_policy,
+                        name="serviceTGTLifetime", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "policy", "create",
                                        "--name", "serviceTGTLifetime",
                                        "--service-tgt-lifetime", "60")
@@ -185,6 +197,9 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
 
         Also checks the upper and lower bounds are handled.
         """
+        self.addCleanup(self.delete_authentication_policy,
+                        name="computerTGTLifetime", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "policy", "create",
                                        "--name", "computerTGTLifetime",
                                        "--computer-tgt-lifetime", "60")
index f7cd7859f037f952098b60ccf98b4207dfd2e5b1..53207b2f2906616255926433035b27d569e340d2 100644 (file)
@@ -91,6 +91,9 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
 
     def test_authentication_silo_create_single_policy(self):
         """Test creating a new authentication silo with a single policy."""
+        self.addCleanup(self.delete_authentication_silo,
+                        name="singlePolicy", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "silo", "create",
                                        "--name", "singlePolicy",
                                        "--policy", "Single Policy")
@@ -106,6 +109,9 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
 
     def test_authentication_silo_create_multiple_policies(self):
         """Test creating a new authentication silo with multiple policies."""
+        self.addCleanup(self.delete_authentication_silo,
+                        name="multiplePolicies", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "silo", "create",
                                        "--name", "multiplePolicies",
                                        "--user-policy", "User Policy",
@@ -125,6 +131,9 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
         """Test creating a new authentication silo when policy is a dn."""
         policy = self.get_authentication_policy("Single Policy")
 
+        self.addCleanup(self.delete_authentication_silo,
+                        name="singlePolicyDN", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "silo", "create",
                                        "--name", "singlePolicyDN",
                                        "--policy", policy["dn"])
@@ -155,6 +164,9 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
 
     def test_authentication_silo_create_audit(self):
         """Test create authentication silo with --audit flag."""
+        self.addCleanup(self.delete_authentication_silo,
+                        name="auditPolicies", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "silo", "create",
                                        "--name", "auditPolicies",
                                        "--policy", "Single Policy",
@@ -167,6 +179,9 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
 
     def test_authentication_silo_create_enforce(self):
         """Test create authentication silo with --enforce flag."""
+        self.addCleanup(self.delete_authentication_silo,
+                        name="enforcePolicies", force=True)
+
         result, out, err = self.runcmd("domain", "auth", "silo", "create",
                                        "--name", "enforcePolicies",
                                        "--policy", "Single Policy",
index 675b63ad6c37a7ea265f6ab5c043ce707c4afa84..c4a19fd7eccfeb5413e7113f7f1363d44a4bdb3b 100644 (file)
@@ -224,6 +224,8 @@ class ClaimCmdTestCase(SambaToolCmdTest):
             # Use a different name, so we don't clash with existing attributes.
             name = "test_create_" + attribute
 
+            self.addCleanup(self.delete_claim_type, name=name, force=True)
+
             result, out, err = self.runcmd("domain", "claim", "claim-type",
                                            "create",
                                            "--attribute", attribute,
@@ -240,6 +242,8 @@ class ClaimCmdTestCase(SambaToolCmdTest):
 
     def test_claim_type_create_boolean(self):
         """Test adding a known boolean attribute and check its type."""
+        self.addCleanup(self.delete_claim_type, name="boolAttr", force=True)
+
         result, out, err = self.runcmd("domain", "claim", "claim-type",
                                        "create", "--attribute=msNPAllowDialin",
                                        "--name=boolAttr", "--class=user")
@@ -251,6 +255,8 @@ class ClaimCmdTestCase(SambaToolCmdTest):
 
     def test_claim_type_create_number(self):
         """Test adding a known numeric attribute and check its type."""
+        self.addCleanup(self.delete_claim_type, name="intAttr", force=True)
+
         result, out, err = self.runcmd("domain", "claim", "claim-type",
                                        "create", "--attribute=adminCount",
                                        "--name=intAttr", "--class=user")
@@ -262,6 +268,8 @@ class ClaimCmdTestCase(SambaToolCmdTest):
 
     def test_claim_type_create_text(self):
         """Test adding a known text attribute and check its type."""
+        self.addCleanup(self.delete_claim_type, name="textAttr", force=True)
+
         result, out, err = self.runcmd("domain", "claim", "claim-type",
                                        "create", "--attribute=givenName",
                                        "--name=textAttr", "--class=user")
@@ -273,6 +281,8 @@ class ClaimCmdTestCase(SambaToolCmdTest):
 
     def test_claim_type_create_disabled(self):
         """Test adding a disabled attribute."""
+        self.addCleanup(self.delete_claim_type, name="home", force=True)
+
         result, out, err = self.runcmd("domain", "claim", "claim-type",
                                        "create", "--attribute=msTSHomeDrive",
                                        "--name=home", "--class=user",
@@ -285,6 +295,8 @@ class ClaimCmdTestCase(SambaToolCmdTest):
 
     def test_claim_type_create_protected(self):
         """Test adding a protected attribute."""
+        self.addCleanup(self.delete_claim_type, name="cellphone", force=True)
+
         result, out, err = self.runcmd("domain", "claim", "claim-type",
                                        "create", "--attribute=mobile",
                                        "--name=cellphone", "--class=user",
@@ -306,6 +318,7 @@ class ClaimCmdTestCase(SambaToolCmdTest):
         computer_dn = f"CN=Computer,{schema_dn}"
 
         # --class=user
+        self.addCleanup(self.delete_claim_type, name="streetName", force=True)
         result, out, err = self.runcmd("domain", "claim", "claim-type",
                                        "create", "--attribute=street",
                                        "--name=streetName", "--class=user")
@@ -318,6 +331,7 @@ class ClaimCmdTestCase(SambaToolCmdTest):
         self.assertNotIn(computer_dn, applies_to)
 
         # --class=computer
+        self.addCleanup(self.delete_claim_type, name="ext", force=True)
         result, out, err = self.runcmd("domain", "claim", "claim-type",
                                        "create", "--attribute=extensionName",
                                        "--name=ext", "--class=computer")
@@ -330,6 +344,8 @@ class ClaimCmdTestCase(SambaToolCmdTest):
         self.assertIn(computer_dn, applies_to)
 
         # --class=user --class=computer
+        self.addCleanup(self.delete_claim_type,
+                        name="primaryComputer", force=True)
         result, out, err = self.runcmd("domain", "claim", "claim-type",
                                        "create", "--attribute=msDS-PrimaryComputer",
                                        "--name=primaryComputer", "--class=user",