forked from gnosek/python-pam
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_pamela.py
78 lines (51 loc) · 1.68 KB
/
test_pamela.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import getpass
import pytest
import pamela
def test_pam_error_noargs():
e = pamela.PAMError()
s = str(e)
r = repr(e)
assert "Unknown" in s
assert "Unknown" in r
def test_pam_error_errno():
en = 2
e = pamela.PAMError(errno=en)
assert str(en) in str(e)
assert "Unknown" not in str(e)
def test_auth_nouser():
with pytest.raises(pamela.PAMError) as exc_info:
pamela.authenticate("userdoesntexist", "wrongpassword")
e = exc_info.value
assert "Unknown" not in str(e)
def test_auth_badpassword():
with pytest.raises(pamela.PAMError) as exc_info:
pamela.authenticate(getpass.getuser(), "wrongpassword")
e = exc_info.value
assert "Unknown" not in str(e)
def test_all():
for name in pamela.__all__:
getattr(pamela, name)
def test_environment():
handle = pamela.pam_start(getpass.getuser(), "login")
k1, v1 = "A", "hat"
handle.put_env(k1, v1)
assert v1 == handle.get_env(k1)
k2, v2 = "B", "dog"
handle.put_env(k2, v2)
assert v2 == handle.get_env(k2)
assert handle.get_envlist() == {k1: v1, k2: v2}
with pytest.raises(pamela.PAMError):
handle.get_env("doesn't exist")
handle.del_env(k2)
with pytest.raises(pamela.PAMError):
handle.get_env(k2)
assert handle.get_envlist() == {k1: v1}
# test set_item / get_item
handle.set_item(pamela.PAM_RHOST, "127.0.0.1")
assert handle.get_item(pamela.PAM_RHOST) == "127.0.0.1"
assert handle.get_item(pamela.PAM_RUSER) is None
@pytest.mark.skip(reason="doesn't work on CI")
def test_session():
handle = pamela.pam_start(getpass.getuser(), "login")
handle.open_session()
handle.close_session()