]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pytest:sid_strings: separate out expected_sid formatting
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 12 Apr 2023 23:30:26 +0000 (11:30 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 28 Apr 2023 02:15:36 +0000 (02:15 +0000)
This is going to be useful for another test, soon.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/sid_strings.py

index bc641b39a14a17beef6ef81a794856a065b7d9b8..94a94a13e44358fcce8799182f3efff56099c9fe 100644 (file)
@@ -81,6 +81,7 @@ class SidStringBase(TestCase):
         cls.base_dn = cls.ldb.domain_dn()
         cls.schema_dn = cls.ldb.get_schema_basedn().get_linearized()
         cls.timestamp = str(int(time.time()))
+        cls.domain_sid = cls.ldb.get_domain_sid()
 
     def _test_sid_string_with_args(self, code, expected_sid):
         suffix = int(blake2b(code.encode(), digest_size=3).hexdigest(), 16)
@@ -185,16 +186,19 @@ cn: {object_name}
         data = res[0].get('nTSecurityDescriptor', idx=0)
         descriptor = ndr_unpack(security.descriptor, data)
 
-        domain_sid = self.ldb.get_domain_sid()
+        expected_sid = self.format_expected_sid(expected_sid)
+        owner_sid = str(descriptor.owner_sid)
+        self.assertEqual(expected_sid, owner_sid)
 
+    def format_expected_sid(self, expected_sid):
         if expected_sid is None:
-            expected_sid = f'{domain_sid}-{security.DOMAIN_RID_ADMINS}'
-        else:
-            expected_sid = expected_sid.format(domain_sid=domain_sid)
+            return f'{self.domain_sid}-{security.DOMAIN_RID_ADMINS}'
 
-        owner_sid = str(descriptor.owner_sid)
+        if not isinstance(expected_sid, str):
+            # never going to match, should have failed already
+            return None
 
-        self.assertEqual(expected_sid, owner_sid)
+        return expected_sid.format(domain_sid=self.domain_sid)
 
 
 @DynamicTestCase