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
):
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_use_global_krb5_ccache
=True,
38 target_hostname
=os
.environ
["SERVER"],
39 target_service
="host",
40 client_helper
="gss-spnego-client",
41 server_helper
="gss-spnego",
42 server_use_winbind
=True)
45 os
.environ
["KRB5CCNAME"] = self
.ccache
46 ret
= self
.run_helper(client_use_global_krb5_ccache
=True,
47 target_hostname
=os
.environ
["SERVER"],
48 target_service
="host",
49 client_helper
="gss-spnego-client",
50 server_helper
="gss-spnego",
51 server_use_winbind
=True)
54 def test_krb5_invalid_keytab(self
):
55 """ ntlm_auth with krb5 and an invalid keytab """
57 dedicated_keytab
= "FILE:%s.%s" % (
58 self
.old_ccache
, "keytab-does-not-exists")
59 proc
= Popen([self
.ntlm_auth_path
,
60 "--helper-protocol", "gss-spnego",
61 "--option", "security=ads",
62 "--option", "kerberosmethod=dedicatedkeytab",
63 "--option", "dedicatedkeytabfile=%s" % dedicated_keytab
],
64 stdout
=PIPE
, stdin
=PIPE
, stderr
=PIPE
)
66 (out
, err
) = proc
.communicate(input=buf
.encode('utf-8'))
67 self
.assertEqual(proc
.returncode
, 0)
69 dedicated_keytab
= "FILE:%s.%s" % (
70 self
.ccache
, "keytab-does-not-exists")
71 proc
= Popen([self
.ntlm_auth_path
,
72 "--helper-protocol", "gss-spnego",
73 "--option", "security=ads",
74 "--option", "kerberosmethod=dedicatedkeytab",
75 "--option", "dedicatedkeytabfile=%s" % dedicated_keytab
],
76 stdout
=PIPE
, stdin
=PIPE
, stderr
=PIPE
)
78 (out
, err
) = proc
.communicate(input=buf
.encode('utf-8'))
79 self
.assertEqual(proc
.returncode
, 0)