r26587: Fix reading Samba 3 WINS database and initial work on group db, aliases and...
[jelmer/samba4-debian.git] / source / scripting / python / samba / tests / samba3.py
1 #!/usr/bin/python
2
3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
5 #   
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.
10 #   
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.
15 #   
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/>.
18 #
19
20 import unittest
21 from samba.samba3 import (GroupMappingDatabase, Registry, PolicyDatabase, SecretsDatabase, TdbSam,
22                           WinsDatabase)
23 import os
24
25 DATADIR=os.path.join(os.path.dirname(__file__), "../../../../../testdata/samba3")
26 print "Samba 3 data dir: %s" % DATADIR
27
28 class RegistryTestCase(unittest.TestCase):
29     def setUp(self):
30         self.registry = Registry(os.path.join(DATADIR, "registry.tdb"))
31
32     def tearDown(self):
33         self.registry.close()
34
35     def test_length(self):
36         self.assertEquals(28, len(self.registry))
37
38     def test_keys(self):
39         self.assertTrue("HKLM" in self.registry.keys())
40
41
42 class PolicyTestCase(unittest.TestCase):
43     def setUp(self):
44         self.policy = PolicyDatabase(os.path.join(DATADIR, "account_policy.tdb"))
45
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)
57
58
59 class GroupsTestCase(unittest.TestCase):
60     def setUp(self):
61         self.groupdb = GroupMappingDatabase(os.path.join(DATADIR, "group_mapping.tdb"))
62
63     def tearDown(self):
64         self.groupdb.close()
65
66     def test_group_length(self):
67         self.assertEquals(13, len(list(self.groupdb.groupsids())))
68
69     def test_groupsids(self):
70         sids = list(self.groupdb.groupsids())
71         self.assertTrue("S-1-5-32-544" in sids)
72
73     def test_alias_length(self):
74         self.assertEquals(0, len(list(self.groupdb.aliases())))
75
76
77 class SecretsDbTestCase(unittest.TestCase):
78     def setUp(self):
79         self.secretsdb = SecretsDatabase(os.path.join(DATADIR, "secrets.tdb"))
80
81     def tearDown(self):
82         self.secretsdb.close()
83
84     def test_get_sid(self):
85         self.assertTrue(self.secretsdb.get_sid("BEDWYR") is not None)
86
87
88 class TdbSamTestCase(unittest.TestCase):
89     def setUp(self):
90         self.samdb = TdbSam(os.path.join(DATADIR, "passdb.tdb"))
91
92     def tearDown(self):
93         self.samdb.close()
94
95     def test_usernames(self):
96         self.assertEquals(3, len(list(self.samdb.usernames())))
97
98
99 class WinsDatabaseTestCase(unittest.TestCase):
100     def setUp(self):
101         self.winsdb = WinsDatabase(os.path.join(DATADIR, "wins.dat"))
102
103     def test_length(self):
104         self.assertEquals(22, len(self.winsdb))
105
106     def test_first_entry(self):
107         self.assertEqual((1124185120, ["192.168.1.5"], "64R"), self.winsdb["ADMINISTRATOR#03"])
108
109     def tearDown(self):
110         self.winsdb.close()
111
112 # FIXME: smbpasswd
113 # FIXME: idmapdb
114 # FIXME: Shares