tests/krb5: Move get_target() to base class
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Wed, 11 Jan 2023 01:17:41 +0000 (14:17 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 3 Mar 2023 01:07:36 +0000 (01:07 +0000)
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/krb5/group_tests.py
python/samba/tests/krb5/kdc_base_test.py

index 8ad7cd43d039079c20e936f2af9416447e92401b..c820fce8145ad5707500595054a55d83c47e1743 100755 (executable)
@@ -1951,35 +1951,6 @@ class GroupTests(KDCBaseTest):
         # Return the mapping from group IDs to principals.
         return groups
 
-    # Get the credentials and server principal name of either the krbtgt, or a
-    # specially created account, with resource SID compression either supported
-    # or unsupported.
-    def get_target(self, to_krbtgt, compression):
-        if to_krbtgt:
-            self.assertIsNone(compression,
-                              "it's no good specifying compression support "
-                              "for the krbtgt")
-            creds = self.get_krbtgt_creds()
-            sname = self.get_krbtgt_sname()
-        else:
-            creds = self.get_cached_creds(
-                account_type=self.AccountType.COMPUTER,
-                opts={
-                    'supported_enctypes':
-                        security.KERB_ENCTYPE_RC4_HMAC_MD5 |
-                        security.KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96,
-                    'sid_compression_support': compression,
-                })
-            target_name = creds.get_username()
-
-            if target_name[-1] == '$':
-                target_name = target_name[:-1]
-            sname = self.PrincipalName_create(
-                name_type=NT_PRINCIPAL,
-                names=['host', target_name])
-
-        return creds, sname
-
     # This is the main function to handle a single testcase.
     def _test_group_with_args(self, case):
         # The group arrangement for the test.
index cbefeb0dcb9101bea1005a490d67930880297ee9..2dec5c8bde4c0340f79a32e6d7fc770ea60fdeec 100644 (file)
@@ -1472,6 +1472,35 @@ class KDCBaseTest(RawKerberosTest):
                                  fallback_creds_fn=download_server_creds)
         return c
 
+    # Get the credentials and server principal name of either the krbtgt, or a
+    # specially created account, with resource SID compression either supported
+    # or unsupported.
+    def get_target(self, to_krbtgt, compression):
+        if to_krbtgt:
+            self.assertIsNone(compression,
+                              "it's no good specifying compression support "
+                              "for the krbtgt")
+            creds = self.get_krbtgt_creds()
+            sname = self.get_krbtgt_sname()
+        else:
+            creds = self.get_cached_creds(
+                account_type=self.AccountType.COMPUTER,
+                opts={
+                    'supported_enctypes':
+                        security.KERB_ENCTYPE_RC4_HMAC_MD5 |
+                        security.KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96,
+                    'sid_compression_support': compression,
+                })
+            target_name = creds.get_username()
+
+            if target_name[-1] == '$':
+                target_name = target_name[:-1]
+            sname = self.PrincipalName_create(
+                name_type=NT_PRINCIPAL,
+                names=['host', target_name])
+
+        return creds, sname
+
     def as_req(self, cname, sname, realm, etypes, padata=None, kdc_options=0):
         '''Send a Kerberos AS_REQ, returns the undecoded response
         '''