traffic: new version of model with packet_rate, version number
[samba.git] / python / samba / tests / auth.py
index f71e1a784d2b6bd92da4b28d2d1773a3db8e5216..099826e0c62e68b380c4ff88a248a7572285c576 100644 (file)
@@ -24,8 +24,79 @@ the functionality, that's already done in other tests.
 from samba import auth
 import samba.tests
 
-class AuthTests(samba.tests.TestCase):
 
-    def test_system_session(self):
-        auth.system_session()
+class AuthSystemSessionTests(samba.tests.TestCase):
 
+    def setUp(self):
+        super(AuthSystemSessionTests, self).setUp()
+        self.system_session = auth.system_session()
+        self.lp = samba.tests.env_loadparm()
+
+    def test_system_session_attrs(self):
+        self.assertTrue(hasattr(self.system_session, 'credentials'))
+        self.assertTrue(hasattr(self.system_session, 'info'))
+        self.assertTrue(hasattr(self.system_session, 'security_token'))
+        self.assertTrue(hasattr(self.system_session, 'session_key'))
+        self.assertTrue(hasattr(self.system_session, 'torture'))
+
+    def test_system_session_credentials(self):
+        self.assertIsNone(self.system_session.credentials.get_bind_dn())
+        self.assertIsNotNone(self.system_session.credentials.get_password())
+        self.assertEqual(self.system_session.credentials.get_username(),
+                         self.lp.get('netbios name').upper() + "$")
+
+    def test_system_session_info(self):
+        self.assertEqual(self.system_session.info.full_name, 'System')
+        self.assertEqual(self.system_session.info.domain_name, 'NT AUTHORITY')
+        self.assertEqual(self.system_session.info.account_name, 'SYSTEM')
+
+    def test_system_session_session_key(self):
+        expected = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+        self.assertEqual(self.system_session.session_key, expected)
+
+    def test_system_session_security_token(self):
+        self.assertTrue(self.system_session.security_token.is_system())
+        self.assertFalse(self.system_session.security_token.is_anonymous())
+
+
+class AuthAdminSessionTests(samba.tests.TestCase):
+
+    def setUp(self):
+        super(AuthAdminSessionTests, self).setUp()
+        self.lp = samba.tests.env_loadparm()
+        self.admin_session = auth.admin_session(self.lp,
+                                                "S-1-5-21-2212615479-2695158682-2101375467")
+
+    def test_admin_session_attrs(self):
+        self.assertTrue(hasattr(self.admin_session, 'credentials'))
+        self.assertTrue(hasattr(self.admin_session, 'info'))
+        self.assertTrue(hasattr(self.admin_session, 'security_token'))
+        self.assertTrue(hasattr(self.admin_session, 'session_key'))
+        self.assertTrue(hasattr(self.admin_session, 'torture'))
+
+    def test_admin_session_credentials(self):
+        self.assertIsNone(self.admin_session.credentials)
+
+    def test_session_info_details(self):
+        self.assertEqual(self.admin_session.info.full_name,
+                         'Administrator')
+        self.assertEqual(self.admin_session.info.domain_name,
+                         self.lp.get('workgroup'))
+        self.assertEqual(self.admin_session.info.account_name,
+                         'Administrator')
+
+    def test_security_token(self):
+        self.assertFalse(self.admin_session.security_token.is_system())
+        self.assertFalse(self.admin_session.security_token.is_anonymous())
+        self.assertTrue(self.admin_session.security_token.has_builtin_administrators())
+
+    def test_session_info_unix_details(self):
+        samba.auth.session_info_fill_unix(session_info=self.admin_session,
+                                          lp_ctx=self.lp,
+                                          user_name="Administrator")
+        self.assertEqual(self.admin_session.unix_info.sanitized_username,
+                         'Administrator')
+        self.assertEqual(self.admin_session.unix_info.unix_name,
+                         self.lp.get('workgroup').upper() +
+                         self.lp.get('winbind separator') + 'Administrator')
+        self.assertIsNotNone(self.admin_session.unix_token)