Skip to content

Commit 544e52e

Browse files
author
Ric Janus Sapasap
committed
Apply black to tests
1 parent a964f51 commit 544e52e

37 files changed

+2628
-1598
lines changed

tests/conftest.py

Lines changed: 121 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
import pytest
55
from saml2 import BINDING_HTTP_REDIRECT, BINDING_HTTP_POST
66
from saml2.extension.idpdisc import BINDING_DISCO
7-
from saml2.saml import NAME_FORMAT_URI, NAMEID_FORMAT_TRANSIENT, NAMEID_FORMAT_PERSISTENT
7+
from saml2.saml import (
8+
NAME_FORMAT_URI,
9+
NAMEID_FORMAT_TRANSIENT,
10+
NAMEID_FORMAT_PERSISTENT,
11+
)
812

913
from satosa.context import Context
1014
from satosa.state import State
@@ -47,11 +51,11 @@ def sp_conf(cert_and_key):
4751
"assertion_consumer_service": [
4852
("%s/acs/redirect" % sp_base, BINDING_HTTP_REDIRECT)
4953
],
50-
"discovery_response": [("%s/disco" % sp_base, BINDING_DISCO)]
54+
"discovery_response": [("%s/disco" % sp_base, BINDING_DISCO)],
5155
},
5256
"want_response_signed": False,
5357
"allow_unsolicited": True,
54-
"name_id_format": [NAMEID_FORMAT_PERSISTENT]
58+
"name_id_format": [NAMEID_FORMAT_PERSISTENT],
5559
},
5660
},
5761
"cert_file": cert_and_key[0],
@@ -82,18 +86,25 @@ def idp_conf(cert_and_key):
8286
"lifetime": {"minutes": 15},
8387
"attribute_restrictions": None, # means all I have
8488
"name_form": NAME_FORMAT_URI,
85-
"fail_on_missing_requested": False
89+
"fail_on_missing_requested": False,
8690
},
8791
},
8892
"subject_data": {},
89-
"name_id_format": [NAMEID_FORMAT_TRANSIENT,
90-
NAMEID_FORMAT_PERSISTENT],
93+
"name_id_format": [NAMEID_FORMAT_TRANSIENT, NAMEID_FORMAT_PERSISTENT],
9194
"want_authn_requests_signed": False,
9295
"ui_info": {
9396
"display_name": [{"text": "SATOSA Test IdP", "lang": "en"}],
94-
"description": [{"text": "Test IdP for SATOSA unit tests.", "lang": "en"}],
95-
"logo": [{"text": "https://idp.example.com/static/logo.png", "width": "120", "height": "60",
96-
"lang": "en"}],
97+
"description": [
98+
{"text": "Test IdP for SATOSA unit tests.", "lang": "en"}
99+
],
100+
"logo": [
101+
{
102+
"text": "https://idp.example.com/static/logo.png",
103+
"width": "120",
104+
"height": "60",
105+
"lang": "en",
106+
}
107+
],
97108
},
98109
},
99110
},
@@ -103,15 +114,22 @@ def idp_conf(cert_and_key):
103114
"organization": {
104115
"name": [["Test IdP Org.", "en"]],
105116
"display_name": [["Test IdP", "en"]],
106-
"url": [["https://idp.example.com/about", "en"]]
117+
"url": [["https://idp.example.com/about", "en"]],
107118
},
108119
"contact_person": [
109-
{"given_name": "Test IdP", "sur_name": "Support", "email_address": ["help@idp.example.com"],
110-
"contact_type": "support"
111-
},
112-
{"given_name": "Test IdP", "sur_name": "Tech support",
113-
"email_address": ["tech@idp.example.com"], "contact_type": "technical"}
114-
]
120+
{
121+
"given_name": "Test IdP",
122+
"sur_name": "Support",
123+
"email_address": ["help@idp.example.com"],
124+
"contact_type": "support",
125+
},
126+
{
127+
"given_name": "Test IdP",
128+
"sur_name": "Tech support",
129+
"email_address": ["tech@idp.example.com"],
130+
"contact_type": "technical",
131+
},
132+
],
115133
}
116134

117135
return idpconfig
@@ -125,8 +143,12 @@ def context():
125143

126144

