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/>.
24 class PasswordExpirePamTests(samba
.tests
.TestCase
):
25 def test_auth_expire_warning(self
):
26 domain
= os
.environ
["DOMAIN"]
27 username
= os
.environ
["USERNAME"]
28 password
= os
.environ
["PASSWORD"]
29 warn_pwd_expire
= int(os
.environ
["WARN_PWD_EXPIRE"])
31 unix_username
= "%s/%s" % (domain
, username
)
33 unix_username
= "%s" % username
34 expected_rc
= 0 # PAM_SUCCESS
36 tc
= pypamtest
.TestCase(pypamtest
.PAMTEST_AUTHENTICATE
, expected_rc
)
38 res
= pypamtest
.run_pamtest(unix_username
, "samba", [tc
], [password
])
39 except pypamtest
.PamTestError
as e
:
40 raise AssertionError(str(e
))
42 self
.assertTrue(res
is not None)
43 if warn_pwd_expire
== 0:
44 self
.assertTrue(res
.info
== ())
45 elif warn_pwd_expire
== 50:
46 # This is needed as otherwise a build started around
48 if (res
.info
[0] != u
"Your password will expire in 41 days.\n") and \
49 (res
.info
[0] != u
"Your password will expire in 43 days.\n"):
50 self
.assertEqual(res
.info
[0], u
"Your password will expire in 42 days.\n")
52 self
.assertEqual(warn_pwd_expire
, 0)