selftest: Make as_canonicalization_tests.py easier to run outside "make test"
authorAndrew Bartlett <abartlet@samba.org>
Mon, 9 Nov 2020 22:12:13 +0000 (11:12 +1300)
committerGary Lockyer <gary@samba.org>
Wed, 11 Nov 2020 01:15:39 +0000 (01:15 +0000)
This takes the realm from the LDAP base DN and so avoids one
easy mistake to make.  So far the NT4 domain name is not
auto-detected, so much be read from the smb.conf.

By using .guess() the smb.conf is read for the unspecified
parts (eg workstation for an NTLM login to the LDAP server if
the target server is an IP address).

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
python/samba/tests/krb5/as_canonicalization_tests.py

index 7cdf614482ef81acacf6bd5b61f014297c5020cc..c0c3208d21664c8f2825696518976c15a345ca4c 100755 (executable)
@@ -185,14 +185,20 @@ class KerberosASCanonicalizationTests(RawKerberosTest):
         cls.username = os.environ["USERNAME"]
         cls.password = os.environ["PASSWORD"]
         cls.domain   = os.environ["DOMAIN"]
-        cls.realm    = os.environ["REALM"]
         cls.host     = os.environ["SERVER"]
 
         c = Credentials()
         c.set_username(cls.username)
         c.set_password(cls.password)
         c.set_domain(cls.domain)
-        c.set_realm(cls.realm)
+        try:
+            realm    = os.environ["REALM"]
+            c.set_realm(realm)
+        except KeyError:
+            pass
+
+        c.guess()
+
         cls.credentials = c
 
         cls.session = system_session()
@@ -236,6 +242,7 @@ class KerberosASCanonicalizationTests(RawKerberosTest):
 
         cls.user_creds = Credentials()
         cls.user_creds.guess(cls.lp)
+        cls.user_creds.set_realm(cls.ldb.domain_dns_name().upper())
         cls.user_creds.set_password(cls.user_pass)
         cls.user_creds.set_username(cls.user_name)
         cls.user_creds.set_workstation(cls.machine_name)
@@ -263,6 +270,7 @@ class KerberosASCanonicalizationTests(RawKerberosTest):
 
         cls.machine_creds = Credentials()
         cls.machine_creds.guess(cls.lp)
+        cls.machine_creds.set_realm(cls.ldb.domain_dns_name().upper())
         cls.machine_creds.set_secure_channel_type(SEC_CHAN_WKSTA)
         cls.machine_creds.set_kerberos_state(DONT_USE_KERBEROS)
         cls.machine_creds.set_password(cls.machine_pass)