1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-20 16:23:51 +03:00

python: tests: addCleanup is always before create operation

This way if it raises during a create, it will still end up running the cleanup.

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>
This commit is contained in:
Rob van der Linde
2023-10-25 16:02:31 +13:00
committed by Andrew Bartlett
parent d19e268221
commit e87d74066a
2 changed files with 46 additions and 26 deletions

View File

@@ -94,7 +94,6 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
"""Test creating a new authentication policy.""" """Test creating a new authentication policy."""
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name="createTest", force=True) name="createTest", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name", "createTest") "--name", "createTest")
self.assertIsNone(result, msg=err) self.assertIsNone(result, msg=err)
@@ -108,7 +107,6 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
"""Test creating a new authentication policy with description set.""" """Test creating a new authentication policy with description set."""
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name="descriptionTest", force=True) name="descriptionTest", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name", "descriptionTest", "--name", "descriptionTest",
"--description", "Custom Description") "--description", "Custom Description")
@@ -126,7 +124,6 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
""" """
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name="userTGTLifetime", force=True) name="userTGTLifetime", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name", "userTGTLifetime", "--name", "userTGTLifetime",
"--user-tgt-lifetime-mins", "60") "--user-tgt-lifetime-mins", "60")
@@ -160,7 +157,6 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
""" """
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name="serviceTGTLifetime", force=True) name="serviceTGTLifetime", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name", "serviceTGTLifetime", "--name", "serviceTGTLifetime",
"--service-tgt-lifetime-mins", "60") "--service-tgt-lifetime-mins", "60")
@@ -194,7 +190,6 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
""" """
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name="computerTGTLifetime", force=True) name="computerTGTLifetime", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name", "computerTGTLifetime", "--name", "computerTGTLifetime",
"--computer-tgt-lifetime-mins", "60") "--computer-tgt-lifetime-mins", "60")
@@ -227,7 +222,6 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name="validSDDLPolicy", force=True) name="validSDDLPolicy", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name", "validSDDLPolicy", "--name", "validSDDLPolicy",
"--user-allowed-to-authenticate-from", "--user-allowed-to-authenticate-from",
@@ -266,6 +260,8 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
def test_create__audit(self): def test_create__audit(self):
"""Test create authentication policy with --audit flag.""" """Test create authentication policy with --audit flag."""
self.addCleanup(self.delete_authentication_policy,
name="auditPolicy", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name", "auditPolicy", "--name", "auditPolicy",
"--audit") "--audit")
@@ -277,6 +273,8 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
def test_create__enforce(self): def test_create__enforce(self):
"""Test create authentication policy with --enforce flag.""" """Test create authentication policy with --enforce flag."""
self.addCleanup(self.delete_authentication_policy,
name="enforcePolicy", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name", "enforcePolicy", "--name", "enforcePolicy",
"--enforce") "--enforce")
@@ -314,11 +312,12 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
def test_modify__description(self): def test_modify__description(self):
"""Test modifying an authentication policy description.""" """Test modifying an authentication policy description."""
# Create a policy to modify for this test.
name = "modifyDescription" name = "modifyDescription"
self.runcmd("domain", "auth", "policy", "create", "--name", name)
# Create a policy to modify for this test.
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "policy", "create", "--name", name)
# Change the policy description. # Change the policy description.
result, out, err = self.runcmd("domain", "auth", "policy", "modify", result, out, err = self.runcmd("domain", "auth", "policy", "modify",
@@ -332,11 +331,12 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
def test_modify__strong_ntlm_policy(self): def test_modify__strong_ntlm_policy(self):
"""Test modify strong ntlm policy on the authentication policy.""" """Test modify strong ntlm policy on the authentication policy."""
# Create a policy to modify for this test.
name = "modifyStrongNTLMPolicy" name = "modifyStrongNTLMPolicy"
self.runcmd("domain", "auth", "policy", "create", "--name", name)
# Create a policy to modify for this test.
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "policy", "create", "--name", name)
result, out, err = self.runcmd("domain", "auth", "policy", "modify", result, out, err = self.runcmd("domain", "auth", "policy", "modify",
"--name", name, "--name", name,
@@ -362,11 +362,12 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
This includes checking the upper and lower bounds. This includes checking the upper and lower bounds.
""" """
# Create a policy to modify for this test.
name = "modifyUserTGTLifetime" name = "modifyUserTGTLifetime"
self.runcmd("domain", "auth", "policy", "create", "--name", name)
# Create a policy to modify for this test.
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "policy", "create", "--name", name)
result, out, err = self.runcmd("domain", "auth", "policy", "modify", result, out, err = self.runcmd("domain", "auth", "policy", "modify",
"--name", name, "--name", name,
@@ -398,11 +399,12 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
This includes checking the upper and lower bounds. This includes checking the upper and lower bounds.
""" """
# Create a policy to modify for this test.
name = "modifyServiceTGTLifetime" name = "modifyServiceTGTLifetime"
self.runcmd("domain", "auth", "policy", "create", "--name", name)
# Create a policy to modify for this test.
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "policy", "create", "--name", name)
result, out, err = self.runcmd("domain", "auth", "policy", "modify", result, out, err = self.runcmd("domain", "auth", "policy", "modify",
"--name", name, "--name", name,
@@ -434,11 +436,12 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
This includes checking the upper and lower bounds. This includes checking the upper and lower bounds.
""" """
# Create a policy to modify for this test.
name = "modifyComputerTGTLifetime" name = "modifyComputerTGTLifetime"
self.runcmd("domain", "auth", "policy", "create", "--name", name)
# Create a policy to modify for this test.
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "policy", "create", "--name", name)
result, out, err = self.runcmd("domain", "auth", "policy", "modify", result, out, err = self.runcmd("domain", "auth", "policy", "modify",
"--name", name, "--name", name,
@@ -482,11 +485,12 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
def test_modify__audit_enforce(self): def test_modify__audit_enforce(self):
"""Test modify authentication policy using --audit and --enforce.""" """Test modify authentication policy using --audit and --enforce."""
# Create a policy to modify for this test.
name = "modifyEnforce" name = "modifyEnforce"
self.runcmd("domain", "auth", "policy", "create", "--name", name)
# Create a policy to modify for this test.
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "policy", "create", "--name", name)
# Change to audit, the default is --enforce. # Change to audit, the default is --enforce.
result, out, err = self.runcmd("domain", "auth", "policy", "modify", result, out, err = self.runcmd("domain", "auth", "policy", "modify",
@@ -509,11 +513,12 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
def test_modify__protect_unprotect(self): def test_modify__protect_unprotect(self):
"""Test modify authentication policy using --protect and --unprotect.""" """Test modify authentication policy using --protect and --unprotect."""
# Create a policy to modify for this test.
name = "modifyProtect" name = "modifyProtect"
self.runcmd("domain", "auth", "policy", "create", "--name", name)
# Create a policy to modify for this test.
self.addCleanup(self.delete_authentication_policy, self.addCleanup(self.delete_authentication_policy,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "policy", "create", "--name", name)
utils = SDUtils(self.samdb) utils = SDUtils(self.samdb)
result, out, err = self.runcmd("domain", "auth", "policy", "modify", result, out, err = self.runcmd("domain", "auth", "policy", "modify",
@@ -625,6 +630,8 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
def test_delete__force_fails(self): def test_delete__force_fails(self):
"""Test deleting an authentication policy with --force, but it fails.""" """Test deleting an authentication policy with --force, but it fails."""
# Create protected authentication policy. # Create protected authentication policy.
self.addCleanup(self.delete_authentication_policy,
name="deleteForceFail", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name=deleteForceFail", "--name=deleteForceFail",
"--protect") "--protect")
@@ -645,6 +652,8 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
def test_delete__fails(self): def test_delete__fails(self):
"""Test deleting an authentication policy, but it fails.""" """Test deleting an authentication policy, but it fails."""
# Create regular authentication policy. # Create regular authentication policy.
self.addCleanup(self.delete_authentication_policy,
name="regularPolicy", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name=regularPolicy") "--name=regularPolicy")
self.assertIsNone(result, msg=err) self.assertIsNone(result, msg=err)
@@ -665,6 +674,8 @@ class AuthPolicyCmdTestCase(BaseAuthCmdTest):
def test_delete__protected_fails(self): def test_delete__protected_fails(self):
"""Test deleting an authentication policy, but it fails.""" """Test deleting an authentication policy, but it fails."""
# Create protected authentication policy. # Create protected authentication policy.
self.addCleanup(self.delete_authentication_policy,
name="protectedPolicy", force=True)
result, out, err = self.runcmd("domain", "auth", "policy", "create", result, out, err = self.runcmd("domain", "auth", "policy", "create",
"--name=protectedPolicy", "--name=protectedPolicy",
"--protect") "--protect")

View File

@@ -227,11 +227,12 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
def test_modify__description(self): def test_modify__description(self):
"""Test modify authentication silo changing the description field.""" """Test modify authentication silo changing the description field."""
# Create a silo to modify for this test.
name = "modifyDescription" name = "modifyDescription"
self.runcmd("domain", "auth", "silo", "create", "--name", name)
# Create a silo to modify for this test.
self.addCleanup(self.delete_authentication_silo, self.addCleanup(self.delete_authentication_silo,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "silo", "create", "--name", name)
result, out, err = self.runcmd("domain", "auth", "silo", "modify", result, out, err = self.runcmd("domain", "auth", "silo", "modify",
"--name", name, "--name", name,
@@ -244,11 +245,12 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
def test_modify__audit_enforce(self): def test_modify__audit_enforce(self):
"""Test modify authentication silo setting --audit and --enforce.""" """Test modify authentication silo setting --audit and --enforce."""
# Create a silo to modify for this test.
name = "modifyEnforce" name = "modifyEnforce"
self.runcmd("domain", "auth", "silo", "create", "--name", name)
# Create a silo to modify for this test.
self.addCleanup(self.delete_authentication_silo, self.addCleanup(self.delete_authentication_silo,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "silo", "create", "--name", name)
result, out, err = self.runcmd("domain", "auth", "silo", "modify", result, out, err = self.runcmd("domain", "auth", "silo", "modify",
"--name", name, "--name", name,
@@ -270,11 +272,12 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
def test_modify__protect_unprotect(self): def test_modify__protect_unprotect(self):
"""Test modify un-protecting and protecting an authentication silo.""" """Test modify un-protecting and protecting an authentication silo."""
# Create a silo to modify for this test.
name = "modifyProtect" name = "modifyProtect"
self.runcmd("domain", "auth", "silo", "create", "--name", name)
# Create a silo to modify for this test.
self.addCleanup(self.delete_authentication_silo, self.addCleanup(self.delete_authentication_silo,
name=name, force=True) name=name, force=True)
self.runcmd("domain", "auth", "silo", "create", "--name", name)
utils = SDUtils(self.samdb) utils = SDUtils(self.samdb)
result, out, err = self.runcmd("domain", "auth", "silo", "modify", result, out, err = self.runcmd("domain", "auth", "silo", "modify",
@@ -402,6 +405,8 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
def test_delete__force_fails(self): def test_delete__force_fails(self):
"""Test deleting an authentication silo with --force, but it fails.""" """Test deleting an authentication silo with --force, but it fails."""
# Create protected authentication silo. # Create protected authentication silo.
self.addCleanup(self.delete_authentication_silo,
name="deleteForceFail", force=True)
result, out, err = self.runcmd("domain", "auth", "silo", "create", result, out, err = self.runcmd("domain", "auth", "silo", "create",
"--name=deleteForceFail", "--name=deleteForceFail",
"--user-authentication-policy", "User Policy", "--user-authentication-policy", "User Policy",
@@ -423,6 +428,8 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
def test_delete__fails(self): def test_delete__fails(self):
"""Test deleting an authentication silo, but it fails.""" """Test deleting an authentication silo, but it fails."""
# Create regular authentication silo. # Create regular authentication silo.
self.addCleanup(self.delete_authentication_silo,
name="regularSilo", force=True)
result, out, err = self.runcmd("domain", "auth", "silo", "create", result, out, err = self.runcmd("domain", "auth", "silo", "create",
"--name=regularSilo", "--name=regularSilo",
"--user-authentication-policy", "User Policy") "--user-authentication-policy", "User Policy")
@@ -444,6 +451,8 @@ class AuthSiloCmdTestCase(BaseAuthCmdTest):
def test_delete__protected_fails(self): def test_delete__protected_fails(self):
"""Test deleting an authentication silo, but it fails.""" """Test deleting an authentication silo, but it fails."""
# Create protected authentication silo. # Create protected authentication silo.
self.addCleanup(self.delete_authentication_silo,
name="protectedSilo", force=True)
result, out, err = self.runcmd("domain", "auth", "silo", "create", result, out, err = self.runcmd("domain", "auth", "silo", "create",
"--name=protectedSilo", "--name=protectedSilo",
"--user-authentication-policy", "User Policy", "--user-authentication-policy", "User Policy",