Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-test
[mat/samba.git] / source4 / libcli / security / tests / bindings.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 import security
22
23 class SecurityTokenTests(unittest.TestCase):
24     def setUp(self):
25         self.token = security.SecurityToken()
26
27     def test_is_system(self):
28         self.assertFalse(self.token.is_system())
29
30     def test_is_anonymous(self):
31         self.assertFalse(self.token.is_anonymous())
32
33     def test_has_builtin_administrators(self):
34         self.assertFalse(self.token.has_builtin_administrators())
35
36     def test_has_nt_authenticated_users(self):
37         self.assertFalse(self.token.has_nt_authenticated_users())
38
39     def test_has_priv(self):
40         self.assertFalse(self.token.has_privilege(security.SEC_PRIV_SHUTDOWN))
41
42     def test_set_priv(self):
43         self.assertFalse(self.token.has_privilege(security.SEC_PRIV_SHUTDOWN))
44         self.assertFalse(self.token.set_privilege(security.SEC_PRIV_SHUTDOWN))
45         self.assertTrue(self.token.has_privilege(security.SEC_PRIV_SHUTDOWN))
46
47
48 class SecurityDescriptorTests(unittest.TestCase):
49     def setUp(self):
50         self.descriptor = security.SecurityDescriptor()
51
52
53 class DomSidTests(unittest.TestCase):
54     def test_parse_sid(self):
55         sid = security.Sid("S-1-5-21")
56         self.assertEquals("S-1-5-21", str(sid))
57
58     def test_sid_equal(self):
59         sid1 = security.Sid("S-1-5-21")
60         sid2 = security.Sid("S-1-5-21")
61         self.assertTrue(sid1.__eq__(sid1))
62         self.assertTrue(sid1.__eq__(sid2))
63
64     def test_random(self):
65         sid = security.random_sid()
66         self.assertTrue(str(sid).startswith("S-1-5-21-"))
67
68
69 class PrivilegeTests(unittest.TestCase):
70     def test_privilege_name(self):
71         self.assertEquals("SeShutdownPrivilege", security.privilege_name(security.SEC_PRIV_SHUTDOWN))
72
73     def test_privilege_id(self):
74         self.assertEquals(security.SEC_PRIV_SHUTDOWN, security.privilege_id("SeShutdownPrivilege"))
75