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."""
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:
})
-
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)
import os
import ldb
import samba
+import tempfile
import unittest
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("", {}))
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"))
+
# 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)
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 == "":
return ldif
def upgrade_provision(lp, samba3):
- subobj = Object()
-
domainname = samba3.configuration.get("workgroup")
if domainname is None:
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
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)
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