python:tests: Do not have current_time() and current_nt_time() implicitly include...
authorJo Sutton <josutton@catalyst.net.nz>
Mon, 4 Mar 2024 00:38:10 +0000 (13:38 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 21 Mar 2024 03:12:33 +0000 (03:12 +0000)
This is just too error‐prone.

current_gkid() will still continue to return the next GKID if it’s
within clock skew.

Signed-off-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/gkdi.py

index 80672977f8d760b72f633b6292153f2476ca2482..03ed8d0141e65c67aad169dba767547a36fc5160 100644 (file)
@@ -91,17 +91,21 @@ class GkdiBaseTest(TestCase):
 
     @staticmethod
     def current_time(offset: Optional[datetime.timedelta] = None) -> datetime.datetime:
-        if offset is None:
-            # Allow for clock skew.
-            offset = timedelta_from_nt_time_delta(MAX_CLOCK_SKEW)
-
         current_time = datetime.datetime.now(tz=datetime.timezone.utc)
-        return current_time + offset
+
+        if offset is not None:
+            current_time += offset
+
+        return current_time
 
     def current_nt_time(self, offset: Optional[datetime.timedelta] = None) -> NtTime:
         return nt_time_from_datetime(self.current_time(offset))
 
     def current_gkid(self, offset: Optional[datetime.timedelta] = None) -> Gkid:
+        if offset is None:
+            # Allow for clock skew.
+            offset = timedelta_from_nt_time_delta(MAX_CLOCK_SKEW)
+
         return Gkid.from_nt_time(self.current_nt_time(offset))
 
     def gkdi_connect(
@@ -515,13 +519,18 @@ class GkdiBaseTest(TestCase):
         # which exists so that the samba-tool tests can borrow that
         # function.
 
-        root_key_guid, root_key_dn = create_root_key(samdb,
-                                                     domain_dn,
-                                                     current_nt_time=self.current_nt_time(),
-                                                     use_start_time=use_start_time,
-                                                     hash_algorithm=hash_algorithm,
-                                                     guid=guid,
-                                                     data=data)
+        root_key_guid, root_key_dn = create_root_key(
+            samdb,
+            domain_dn,
+            current_nt_time=self.current_nt_time(
+                # Allow for clock skew.
+                timedelta_from_nt_time_delta(MAX_CLOCK_SKEW)
+            ),
+            use_start_time=use_start_time,
+            hash_algorithm=hash_algorithm,
+            guid=guid,
+            data=data,
+        )
 
         if guid is not None:
             # A test may request that a root key have a specific GUID so that