s3:ntlm_auth: make logs more consistent with length check
[Samba.git] / python / samba / tests / pam_winbind.py
blob708f408f76834f41430f387dac0f07defb3a30d5
1 # Unix SMB/CIFS implementation.
3 # Copyright (C) 2017 Andreas Schneider <asn@samba.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import samba.tests
20 import pypamtest
21 import os
24 class SimplePamTests(samba.tests.TestCase):
25 def test_authenticate(self):
26 domain = os.environ["DOMAIN"]
27 username = os.environ["USERNAME"]
28 password = os.environ["PASSWORD"]
29 if domain != "":
30 unix_username = "%s/%s" % (domain, username)
31 else:
32 unix_username = "%s" % username
33 expected_rc = 0 # PAM_SUCCESS
35 tc = pypamtest.TestCase(pypamtest.PAMTEST_AUTHENTICATE, expected_rc)
36 try:
37 res = pypamtest.run_pamtest(unix_username, "samba", [tc], [password])
38 except pypamtest.PamTestError as e:
39 raise AssertionError(str(e))
41 self.assertTrue(res is not None)
43 def test_authenticate_error(self):
44 domain = os.environ["DOMAIN"]
45 username = os.environ["USERNAME"]
46 password = "WrongPassword"
47 if domain != "":
48 unix_username = "%s/%s" % (domain, username)
49 else:
50 unix_username = "%s" % username
51 expected_rc = 7 # PAM_AUTH_ERR
53 tc = pypamtest.TestCase(pypamtest.PAMTEST_AUTHENTICATE, expected_rc)
54 try:
55 res = pypamtest.run_pamtest(unix_username, "samba", [tc], [password])
56 except pypamtest.PamTestError as e:
57 raise AssertionError(str(e))
59 self.assertTrue(res is not None)
61 # Authenticate again to check that we are not locked out with just one
62 # failed login
63 password = os.environ["PASSWORD"]
64 expected_rc = 0 # PAM_SUCCESS
66 tc = pypamtest.TestCase(pypamtest.PAMTEST_AUTHENTICATE, expected_rc)
67 try:
68 res = pypamtest.run_pamtest(unix_username, "samba", [tc], [password])
69 except pypamtest.PamTestError as e:
70 raise AssertionError(str(e))
72 self.assertTrue(res is not None)