1 # Unix SMB/CIFS implementation.
3 # Copyright (C) 2022 Samuel Cabrero <scabrero@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/>.
23 class PamChauthtokTests(samba
.tests
.TestCase
):
24 def test_setcred_delete_cred(self
):
25 domain
= os
.environ
["DOMAIN"]
26 username
= os
.environ
["USERNAME"]
27 password
= os
.environ
["PASSWORD"]
30 unix_username
= "%s/%s" % (domain
, username
)
32 unix_username
= "%s" % username
33 expected_rc
= 0 # PAM_SUCCESS
35 tc
= pypamtest
.TestCase(pypamtest
.PAMTEST_AUTHENTICATE
, expected_rc
)
36 tc1
= pypamtest
.TestCase(pypamtest
.PAMTEST_GETENVLIST
, expected_rc
)
37 tc2
= pypamtest
.TestCase(pypamtest
.PAMTEST_KEEPHANDLE
, expected_rc
)
39 res
= pypamtest
.run_pamtest(unix_username
, "samba", [tc
, tc1
, tc2
], [password
])
40 except pypamtest
.PamTestError
as e
:
41 raise AssertionError(str(e
))
43 self
.assertTrue(res
is not None)
45 ccache
= tc1
.pam_env
["KRB5CCNAME"]
46 ccache
= ccache
[ccache
.index(":") + 1:]
47 self
.assertTrue(os
.path
.exists(ccache
))
49 handle
= tc2
.pam_handle
50 tc3
= pypamtest
.TestCase(pypamtest
.PAMTEST_SETCRED
, expected_rc
, pypamtest
.PAMTEST_FLAG_DELETE_CRED
)
52 res
= pypamtest
.run_pamtest(unix_username
, "samba", [tc3
], handle
=handle
)
53 except pypamtest
.PamTestError
as e
:
54 raise AssertionError(str(e
))
56 self
.assertFalse(os
.path
.exists(ccache
))