1 # Unix SMB/CIFS implementation.
3 # Copyright (C) Samuel Cabrero <scabrero@suse.de> 2018
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/>.
21 from subprocess import Popen, PIPE
22 from samba.tests.ntlm_auth_base import NTLMAuthTestCase
24 class NTLMAuthKerberosTests(NTLMAuthTestCase):
27 super(NTLMAuthKerberosTests, self).setUp()
28 self.old_ccache = os.path.join(os.environ["SELFTEST_PREFIX"],
29 "ktest", "krb5_ccache-2")
30 self.ccache = os.path.join(os.environ["SELFTEST_PREFIX"],
31 "ktest", "krb5_ccache-3")
33 def test_krb5_gss_spnego_client_gss_spnego_server(self):
34 """ ntlm_auth with krb5 gss-spnego-client and gss-spnego server """
36 os.environ["KRB5CCNAME"] = self.old_ccache
37 ret = self.run_helper(client_username="foo",
38 client_password="secret",
40 target_hostname=os.environ["SERVER"],
41 target_service="host",
42 client_helper="gss-spnego-client",
43 server_helper="gss-spnego",
44 server_use_winbind=True)
47 os.environ["KRB5CCNAME"] = self.ccache
48 ret = self.run_helper(client_username="foo",
49 client_password="secret",
51 target_hostname=os.environ["SERVER"],
52 target_service="host",
53 client_helper="gss-spnego-client",
54 server_helper="gss-spnego",
55 server_use_winbind=True)
58 def test_krb5_invalid_keytab(self):
59 """ ntlm_auth with krb5 and an invalid keytab """
61 dedicated_keytab = "FILE:%s.%s" % (
62 self.old_ccache, "keytab-does-not-exists")
63 proc = Popen([self.ntlm_auth_path,
64 "--helper-protocol", "gss-spnego",
65 "--option", "security=ads",
66 "--option", "kerberosmethod=dedicatedkeytab",
67 "--option", "dedicatedkeytabfile=%s" % dedicated_keytab],
68 stdout=PIPE, stdin=PIPE, stderr=PIPE)
70 (out, err) = proc.communicate(input=buf.encode('utf-8'))
71 self.assertEqual(proc.returncode, 0)
73 dedicated_keytab = "FILE:%s.%s" % (
74 self.ccache, "keytab-does-not-exists")
75 proc = Popen([self.ntlm_auth_path,
76 "--helper-protocol", "gss-spnego",
77 "--option", "security=ads",
78 "--option", "kerberosmethod=dedicatedkeytab",
79 "--option", "dedicatedkeytabfile=%s" % dedicated_keytab],
80 stdout=PIPE, stdin=PIPE, stderr=PIPE)
82 (out, err) = proc.communicate(input=buf.encode('utf-8'))
83 self.assertEqual(proc.returncode, 0)