1
+ import logging
1
2
from types import SimpleNamespace
2
3
3
4
import pytest
@@ -44,18 +45,29 @@ def test_no_cache(app, wsgi_env):
44
45
assert g .username is None
45
46
46
47
47
- def test_expired (app , wsgi_env , mocker ):
48
+ def test_expired (app , wsgi_env , caplog , mocker ):
48
49
creds_factory = mocker .patch ("gssapi.Credentials" )
49
50
creds_factory .return_value = SimpleNamespace (lifetime = 0 )
50
- with app .test_request_context ("/" , environ_base = wsgi_env ):
51
+ caplog .set_level (logging .INFO )
52
+ client = app .test_client ()
53
+ response = client .get ("/someplace" , environ_base = wsgi_env )
54
+ assert response .status_code == 302
55
+ assert response .headers ["location" ] == "http://localhost/someplace"
56
+ assert caplog .messages == ["Credential lifetime has expired." ]
57
+
58
+
59
+ def test_expired_unsafe_method (app , wsgi_env , mocker ):
60
+ creds_factory = mocker .patch ("gssapi.Credentials" )
61
+ creds_factory .return_value = SimpleNamespace (lifetime = 0 )
62
+ with app .test_request_context ("/someplace" , method = "POST" , environ_base = wsgi_env ):
51
63
with pytest .raises (Unauthorized ) as excinfo :
52
64
app .preprocess_request ()
53
65
assert g .principal is None
54
66
assert g .username is None
55
- assert excinfo .value .description == "Credential lifetime has expired "
67
+ assert excinfo .value .description == "Re-authentication is necessary, please try your request again. "
56
68
57
69
58
- def test_expired_exception (app , wsgi_env , mocker ):
70
+ def test_expired_exception (app , wsgi_env , mocker , caplog ):
59
71
creds_factory = mocker .patch ("gssapi.Credentials" )
60
72
61
73
class MockedCred :
@@ -64,15 +76,15 @@ def lifetime(self):
64
76
raise ExpiredCredentialsError (720896 , 100001 )
65
77
66
78
creds_factory .return_value = MockedCred ()
67
- with app . test_request_context ( "/" , environ_base = wsgi_env ):
68
- with pytest . raises ( Unauthorized ) as excinfo :
69
- try :
70
- app . preprocess_request ( )
71
- except ExpiredCredentialsError :
72
- pytest .fail ("Did not catch ExpiredCredentialsError on cred.lifetime" )
73
- assert g . principal is None
74
- assert g . username is None
75
- assert excinfo . value . description == "Credential lifetime has expired"
79
+ caplog . set_level ( logging . INFO )
80
+ client = app . test_client ()
81
+ try :
82
+ response = client . get ( "/someplace" , environ_base = wsgi_env )
83
+ except ExpiredCredentialsError :
84
+ pytest .fail ("Did not catch ExpiredCredentialsError on cred.lifetime" )
85
+ assert response . status_code == 302
86
+ assert response . headers [ "location" ] == "http://localhost/someplace"
87
+ assert caplog . messages == [ "Credential lifetime has expired." ]
76
88
77
89
78
90
def test_nominal (app , wsgi_env , mocker ):
@@ -100,3 +112,13 @@ def test_alt_abort(app, wsgi_env, mocker):
100
112
call_args = mock_abort .call_args_list [0 ][0 ]
101
113
assert call_args [0 ] == 403
102
114
assert call_args [1 ].startswith ("Invalid credentials " )
115
+
116
+
117
+ def test_ccache_not_found (app , wsgi_env , caplog , mocker ):
118
+ wsgi_env ["KRB5CCNAME" ] = "FILE:/tmp/does-not-exist"
119
+ #caplog.set_level(logging.INFO)
120
+ client = app .test_client ()
121
+ response = client .get ("/someplace" , environ_base = wsgi_env )
122
+ assert response .status_code == 302
123
+ assert response .headers ["location" ] == "http://localhost/someplace"
124
+ assert caplog .messages == ["Delegated credentials not found: '/tmp/does-not-exist'" ]
0 commit comments