selftest.py: Add mk_realms_stanza function.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 23 Mar 2012 22:46:19 +0000 (23:46 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 24 Mar 2012 02:19:31 +0000 (03:19 +0100)
selftest/target/samba.py
selftest/tests/test_samba.py

index 5e652a3..025dbae 100644 (file)
@@ -22,3 +22,35 @@ def bindir_path(binary_mapping, bindir, path):
     if os.path.isfile(valpath):
         return valpath
     return path
+
+
+def mk_realms_stanza(realm, dnsname, domain, kdc_ipv4):
+    """Create a realms stanza for use in a krb5.conf file.
+
+    :param realm: Real name
+    :param dnsname: DNS name matching the realm
+    :param domain: Domain name
+    :param kdc_ipv4: IPv4 address of the KDC
+    :return: String with stanza
+    """
+    return """\
+ %(realm)s = {
+  kdc = %(kdc_ipv4)s:88
+  admin_server = %(kdc_ipv4)s:88
+  default_domain = %(dnsname)s
+ }
+ %(dnsname)s = {
+  kdc = %(kdc_ipv4)s:88
+  admin_server = %(kdc_ipv4)s:88
+  default_domain = %(dnsname)s
+ }
+ %(domain)s = {
+  kdc = %(kdc_ipv4)s:88
+  admin_server = %(kdc_ipv4)s:88
+  default_domain = %(dnsname)s
+ }
+
+""" % {
+    "kdc_ipv4": kdc_ipv4, "dnsname": dnsname, "realm": realm, "domain": domain}
+
+
index d3da930..60f6f7f 100644 (file)
 
 from selftest.tests import TestCase
 
-from selftest.target.samba import bindir_path
+from selftest.target.samba import (
+    bindir_path,
+    mk_realms_stanza,
+    )
 
 
 class BinDirPathTests(TestCase):
@@ -33,6 +36,31 @@ class BinDirPathTests(TestCase):
             bindir_path({"exe": "ls"}, "/bin", "exe"))
 
     def test_no_mapping(self):
-        self.assertEquals("exe", bindir_path({}, "/some/path", "exe"))
-        self.assertEquals("/bin/ls",
+        self.assertEqual("exe", bindir_path({}, "/some/path", "exe"))
+        self.assertEqual("/bin/ls",
             bindir_path({}, "/bin", "ls"))
+
+
+class MkRealmsStanzaTests(TestCase):
+
+    def test_basic(self):
+        self.assertEqual(
+           mk_realms_stanza("rijk", "dnsnaam", "domein", "ipv4_kdc"),
+          '''\
+ rijk = {
+  kdc = ipv4_kdc:88
+  admin_server = ipv4_kdc:88
+  default_domain = dnsnaam
+ }
+ dnsnaam = {
+  kdc = ipv4_kdc:88
+  admin_server = ipv4_kdc:88
+  default_domain = dnsnaam
+ }
+ domein = {
+  kdc = ipv4_kdc:88
+  admin_server = ipv4_kdc:88
+  default_domain = dnsnaam
+ }
+
+''')