Skip to content

Commit 24f5f77

Browse files
committed
Fix timing issues in test suite
1 parent 43faae0 commit 24f5f77

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

tests/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"email": "email"},
7373
"BOOLEAN_CLAIM_MAPPING": {"is_staff": "user_is_staff",
7474
"is_superuser": "user_is_superuser"},
75-
"LOGIN_EXEMPT_URLS": ["^context_processor/$"]
75+
"CONFIG_RELOAD_INTERVAL": 0, # Always reload settings
7676
}
7777

7878
LOGIN_URL = "django_auth_adfs:login"

tests/test_authentication.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_group_claim(self):
9292
self.assertEqual(user.email, "[email protected]")
9393
self.assertEqual(len(user.groups.all()), 0)
9494

95-
@mock_adfs("2016")
95+
@mock_adfs("2016", empty_keys=True)
9696
def test_empty_keys(self):
9797
backend = AdfsAuthCodeBackend()
9898
with patch("django_auth_adfs.config.provider_config.signing_keys", []):
@@ -152,7 +152,6 @@ def test_oauth_redir_2012(self):
152152
redir = urlparse(response["Location"])
153153
qs = parse_qs(redir.query)
154154
sq_expected = {
155-
'scope': ['openid'],
156155
'client_id': ['your-configured-client-id'],
157156
'state': ['L3Rlc3Qv'],
158157
'response_type': ['code'],
@@ -170,7 +169,7 @@ def test_oauth_redir_2016(self):
170169
self.assertEqual(response.status_code, 302)
171170
redir = urlparse(response["Location"])
172171
qs = parse_qs(redir.query)
173-
sq_expected = {
172+
qs_expected = {
174173
'scope': ['openid'],
175174
'client_id': ['your-configured-client-id'],
176175
'state': ['L3Rlc3Qv'],
@@ -181,7 +180,7 @@ def test_oauth_redir_2016(self):
181180
self.assertEqual(redir.scheme, 'https')
182181
self.assertEqual(redir.hostname, 'adfs.example.com')
183182
self.assertEqual(redir.path.rstrip("/"), '/adfs/oauth2/authorize')
184-
self.assertEqual(qs, sq_expected)
183+
self.assertEqual(qs, qs_expected)
185184

186185
@mock_adfs("azure")
187186
def test_oauth_redir_azure(self):

tests/utils.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import time
66
from datetime import datetime, tzinfo, timedelta
7+
from functools import partial
78

89
import jwt
910
import responses
@@ -108,29 +109,32 @@ def do_build_access_token(request, issuer):
108109
return 200, [], json.dumps(response)
109110

110111

111-
def build_openid_keys(request):
112-
keys = {
113-
"keys": [
114-
{
115-
"kty": "RSA",
116-
"use": "sig",
117-
"kid": "dummythumbprint",
118-
"x5t": "dummythumbprint",
119-
"n": "somebase64encodedmodulus",
120-
"e": "somebase64encodedexponent",
121-
"x5c": [base64.b64encode(signing_cert_a).decode(), ]
122-
},
123-
{
124-
"kty": "RSA",
125-
"use": "sig",
126-
"kid": "dummythumbprint",
127-
"x5t": "dummythumbprint",
128-
"n": "somebase64encodedmodulus",
129-
"e": "somebase64encodedexponent",
130-
"x5c": [base64.b64encode(signing_cert_b).decode(), ]
131-
},
132-
]
133-
}
112+
def build_openid_keys(request, empty_keys=False):
113+
if empty_keys:
114+
keys = {"keys": []}
115+
else:
116+
keys = {
117+
"keys": [
118+
{
119+
"kty": "RSA",
120+
"use": "sig",
121+
"kid": "dummythumbprint",
122+
"x5t": "dummythumbprint",
123+
"n": "somebase64encodedmodulus",
124+
"e": "somebase64encodedexponent",
125+
"x5c": [base64.b64encode(signing_cert_a).decode(), ]
126+
},
127+
{
128+
"kty": "RSA",
129+
"use": "sig",
130+
"kid": "dummythumbprint",
131+
"x5t": "dummythumbprint",
132+
"n": "somebase64encodedmodulus",
133+
"e": "somebase64encodedexponent",
134+
"x5c": [base64.b64encode(signing_cert_b).decode(), ]
135+
},
136+
]
137+
}
134138
return 200, [], json.dumps(keys)
135139

136140

@@ -142,7 +146,7 @@ def build_adfs_meta(request):
142146
return 200, [], data
143147

144148

145-
def mock_adfs(adfs_version):
149+
def mock_adfs(adfs_version, empty_keys=False):
146150
if adfs_version not in ["2012", "2016", "azure"]:
147151
raise NotImplementedError("This version of ADFS is not implemented")
148152

@@ -167,7 +171,7 @@ def wrapper(*original_args, **original_kwargs):
167171
)
168172
rsps.add_callback(
169173
rsps.GET, openid_keys,
170-
callback=build_openid_keys,
174+
callback=partial(build_openid_keys, empty_keys=empty_keys),
171175
content_type='application/json',
172176
)
173177
elif adfs_version == "azure":
@@ -177,7 +181,7 @@ def wrapper(*original_args, **original_kwargs):
177181
)
178182
rsps.add_callback(
179183
rsps.GET, openid_keys,
180-
callback=build_openid_keys,
184+
callback=partial(build_openid_keys, empty_keys=empty_keys),
181185
content_type='application/json',
182186
)
183187
else:

0 commit comments

Comments
 (0)