[SCM] Samba Shared Repository - branch master updated
Garming Sam
garming at samba.org
Mon Nov 7 02:52:02 UTC 2016
The branch, master has been updated
via a00d34d credentials: Add test for credentials behaviour
via 6539d49 pycredentials: Add bindings for {get,set}_principal, get_ntlm_username_domain
via 03b23cd python: samba.tests.credentials: Add tests
via ba060f8 python: samba.tests.credentials: Fix DeprecationWarning
from 815658d samba_tool/fsmo: Allocate RID Set when seizing RID manager
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit a00d34dbc1cf0348be2417ee21903ab1bbf77a3d
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Oct 12 11:28:26 2016 +1300
credentials: Add test for credentials behaviour
Signed-off-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Garming Sam <garming at catalyst.net.nz>
Autobuild-User(master): Garming Sam <garming at samba.org>
Autobuild-Date(master): Mon Nov 7 03:51:11 CET 2016 on sn-devel-144
commit 6539d4997f3ef286cd043fd2d8443036d58da236
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Oct 12 11:27:54 2016 +1300
pycredentials: Add bindings for {get,set}_principal, get_ntlm_username_domain
These will be used in testsuite for the credentials code
Signed-off-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Garming Sam <garming at catalyst.net.nz>
commit 03b23cd0ad4cd5aac13518bf051a6651ffaffab4
Author: Lumir Balhar <lbalhar at redhat.com>
Date: Wed Oct 19 12:11:31 2016 +0200
python: samba.tests.credentials: Add tests
Newly tested functions:
- set_utf16_password
- set_old_password
- get_old_password
- set_old_utf16_password
Signed-off-by: Lumir Balhar <lbalhar at redhat.com>
Reviewed-by: Garming Sam <garming at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit ba060f862388e482beffe349baf02b559fc8dffd
Author: Lumir Balhar <lbalhar at redhat.com>
Date: Tue Oct 18 14:30:28 2016 +0200
python: samba.tests.credentials: Fix DeprecationWarning
For historical reasons, TestCase methods have some aliases
which are deprecated since Python 2.7.
Change "assertEquals" to the preferred name, "assertEqual".
Deprecation notice: https://docs.python.org/2/library/unittest.html#deprecated-aliases
Signed-off-by: Lumir Balhar <lbalhar at redhat.com>
Reviewed-by: Garming Sam <garming at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
-----------------------------------------------------------------------
Summary of changes:
auth/credentials/pycredentials.c | 45 ++++++++++++
python/samba/tests/credentials.py | 151 +++++++++++++++++++++++++++++++++-----
2 files changed, 177 insertions(+), 19 deletions(-)
Changeset truncated at 500 lines:
diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c
index 43fba37..9ea0682 100644
--- a/auth/credentials/pycredentials.c
+++ b/auth/credentials/pycredentials.c
@@ -59,6 +59,43 @@ static PyObject *py_creds_set_username(PyObject *self, PyObject *args)
return PyBool_FromLong(cli_credentials_set_username(PyCredentials_AsCliCredentials(self), newval, obt));
}
+static PyObject *py_creds_get_ntlm_username_domain(PyObject *self, PyObject *unused)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ const char *user = NULL;
+ const char *domain = NULL;
+ PyObject *ret = NULL;
+ cli_credentials_get_ntlm_username_domain(PyCredentials_AsCliCredentials(self),
+ frame, &user, &domain);
+ ret = Py_BuildValue("(OO)",
+ PyString_FromStringOrNULL(user),
+ PyString_FromStringOrNULL(domain));
+ TALLOC_FREE(frame);
+ return ret;
+}
+
+static PyObject *py_creds_get_principal(PyObject *self, PyObject *unused)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ PyObject *ret = PyString_FromStringOrNULL(cli_credentials_get_principal(PyCredentials_AsCliCredentials(self), frame));
+ TALLOC_FREE(frame);
+ return ret;
+}
+
+static PyObject *py_creds_set_principal(PyObject *self, PyObject *args)
+{
+ char *newval;
+ enum credentials_obtained obt = CRED_SPECIFIED;
+ int _obt = obt;
+
+ if (!PyArg_ParseTuple(args, "s|i", &newval, &_obt)) {
+ return NULL;
+ }
+ obt = _obt;
+
+ return PyBool_FromLong(cli_credentials_set_principal(PyCredentials_AsCliCredentials(self), newval, obt));
+}
+
static PyObject *py_creds_get_password(PyObject *self, PyObject *unused)
{
return PyString_FromStringOrNULL(cli_credentials_get_password(PyCredentials_AsCliCredentials(self)));
@@ -463,9 +500,17 @@ static PyMethodDef py_creds_methods[] = {
{ "set_username", py_creds_set_username, METH_VARARGS,
"S.set_username(name, obtained=CRED_SPECIFIED) -> None\n"
"Change username." },
+ { "get_principal", py_creds_get_principal, METH_NOARGS,
+ "S.get_principal() -> user at realm\nObtain user principal." },
+ { "set_principal", py_creds_set_principal, METH_VARARGS,
+ "S.set_principal(name, obtained=CRED_SPECIFIED) -> None\n"
+ "Change principal." },
{ "get_password", py_creds_get_password, METH_NOARGS,
"S.get_password() -> password\n"
"Obtain password." },
+ { "get_ntlm_username_domain", py_creds_get_ntlm_username_domain, METH_NOARGS,
+ "S.get_ntlm_username_domain() -> (domain, username)\n"
+ "Obtain NTLM username and domain, split up either as (DOMAIN, user) or (\"\", \"user at realm\")." },
{ "set_password", py_creds_set_password, METH_VARARGS,
"S.set_password(password, obtained=CRED_SPECIFIED) -> None\n"
"Change password." },
diff --git a/python/samba/tests/credentials.py b/python/samba/tests/credentials.py
index 95ee0fa..a228327 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):
@@ -32,35 +33,52 @@ class CredentialsTests(samba.tests.TestCase):
def test_set_username(self):
self.creds.set_username("somebody")
- self.assertEquals("somebody", self.creds.get_username())
+ self.assertEqual("somebody", self.creds.get_username())
def test_set_password(self):
self.creds.set_password("S3CreT")
- self.assertEquals("S3CreT", self.creds.get_password())
+ self.assertEqual("S3CreT", self.creds.get_password())
+
+ def test_set_utf16_password(self):
+ password = 'S3cRet'
+ passbytes = password.encode('utf-16-le')
+ self.assertTrue(self.creds.set_utf16_password(passbytes))
+ self.assertEqual(password, self.creds.get_password())
+
+ def test_set_old_password(self):
+ self.assertEqual(None, self.creds.get_old_password())
+ self.assertTrue(self.creds.set_old_password("S3c0ndS3CreT"))
+ self.assertEqual("S3c0ndS3CreT", self.creds.get_old_password())
+
+ def test_set_old_utf16_password(self):
+ password = '0ldS3cRet'
+ passbytes = password.encode('utf-16-le')
+ self.assertTrue(self.creds.set_old_utf16_password(passbytes))
+ self.assertEqual(password, self.creds.get_old_password())
def test_set_domain(self):
self.creds.set_domain("ABMAS")
- self.assertEquals("ABMAS", self.creds.get_domain())
+ self.assertEqual("ABMAS", self.creds.get_domain())
def test_set_realm(self):
self.creds.set_realm("myrealm")
- self.assertEquals("MYREALM", self.creds.get_realm())
+ self.assertEqual("MYREALM", self.creds.get_realm())
def test_parse_string_anon(self):
self.creds.parse_string("%")
- self.assertEquals("", self.creds.get_username())
- self.assertEquals(None, self.creds.get_password())
+ self.assertEqual("", self.creds.get_username())
+ self.assertEqual(None, self.creds.get_password())
def test_parse_string_user_pw_domain(self):
self.creds.parse_string("dom\\someone%secr")
- self.assertEquals("someone", self.creds.get_username())
- self.assertEquals("secr", self.creds.get_password())
- self.assertEquals("DOM", self.creds.get_domain())
+ self.assertEqual("someone", self.creds.get_username())
+ self.assertEqual("secr", self.creds.get_password())
+ self.assertEqual("DOM", self.creds.get_domain())
def test_bind_dn(self):
- self.assertEquals(None, self.creds.get_bind_dn())
+ self.assertEqual(None, self.creds.get_bind_dn())
self.creds.set_bind_dn("dc=foo,cn=bar")
- self.assertEquals("dc=foo,cn=bar", self.creds.get_bind_dn())
+ self.assertEqual("dc=foo,cn=bar", self.creds.get_bind_dn())
def test_is_anon(self):
self.creds.set_username("")
@@ -72,18 +90,14 @@ class CredentialsTests(samba.tests.TestCase):
def test_workstation(self):
# FIXME: This is uninitialised, it should be None
- #self.assertEquals(None, self.creds.get_workstation())
+ #self.assertEqual(None, self.creds.get_workstation())
self.creds.set_workstation("myworksta")
- self.assertEquals("myworksta", self.creds.get_workstation())
+ self.assertEqual("myworksta", self.creds.get_workstation())
def test_get_nt_hash(self):
self.creds.set_password("geheim")
- self.assertEquals('\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()
+ self.assertEqual('\xc2\xae\x1f\xe6\xe6H\x84cRE>\x81o*\xeb\x93',
+ self.creds.get_nt_hash())
def test_set_cmdline_callbacks(self):
self.creds.set_cmdline_callbacks()
@@ -96,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 at 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 at 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 at samba.org")
+ self.assertEqual(creds.is_anonymous(), False)
+ self.assertEqual(creds.authentication_requested(), True)
--
Samba Shared Repository
More information about the samba-cvs
mailing list