PEP8: fix E302: expected 2 blank lines, found 1
[bbaumbach/samba-autobuild/.git] / python / samba / tests / auth.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 """Tests for the Auth Python bindings.
19
20 Note that this just tests the bindings work. It does not intend to test
21 the functionality, that's already done in other tests.
22 """
23
24 from samba import auth
25 import samba.tests
26
27
28 class AuthSystemSessionTests(samba.tests.TestCase):
29
30     def setUp(self):
31         super(AuthSystemSessionTests, self).setUp()
32         self.system_session = auth.system_session()
33         self.lp = samba.tests.env_loadparm()
34
35     def test_system_session_attrs(self):
36         self.assertTrue(hasattr(self.system_session, 'credentials'))
37         self.assertTrue(hasattr(self.system_session, 'info'))
38         self.assertTrue(hasattr(self.system_session, 'security_token'))
39         self.assertTrue(hasattr(self.system_session, 'session_key'))
40         self.assertTrue(hasattr(self.system_session, 'torture'))
41
42     def test_system_session_credentials(self):
43         self.assertIsNone(self.system_session.credentials.get_bind_dn())
44         self.assertIsNotNone(self.system_session.credentials.get_password())
45         self.assertEqual(self.system_session.credentials.get_username(),
46                          self.lp.get('netbios name').upper() + "$")
47
48     def test_system_session_info(self):
49         self.assertEqual(self.system_session.info.full_name, 'System')
50         self.assertEqual(self.system_session.info.domain_name, 'NT AUTHORITY')
51         self.assertEqual(self.system_session.info.account_name, 'SYSTEM')
52
53     def test_system_session_session_key(self):
54         expected = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
55         self.assertEqual(self.system_session.session_key, expected)
56
57     def test_system_session_security_token(self):
58         self.assertTrue(self.system_session.security_token.is_system())
59         self.assertFalse(self.system_session.security_token.is_anonymous())
60
61
62 class AuthAdminSessionTests(samba.tests.TestCase):
63
64     def setUp(self):
65         super(AuthAdminSessionTests, self).setUp()
66         self.lp = samba.tests.env_loadparm()
67         self.admin_session = auth.admin_session(self.lp,
68                                                 "S-1-5-21-2212615479-2695158682-2101375467")
69
70     def test_admin_session_attrs(self):
71         self.assertTrue(hasattr(self.admin_session, 'credentials'))
72         self.assertTrue(hasattr(self.admin_session, 'info'))
73         self.assertTrue(hasattr(self.admin_session, 'security_token'))
74         self.assertTrue(hasattr(self.admin_session, 'session_key'))
75         self.assertTrue(hasattr(self.admin_session, 'torture'))
76
77     def test_admin_session_credentials(self):
78         self.assertIsNone(self.admin_session.credentials)
79
80     def test_session_info_details(self):
81         self.assertEqual(self.admin_session.info.full_name,
82                          'Administrator')
83         self.assertEqual(self.admin_session.info.domain_name,
84                          self.lp.get('workgroup'))
85         self.assertEqual(self.admin_session.info.account_name,
86                          'Administrator')
87
88     def test_security_token(self):
89         self.assertFalse(self.admin_session.security_token.is_system())
90         self.assertFalse(self.admin_session.security_token.is_anonymous())
91         self.assertTrue(self.admin_session.security_token.has_builtin_administrators())
92
93     def test_session_info_unix_details(self):
94         samba.auth.session_info_fill_unix(session_info=self.admin_session,
95                                           lp_ctx=self.lp,
96                                           user_name="Administrator")
97         self.assertEqual(self.admin_session.unix_info.sanitized_username,
98                          'Administrator')
99         self.assertEqual(self.admin_session.unix_info.unix_name,
100                          self.lp.get('workgroup').upper() +
101                          self.lp.get('winbind separator') + 'Administrator')
102         self.assertIsNotNone(self.admin_session.unix_token)