From: Douglas Bagnall Date: Wed, 5 Apr 2023 03:20:57 +0000 (+1200) Subject: pytest:sid_strings: use hashed instead of random unique numbers X-Git-Tag: talloc-2.4.1~853 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5c4f4dc9ead3636bd60fb0f7dc15331cbe49c2ec;p=thirdparty%2Fsamba.git pytest:sid_strings: use hashed instead of random unique numbers This removes the slim chance of flapping failures, and makes tracking the created class back to the SID string theoretically possible. To maintain uniqueness of the governs-id, we in chuck some of the timestamp. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/sid_strings.py b/python/samba/tests/sid_strings.py index f44a0508e86..de3baee5deb 100644 --- a/python/samba/tests/sid_strings.py +++ b/python/samba/tests/sid_strings.py @@ -16,10 +16,10 @@ # import os -import random import string import sys import time +from hashlib import blake2b import ldb @@ -81,14 +81,14 @@ class SidStringTests(TestCase): cls.timestamp = str(int(time.time())) def _test_sid_string_with_args(self, code, expected_sid): - random_suffix = random.randint(0, 100000) + suffix = int(blake2b(code.encode(), digest_size=3).hexdigest(), 16) - class_name = f'my-Sid-String-Class-{self.timestamp}-{random_suffix}' + class_name = f'my-Sid-String-Class-{self.timestamp}-{suffix}' class_ldap_display_name = class_name.replace('-', '') class_dn = f'CN={class_name},{self.schema_dn}' - governs_id = f'1.3.6.1.4.1.7165.4.6.2.9.{random_suffix}' + governs_id = f'1.3.6.1.4.1.7165.4.6.2.9.{self.timestamp[-8:]}.{suffix}' if expected_sid is not None: # Append the RID to our OID to ensure more uniqueness. rid = expected_sid.rsplit('-', 1)[1] @@ -126,7 +126,7 @@ schemaUpdateNow: 1 ''' self.ldb.modify_ldif(ldif) - object_name = f'sddl_{self.timestamp}_{random_suffix}' + object_name = f'sddl_{self.timestamp}_{suffix}' object_dn = f'CN={object_name},{self.base_dn}' ldif = f'''