127145
@pytest.fixture
128-
def satosa_config_dict(backend_plugin_config, frontend_plugin_config, request_microservice_config,
129-
response_microservice_config):
146+
def satosa_config_dict(
147+
backend_plugin_config,
148+
frontend_plugin_config,
149+
request_microservice_config,
150+
response_microservice_config,
151+
):
130152
config = {
131153
"BASE": BASE_URL,
132154
"COOKIE_STATE_NAME": "TEST_STATE",
@@ -136,28 +158,20 @@ def satosa_config_dict(backend_plugin_config, frontend_plugin_config, request_mi
136158
"BACKEND_MODULES": [backend_plugin_config],
137159
"FRONTEND_MODULES": [frontend_plugin_config],
138160
"MICRO_SERVICES": [request_microservice_config, response_microservice_config],
139-
"LOGGING": {"version": 1}
161+
"LOGGING": {"version": 1},
140162
}
141163
return config
142164

143165

144166
@pytest.fixture
145167
def backend_plugin_config():
146-
data = {
147-
"module": "util.TestBackend",
148-
"name": "backend",
149-
"config": {"foo": "bar"}
150-
}
168+
data = {"module": "util.TestBackend", "name": "backend", "config": {"foo": "bar"}}
151169
return data
152170

153171

154172
@pytest.fixture
155173
def frontend_plugin_config():
156-
data = {
157-
"module": "util.TestFrontend",
158-
"name": "frontend",
159-
"config": {"abc": "xyz"}
160-
}
174+
data = {"module": "util.TestFrontend", "name": "frontend", "config": {"abc": "xyz"}}
161175
return data
162176

163177

@@ -175,7 +189,7 @@ def response_microservice_config():
175189
data = {
176190
"module": "util.TestResponseMicroservice",
177191
"name": "response-microservice",
178-
"config": {"qwe": "rty"}
192+
"config": {"qwe": "rty"},
179193
}
180194
return data
181195

@@ -190,19 +204,17 @@ def saml_frontend_config(cert_and_key, sp_conf):
190204
"entityid": "frontend-entity_id",
191205
"service": {
192206
"idp": {
193-
"endpoints": {
194-
"single_sign_on_service": []
195-
},
207+
"endpoints": {"single_sign_on_service": []},
196208
"name": "Frontend IdP",
197209
"name_id_format": NAMEID_FORMAT_TRANSIENT,
198210
"policy": {
199211
"default": {
200212
"attribute_restrictions": None,
201213
"fail_on_missing_requested": False,
202214
"lifetime": {"minutes": 15},
203-
"name_form": NAME_FORMAT_URI
215+
"name_form": NAME_FORMAT_URI,
204216
}
205-
}
217+
},
206218
}
207219
},
208220
"cert_file": cert_and_key[0],
@@ -211,23 +223,30 @@ def saml_frontend_config(cert_and_key, sp_conf):
211223
"organization": {
212224
"name": [["SATOSA Org.", "en"]],
213225
"display_name": [["SATOSA", "en"]],
214-
"url": [["https://satosa.example.com/about", "en"]]
226+
"url": [["https://satosa.example.com/about", "en"]],
215227
},
216228
"contact_person": [
217-
{"given_name": "SATOSA", "sur_name": "Support", "email_address": ["help@satosa.example.com"],
218-
"contact_type": "support"
219-
},
220-
{"given_name": "SATOSA", "sur_name": "Tech Support", "email_address": ["tech@satosa.example.com"],
221-
"contact_type": "technical"
222-
}
223-
]
229+
{
230+
"given_name": "SATOSA",
231+
"sur_name": "Support",
232+
"email_address": ["help@satosa.example.com"],
233+
"contact_type": "support",
234+
},
235+
{
236+
"given_name": "SATOSA",
237+
"sur_name": "Tech Support",
238+
"email_address": ["tech@satosa.example.com"],
239+
"contact_type": "technical",
240+
},
241+
],
224242
},
225-
226243
"endpoints": {
227-
"single_sign_on_service": {BINDING_HTTP_POST: "sso/post",
228-
BINDING_HTTP_REDIRECT: "sso/redirect"}
229-
}
230-
}
244+
"single_sign_on_service": {
245+
BINDING_HTTP_POST: "sso/post",
246+
BINDING_HTTP_REDIRECT: "sso/redirect",
247+
}
248+
},
249+
},
231250
}
232251

233252
return data
@@ -242,28 +261,41 @@ def saml_backend_config(idp_conf):
242261
"config": {
243262
"sp_config": {
244263
"entityid": "backend-entity_id",
245-
"organization": {"display_name": "Example Identities", "name": "Test Identities Org.",
246-
"url": "http://www.example.com"},
264+
"organization": {
265+
"display_name": "Example Identities",
266+
"name": "Test Identities Org.",
267+
"url": "http://www.example.com",
268+
},
247269
"contact_person": [
248-
{"contact_type": "technical", "email_address": "technical@example.com",
249-
"given_name": "Technical"},
250-
{"contact_type": "support", "email_address": "support@example.com", "given_name": "Support"}
270+
{
271+
"contact_type": "technical",
272+
"email_address": "technical@example.com",
273+
"given_name": "Technical",
274+
},
275+
{
276+
"contact_type": "support",
277+
"email_address": "support@example.com",
278+
"given_name": "Support",
279+
},
251280
],
252281
"service": {
253282
"sp": {
254283
"want_response_signed": False,
255284
"allow_unsolicited": True,
256285
"endpoints": {
257286
"assertion_consumer_service": [
258-
("{}/{}/acs/redirect".format(BASE_URL, name), BINDING_HTTP_REDIRECT)],
259-
"discovery_response": [("{}/disco", BINDING_DISCO)]
260-
261-
}
287+
(
288+
"{}/{}/acs/redirect".format(BASE_URL, name),
289+
BINDING_HTTP_REDIRECT,
290+
)
291+
],
292+
"discovery_response": [("{}/disco", BINDING_DISCO)],
293+
},
262294
}
263295
},
264-
"metadata": {"inline": [create_metadata_from_config_dict(idp_conf)]}
296+
"metadata": {"inline": [create_metadata_from_config_dict(idp_conf)]},
265297
}
266-
}
298+
},
267299
}
268300
return data
269301

