r26197: Add bindings for libsecurity.
[sfrench/samba-autobuild/.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 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 RandomSidTests(unittest.TestCase):
54     def test_random(self):
55         sid = security.random_sid()
56         self.assertTrue(str(sid).startswith("S-1-5-21-"))
57
58
59 class PrivilegeTests(unittest.TestCase):
60     def test_privilege_name(self):
61         self.assertEquals("SeShutdownPrivilege", security.privilege_name(security.SEC_PRIV_SHUTDOWN))
62
63     def test_privilege_id(self):
64         self.assertEquals(security.SEC_PRIV_SHUTDOWN, security.privilege_id("SeShutdownPrivilege"))
65