mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
r26536: More tests for provisioning code.
(This used to be commit 43c8bfeedf
)
This commit is contained in:
parent
595ec370da
commit
86f91db7d5
@ -92,7 +92,9 @@ class Ldb(ldb.Ldb):
|
||||
res = self.search(basedn, scope, expression, [attribute])
|
||||
if len(res) != 1 or res[0][attribute] is None:
|
||||
return None
|
||||
return res[0][attribute]
|
||||
values = set(res[0][attribute])
|
||||
assert len(values) == 1
|
||||
return values.pop()
|
||||
|
||||
def erase(self):
|
||||
"""Erase an ldb, removing all records."""
|
||||
|
@ -73,11 +73,6 @@ def findnss(nssfn, *names):
|
||||
raise Exception("Unable to find user/group for %s" % arguments[1])
|
||||
|
||||
|
||||
def hostname():
|
||||
"""return first part of hostname."""
|
||||
return gethostname().split(".")[0]
|
||||
|
||||
|
||||
def open_ldb(session_info, credentials, lp, dbname):
|
||||
assert session_info is not None
|
||||
try:
|
||||
@ -742,7 +737,6 @@ def provision_dns(setup_dir, paths, session_info,
|
||||
})
|
||||
|
||||
|
||||
|
||||
def provision_ldapbase(setup_dir, message, paths):
|
||||
"""Write out a DNS zone file, from the info in the current database."""
|
||||
message("Setting up LDAP base entry: %s" % domaindn)
|
||||
|
@ -20,6 +20,7 @@
|
||||
import os
|
||||
import ldb
|
||||
import samba
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
class LdbTestCase(unittest.TestCase):
|
||||
@ -35,6 +36,15 @@ class LdbTestCase(unittest.TestCase):
|
||||
self.ldb = samba.Ldb(self.filename)
|
||||
|
||||
|
||||
class TestCaseInTempDir(unittest.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCaseInTempDir, self).setUp()
|
||||
self.tempdir = tempfile.mkdtemp()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCaseInTempDir, self).tearDown()
|
||||
|
||||
|
||||
class SubstituteVarTestCase(unittest.TestCase):
|
||||
def test_empty(self):
|
||||
self.assertEquals("", samba.substitute_var("", {}))
|
||||
@ -52,3 +62,11 @@ class SubstituteVarTestCase(unittest.TestCase):
|
||||
def test_unknown_var(self):
|
||||
self.assertEquals("foo ${bla} gsff",
|
||||
samba.substitute_var("foo ${bla} gsff", {"bar": "bla"}))
|
||||
|
||||
|
||||
class LdbExtensionTests(TestCaseInTempDir):
|
||||
def test_searchone(self):
|
||||
l = samba.Ldb(self.tempdir + "/searchone.ldb")
|
||||
l.add({"dn": ldb.Dn(l, "foo=dc"), "bar": "bla"})
|
||||
self.assertEquals("bla", l.searchone(ldb.Dn(l, "foo=dc"), "bar"))
|
||||
|
||||
|
@ -17,13 +17,22 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import unittest
|
||||
import samba.provision
|
||||
import os
|
||||
from samba.provision import setup_secretsdb
|
||||
import samba.tests
|
||||
from ldb import Dn
|
||||
|
||||
class ProvisionTestCase(unittest.TestCase):
|
||||
setup_dir = "setup"
|
||||
|
||||
class ProvisionTestCase(samba.tests.TestCaseInTempDir):
|
||||
def test_setup_secretsdb(self):
|
||||
raise NotImplementedError(self.test_setup_secretsdb)
|
||||
ldb = setup_secretsdb(os.path.join(self.tempdir, "secrets.ldb"),
|
||||
setup_dir, None, None, None)
|
||||
self.assertEquals("LSA Secrets",
|
||||
ldb.searchone(Dn(ldb, "CN=LSA Secrets"), "CN"))
|
||||
|
||||
|
||||
class Disabled:
|
||||
def test_setup_templatesdb(self):
|
||||
raise NotImplementedError(self.test_setup_templatesdb)
|
||||
|
||||
|
@ -14,7 +14,10 @@ import pwd
|
||||
import uuid
|
||||
|
||||
def regkey_to_dn(name):
|
||||
"""Convert a registry key to a DN."""
|
||||
"""Convert a registry key to a DN.
|
||||
|
||||
:name: The registry key name.
|
||||
:return: A matching DN."""
|
||||
dn = "hive=NONE"
|
||||
|
||||
if name == "":
|
||||
@ -253,8 +256,6 @@ maxVersion: %llu
|
||||
return ldif
|
||||
|
||||
def upgrade_provision(lp, samba3):
|
||||
subobj = Object()
|
||||
|
||||
domainname = samba3.configuration.get("workgroup")
|
||||
|
||||
if domainname is None:
|
||||
@ -272,13 +273,7 @@ def upgrade_provision(lp, samba3):
|
||||
|
||||
subobj.realm = realm
|
||||
subobj.domain = domainname
|
||||
subobj.hostname = hostname()
|
||||
|
||||
assert subobj.realm is not None
|
||||
assert subobj.domain is not None
|
||||
assert subobj.hostname is not None
|
||||
|
||||
subobj.HOSTIP = hostip()
|
||||
if domsec is not None:
|
||||
subobj.DOMAINGUID = domsec.guid
|
||||
subobj.DOMAINSID = domsec.sid
|
||||
@ -288,10 +283,7 @@ def upgrade_provision(lp, samba3):
|
||||
subobj.DOMAINSID = randsid()
|
||||
|
||||
if hostsec:
|
||||
subobj.HOSTGUID = hostsec.guid
|
||||
else:
|
||||
subobj.HOSTGUID = uuid.random()
|
||||
subobj.invocationid = uuid.random()
|
||||
hostguid = hostsec.guid
|
||||
subobj.krbtgtpass = randpass(12)
|
||||
subobj.machinepass = randpass(12)
|
||||
subobj.adminpass = randpass(12)
|
||||
|
@ -296,4 +296,5 @@ then
|
||||
plantest "param.python" none PYTHONPATH=bin/python:scripting/python:param/tests scripting/bin/subunitrun bindings
|
||||
plantest "upgrade.python" none PYTHONPATH=bin/python:scripting/python scripting/bin/subunitrun samba.tests.upgrade
|
||||
plantest "samba.python" none PYTHONPATH=bin/python:scripting/python scripting/bin/subunitrun samba.tests
|
||||
plantest "provision.python" none PYTHONPATH=bin/python:scripting/python scripting/bin/subunitrun samba.tests.provision
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user