summaryrefslogtreecommitdiff
path: root/python/samba
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2016-10-12 11:28:26 +1300
committerGarming Sam <garming@samba.org>2016-11-07 03:51:11 +0100
commita00d34dbc1cf0348be2417ee21903ab1bbf77a3d (patch)
tree9ae735318f8384a180e1ca1468b999ec6fe5fd7a /python/samba
parent6539d4997f3ef286cd043fd2d8443036d58da236 (diff)
downloadsamba-a00d34dbc1cf0348be2417ee21903ab1bbf77a3d.tar.gz
credentials: Add test for credentials behaviour
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz> Autobuild-User(master): Garming Sam <garming@samba.org> Autobuild-Date(master): Mon Nov 7 03:51:11 CET 2016 on sn-devel-144
Diffstat (limited to 'python/samba')
-rw-r--r--python/samba/tests/credentials.py104
1 files changed, 100 insertions, 4 deletions
diff --git a/python/samba/tests/credentials.py b/python/samba/tests/credentials.py
index a08ef3e5dc5..a2283278661 100644
--- a/python/samba/tests/credentials.py
+++ b/python/samba/tests/credentials.py
@@ -23,6 +23,7 @@ the functionality, that's already done in other tests.
from samba import credentials
import samba.tests
+import os
class CredentialsTests(samba.tests.TestCase):
@@ -98,10 +99,6 @@ class CredentialsTests(samba.tests.TestCase):
self.assertEqual('\xc2\xae\x1f\xe6\xe6H\x84cRE>\x81o*\xeb\x93',
self.creds.get_nt_hash())
- def test_guess(self):
- # Just check the method is there and doesn't raise an exception
- self.creds.guess()
-
def test_set_cmdline_callbacks(self):
self.creds.set_cmdline_callbacks()
@@ -113,3 +110,102 @@ class CredentialsTests(samba.tests.TestCase):
def test_wrong_password(self):
self.assertFalse(self.creds.wrong_password())
+
+ def test_guess(self):
+ creds = credentials.Credentials()
+ lp = samba.tests.env_loadparm()
+ os.environ["USER"] = "env_user"
+ creds.guess(lp)
+ self.assertEqual(creds.get_username(), "env_user")
+ self.assertEqual(creds.get_domain(), lp.get("workgroup").upper())
+ self.assertEqual(creds.get_realm(), lp.get("realm").upper())
+ self.assertEqual(creds.is_anonymous(), False)
+ self.assertEqual(creds.authentication_requested(), False)
+
+ def test_set_anonymous(self):
+ creds = credentials.Credentials()
+ lp = samba.tests.env_loadparm()
+ os.environ["USER"] = "env_user"
+ creds.guess(lp)
+ creds.set_anonymous()
+ self.assertEqual(creds.get_username(), "")
+ self.assertEqual(creds.get_domain(), "")
+ self.assertEqual(creds.get_realm(), None)
+ self.assertEqual(creds.is_anonymous(), True)
+ self.assertEqual(creds.authentication_requested(), False)
+
+ def test_parse_username(self):
+ creds = credentials.Credentials()
+ lp = samba.tests.env_loadparm()
+ os.environ["USER"] = "env_user"
+ creds.guess(lp)
+ creds.parse_string("user")
+ self.assertEqual(creds.get_username(), "user")
+ self.assertEqual(creds.get_domain(), lp.get("workgroup").upper())
+ self.assertEqual(creds.get_realm(), lp.get("realm").upper())
+ self.assertEqual(creds.is_anonymous(), False)
+ self.assertEqual(creds.authentication_requested(), True)
+
+ def test_parse_username_with_domain(self):
+ creds = credentials.Credentials()
+ lp = samba.tests.env_loadparm()
+ os.environ["USER"] = "env_user"
+ creds.guess(lp)
+ creds.parse_string("domain\user")
+ self.assertEqual(creds.get_username(), "user")
+ self.assertEqual(creds.get_domain(), "DOMAIN")
+ self.assertEqual(creds.get_realm(), lp.get("realm").upper())
+ self.assertEqual(creds.is_anonymous(), False)
+ self.assertEqual(creds.authentication_requested(), True)
+
+ def test_parse_username_with_realm(self):
+ creds = credentials.Credentials()
+ lp = samba.tests.env_loadparm()
+ os.environ["USER"] = "env_user"
+ creds.guess(lp)
+ creds.parse_string("user@samba.org")
+ self.assertEqual(creds.get_username(), "env_user")
+ self.assertEqual(creds.get_domain(), lp.get("workgroup").upper())
+ self.assertEqual(creds.get_realm(), "SAMBA.ORG")
+ self.assertEqual(creds.is_anonymous(), False)
+ self.assertEqual(creds.authentication_requested(), True)
+
+ def test_parse_username_pw(self):
+ creds = credentials.Credentials()
+ lp = samba.tests.env_loadparm()
+ os.environ["USER"] = "env_user"
+ creds.guess(lp)
+ creds.parse_string("user%pass")
+ self.assertEqual(creds.get_username(), "user")
+ self.assertEqual(creds.get_password(), "pass")
+ self.assertEqual(creds.get_domain(), lp.get("workgroup"))
+ self.assertEqual(creds.get_realm(), lp.get("realm"))
+ self.assertEqual(creds.is_anonymous(), False)
+ self.assertEqual(creds.authentication_requested(), True)
+
+ def test_parse_username_with_domain_pw(self):
+ creds = credentials.Credentials()
+ lp = samba.tests.env_loadparm()
+ os.environ["USER"] = "env_user"
+ creds.guess(lp)
+ creds.parse_string("domain\user%pass")
+ self.assertEqual(creds.get_username(), "user")
+ self.assertEqual(creds.get_domain(), "DOMAIN")
+ self.assertEqual(creds.get_password(), "pass")
+ self.assertEqual(creds.get_realm(), lp.get("realm"))
+ self.assertEqual(creds.is_anonymous(), False)
+ self.assertEqual(creds.authentication_requested(), True)
+
+ def test_parse_username_with_realm_pw(self):
+ creds = credentials.Credentials()
+ lp = samba.tests.env_loadparm()
+ os.environ["USER"] = "env_user"
+ creds.guess(lp)
+ creds.parse_string("user@samba.org%pass")
+ self.assertEqual(creds.get_username(), "env_user")
+ self.assertEqual(creds.get_domain(), lp.get("workgroup").upper())
+ self.assertEqual(creds.get_password(), "pass")
+ self.assertEqual(creds.get_realm(), "SAMBA.ORG")
+ self.assertEqual(creds.get_principal(), "user@samba.org")
+ self.assertEqual(creds.is_anonymous(), False)
+ self.assertEqual(creds.authentication_requested(), True)