3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from samba.samba3 import (GroupMappingDatabase, Registry, PolicyDatabase, SecretsDatabase, TdbSam,
25 DATADIR=os.path.join(os.path.dirname(__file__), "../../../../../testdata/samba3")
26 print "Samba 3 data dir: %s" % DATADIR
28 class RegistryTestCase(unittest.TestCase):
30 self.registry = Registry(os.path.join(DATADIR, "registry.tdb"))
35 def test_length(self):
36 self.assertEquals(28, len(self.registry))
39 self.assertTrue("HKLM" in self.registry.keys())
42 class PolicyTestCase(unittest.TestCase):
44 self.policy = PolicyDatabase(os.path.join(DATADIR, "account_policy.tdb"))
46 def test_policy(self):
47 self.assertEquals(self.policy.min_password_length, 5)
48 self.assertEquals(self.policy.minimum_password_age, 0)
49 self.assertEquals(self.policy.maximum_password_age, 999999999)
50 self.assertEquals(self.policy.refuse_machine_password_change, 0)
51 self.assertEquals(self.policy.reset_count_minutes, 0)
52 self.assertEquals(self.policy.disconnect_time, -1)
53 self.assertEquals(self.policy.user_must_logon_to_change_password, None)
54 self.assertEquals(self.policy.password_history, 0)
55 self.assertEquals(self.policy.lockout_duration, 0)
56 self.assertEquals(self.policy.bad_lockout_minutes, None)
59 class GroupsTestCase(unittest.TestCase):
61 self.groupdb = GroupMappingDatabase(os.path.join(DATADIR, "group_mapping.tdb"))
66 def test_group_length(self):
67 self.assertEquals(13, len(list(self.groupdb.groupsids())))
69 def test_groupsids(self):
70 sids = list(self.groupdb.groupsids())
71 self.assertTrue("S-1-5-32-544" in sids)
73 def test_alias_length(self):
74 self.assertEquals(0, len(list(self.groupdb.aliases())))
77 class SecretsDbTestCase(unittest.TestCase):
79 self.secretsdb = SecretsDatabase(os.path.join(DATADIR, "secrets.tdb"))
82 self.secretsdb.close()
84 def test_get_sid(self):
85 self.assertTrue(self.secretsdb.get_sid("BEDWYR") is not None)
88 class TdbSamTestCase(unittest.TestCase):
90 self.samdb = TdbSam(os.path.join(DATADIR, "passdb.tdb"))
95 def test_usernames(self):
96 self.assertEquals(3, len(list(self.samdb.usernames())))
99 class WinsDatabaseTestCase(unittest.TestCase):
101 self.winsdb = WinsDatabase(os.path.join(DATADIR, "wins.dat"))
103 def test_length(self):
104 self.assertEquals(22, len(self.winsdb))
106 def test_first_entry(self):
107 self.assertEqual((1124185120, ["192.168.1.5"], "64R"), self.winsdb["ADMINISTRATOR#03"])