17
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
from samba.samba3 import GroupMappingDatabase, Registry, PolicyDatabase, SecretsDatabase, TdbSam
22
from samba.samba3 import WinsDatabase, SmbpasswdFile, ACB_NORMAL, IdmapDatabase, SAMUser, ParamFile
20
"""Tests for samba.samba3."""
22
from samba.samba3 import (GroupMappingDatabase, Registry, PolicyDatabase,
23
SecretsDatabase, TdbSam)
24
from samba.samba3 import (WinsDatabase, SmbpasswdFile, ACB_NORMAL,
25
IdmapDatabase, SAMUser, ParamFile)
26
from samba.tests import TestCase
25
DATADIR=os.path.join(os.path.dirname(__file__), "../../../../../testdata/samba3")
26
print "Samba 3 data dir: %s" % DATADIR
28
class RegistryTestCase(unittest.TestCase):
29
for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]:
30
DATADIR = os.path.join(os.path.dirname(__file__), p)
31
if os.path.exists(DATADIR):
35
class RegistryTestCase(TestCase):
38
super(RegistryTestCase, self).setUp()
30
39
self.registry = Registry(os.path.join(DATADIR, "registry.tdb"))
32
41
def tearDown(self):
33
42
self.registry.close()
43
super(RegistryTestCase, self).tearDown()
35
45
def test_length(self):
36
46
self.assertEquals(28, len(self.registry))
47
57
self.registry.values("HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/EVENTLOG"))
50
class PolicyTestCase(unittest.TestCase):
60
class PolicyTestCase(TestCase):
63
super(PolicyTestCase, self).setUp()
52
64
self.policy = PolicyDatabase(os.path.join(DATADIR, "account_policy.tdb"))
54
66
def test_policy(self):
64
76
self.assertEquals(self.policy.bad_lockout_minutes, None)
67
class GroupsTestCase(unittest.TestCase):
79
class GroupsTestCase(TestCase):
82
super(GroupsTestCase, self).setUp()
69
83
self.groupdb = GroupMappingDatabase(os.path.join(DATADIR, "group_mapping.tdb"))
71
85
def tearDown(self):
72
86
self.groupdb.close()
87
super(GroupsTestCase, self).tearDown()
74
89
def test_group_length(self):
75
90
self.assertEquals(13, len(list(self.groupdb.groupsids())))
85
100
self.assertEquals(0, len(list(self.groupdb.aliases())))
88
class SecretsDbTestCase(unittest.TestCase):
103
class SecretsDbTestCase(TestCase):
106
super(SecretsDbTestCase, self).setUp()
90
107
self.secretsdb = SecretsDatabase(os.path.join(DATADIR, "secrets.tdb"))
92
109
def tearDown(self):
93
110
self.secretsdb.close()
111
super(SecretsDbTestCase, self).tearDown()
95
113
def test_get_sid(self):
96
114
self.assertTrue(self.secretsdb.get_sid("BEDWYR") is not None)
99
class TdbSamTestCase(unittest.TestCase):
117
class TdbSamTestCase(TestCase):
120
super(TdbSamTestCase, self).setUp()
101
121
self.samdb = TdbSam(os.path.join(DATADIR, "passdb.tdb"))
103
123
def tearDown(self):
104
124
self.samdb.close()
125
super(TdbSamTestCase, self).tearDown()
106
127
def test_usernames(self):
107
128
self.assertEquals(3, len(list(self.samdb.usernames())))
140
161
self.assertEquals(user, other)
143
class WinsDatabaseTestCase(unittest.TestCase):
164
class WinsDatabaseTestCase(TestCase):
167
super(WinsDatabaseTestCase, self).setUp()
145
168
self.winsdb = WinsDatabase(os.path.join(DATADIR, "wins.dat"))
147
170
def test_length(self):
153
176
def tearDown(self):
154
177
self.winsdb.close()
157
class SmbpasswdTestCase(unittest.TestCase):
178
super(WinsDatabaseTestCase, self).tearDown()
181
class SmbpasswdTestCase(TestCase):
184
super(SmbpasswdTestCase, self).setUp()
159
185
self.samdb = SmbpasswdFile(os.path.join(DATADIR, "smbpasswd"))
161
187
def test_length(self):
173
199
def tearDown(self):
174
200
self.samdb.close()
177
class IdmapDbTestCase(unittest.TestCase):
201
super(SmbpasswdTestCase, self).tearDown()
204
class IdmapDbTestCase(TestCase):
179
self.idmapdb = IdmapDatabase(os.path.join(DATADIR, "winbindd_idmap.tdb"))
207
super(IdmapDbTestCase, self).setUp()
208
self.idmapdb = IdmapDatabase(os.path.join(DATADIR,
209
"winbindd_idmap.tdb"))
181
211
def test_user_hwm(self):
182
212
self.assertEquals(10000, self.idmapdb.get_user_hwm())
199
229
def tearDown(self):
200
230
self.idmapdb.close()
203
class ShareInfoTestCase(unittest.TestCase):
205
self.shareinfodb = ShareInfoDatabase(os.path.join(DATADIR, "share_info.tdb"))
207
# FIXME: needs proper data so it can be tested
210
self.shareinfodb.close()
213
class ParamTestCase(unittest.TestCase):
231
super(IdmapDbTestCase, self).tearDown()
234
class ParamTestCase(TestCase):
214
236
def test_init(self):
215
237
file = ParamFile()
216
238
self.assertTrue(file is not None)