@@ -284,12 +316,12 @@ def oidc_backend_config():
284316
"config": {
285317
"provider_metadata": {
286318
"issuer": "https://op.example.com",
287-
"authorization_endpoint": "https://example.com/authorization"
319+
"authorization_endpoint": "https://example.com/authorization",
288320
},
289321
"client": {
290322
"auth_req_params": {
291323
"response_type": "code",
292-
"scope": "openid, profile, email, address, phone"
324+
"scope": "openid, profile, email, address, phone",
293325
},
294326
"client_metadata": {
295327
"client_id": "backend_client",
@@ -298,30 +330,39 @@ def oidc_backend_config():
298330
"contacts": ["suppert@example.com"],
299331
"redirect_uris": ["http://example.com/OIDCBackend"],
300332
"subject_type": "public",
301-
}
333+
},
302334
},
303335
"entity_info": {
304-
"contact_person": [{
305-
"contact_type": "technical",
306-
"email_address": ["technical_test@example.com", "support_test@example.com"],
307-
"given_name": "Test",
308-
"sur_name": "OP"
309-
}, {
310-
"contact_type": "support",
311-
"email_address": ["support_test@example.com"],
312-
"given_name": "Support_test"
313-
}],
336+
"contact_person": [
337+
{
338+
"contact_type": "technical",
339+
"email_address": [
340+
"technical_test@example.com",
341+
"support_test@example.com",
342+
],
343+
"given_name": "Test",
344+
"sur_name": "OP",
345+
},
346+
{
347+
"contact_type": "support",
348+
"email_address": ["support_test@example.com"],
349+
"given_name": "Support_test",
350+
},
351+
],
314352
"organization": {
315353
"display_name": ["OP Identities", "en"],
316354
"name": [["En test-OP", "se"], ["A test OP", "en"]],
317-
"url": [["http://www.example.com", "en"], ["http://www.example.se", "se"]],
355+
"url": [
356+
["http://www.example.com", "en"],
357+
["http://www.example.se", "se"],
358+
],
318359
"ui_info": {
319360
"description": [["This is a test OP", "en"]],
320-
"display_name": [["OP - TEST", "en"]]
321-
}
322-
}
323-
}
324-
}
361+
"display_name": [["OP - TEST", "en"]],
362+
},
363+
},
364+
},
365+
},
325366
}
326367

327368
return data
@@ -336,7 +377,7 @@ def account_linking_module_config(signing_key_path):
336377
"api_url": "http://account.example.com/api",
337378
"redirect_url": "http://account.example.com/redirect",
338379
"sign_key": signing_key_path,
339-
}
380+
},
340381
}
341382
return account_linking_config
342383

@@ -350,6 +391,6 @@ def consent_module_config(signing_key_path):
350391
"api_url": "http://consent.example.com/api",
351392
"redirect_url": "http://consent.example.com/redirect",
352393
"sign_key": signing_key_path,
353-
}
394+
},
354395
}
355396
return consent_config

tests/flows/test_account_linking.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,32 @@ def test_full_flow(self, satosa_config_dict, account_linking_module_config):
1818
test_client = Client(make_app(SATOSAConfig(satosa_config_dict)), Response)
1919

2020
# incoming auth req
21-
http_resp = test_client.get("/{}/{}/request".format(satosa_config_dict["BACKEND_MODULES"][0]["name"],
22-
satosa_config_dict["FRONTEND_MODULES"][0]["name"]))
21+
http_resp = test_client.get(
22+
"/{}/{}/request".format(
23+
satosa_config_dict["BACKEND_MODULES"][0]["name"],
24+
satosa_config_dict["FRONTEND_MODULES"][0]["name"],
25+
)
26+
)
2327
assert http_resp.status_code == 200
2428

2529
with responses.RequestsMock() as rsps:
2630
# fake no previous account linking
27-
rsps.add(responses.GET, "{}/get_id".format(api_url), "test_ticket", status=404)
31+
rsps.add(
32+
responses.GET, "{}/get_id".format(api_url), "test_ticket", status=404
33+
)
2834

2935
# incoming auth resp
30-
http_resp = test_client.get("/{}/response".format(satosa_config_dict["BACKEND_MODULES"][0]["name"]))
36+
http_resp = test_client.get(
37+
"/{}/response".format(satosa_config_dict["BACKEND_MODULES"][0]["name"])
38+
)
3139
assert http_resp.status_code == 302
3240
assert http_resp.headers["Location"].startswith(redirect_url)
3341

3442
with responses.RequestsMock() as rsps:
3543
# fake previous account linking
36-
rsps.add(responses.GET, "{}/get_id".format(api_url), "test_userid", status=200)
44+
rsps.add(
45+
responses.GET, "{}/get_id".format(api_url), "test_userid", status=200
46+
)
3747

3848
# incoming account linking response
3949
http_resp = test_client.get("/account_linking/handle_account_linking")

0 commit comments

Comments
 (0)