Skip to content

Commit b192d3a

Browse files
committed
Cleanup minor whitespace and formatting issues
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 3f8a39e commit b192d3a

File tree

4 files changed

+49
-57
lines changed

4 files changed

+49
-57
lines changed

src/satosa/backends/saml2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ def _translate_response(self, response, state):
287287
pass
288288

289289
internal_resp.attributes = self.converter.to_internal(
290-
self.attribute_profile,
291-
response.ava
292-
)
290+
self.attribute_profile, response.ava)
293291

294292
satosa_logging(logger, logging.DEBUG,
295293
"backend received attributes:\n%s" %

src/satosa/base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,23 +178,24 @@ def _auth_resp_callback_func(self, context, internal_response):
178178
# If configured construct the user id from attribute values.
179179
if "user_id_from_attrs" in self.config["INTERNAL_ATTRIBUTES"]:
180180
user_id = [
181-
"".join(internal_response.attributes[attr]) for attr in
182-
self.config["INTERNAL_ATTRIBUTES"]["user_id_from_attrs"]
183-
]
181+
"".join(internal_response.attributes[attr]) for attr in
182+
self.config["INTERNAL_ATTRIBUTES"]["user_id_from_attrs"]
183+
]
184184
internal_response.user_id = "".join(user_id)
185185

186186
# The authentication response may not contain a user id. For example
187187
# a SAML IdP may not assert a SAML NameID in the subject and we may
188188
# not be configured to construct one from asserted attributes.
189189
# So only hash the user_id if it is not None.
190190
if internal_response.user_id:
191-
user_id = UserIdHasher.hash_data(self.config["USER_ID_HASH_SALT"],
192-
internal_response.user_id)
191+
user_id = UserIdHasher.hash_data(
192+
self.config["USER_ID_HASH_SALT"],
193+
internal_response.user_id)
193194
internal_response.user_id = user_id
194195

195196
if self.response_micro_services:
196-
return self.response_micro_services[0].process(context,
197-
internal_response)
197+
return self.response_micro_services[0].process(
198+
context, internal_response)
198199

199200
return self._auth_resp_finish(context, internal_response)
200201

tests/satosa/backends/test_saml2.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -193,33 +193,31 @@ def test_authn_response(self, context, idp_conf, sp_conf):
193193

194194
def test_authn_response_no_name_id(self, context, idp_conf, sp_conf):
195195
response_binding = BINDING_HTTP_REDIRECT
196-
fakesp = FakeSP(SPConfig().load(sp_conf, metadata_construction=False))
197-
fakeidp = FakeIdP(
198-
USERS,
199-
config=IdPConfig().load(
200-
idp_conf,
201-
metadata_construction=False
202-
)
203-
)
196+
197+
fakesp_conf = SPConfig().load(sp_conf, metadata_construction=False)
198+
fakesp = FakeSP(fakesp_conf)
199+
200+
fakeidp_conf = IdPConfig().load(idp_conf, metadata_construction=False)
201+
fakeidp = FakeIdP(USERS, config=fakeidp_conf)
202+
204203
destination, request_params = fakesp.make_auth_req(
205-
idp_conf["entityid"])
204+
idp_conf["entityid"])
206205

207206
# Use the fake IdP to mock up an authentication request that has no
208207
# <NameID> element.
209208
url, auth_resp = fakeidp.handle_auth_req_no_name_id(
210-
request_params["SAMLRequest"],
211-
request_params["RelayState"],
212-
BINDING_HTTP_REDIRECT,
213-
"testuser1",
214-
response_binding=response_binding
215-
)
209+
request_params["SAMLRequest"],
210+
request_params["RelayState"],
211+
BINDING_HTTP_REDIRECT,
212+
"testuser1",
213+
response_binding=response_binding)
216214

217215
backend = self.samlbackend
218216

219217
context.request = auth_resp
220218
context.state[backend.name] = {
221-
"relay_state": request_params["RelayState"]
222-
}
219+
"relay_state": request_params["RelayState"],
220+
}
223221
backend.authn_response(context, response_binding)
224222

225223
context, internal_resp = backend.auth_callback_func.call_args[0]

tests/util.py

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,13 @@ def __apply_binding_to_authn_response(self,
135135
resp = {"SAMLResponse": saml_response, "RelayState": relay_state}
136136
elif response_binding == BINDING_HTTP_REDIRECT:
137137
http_args = self.apply_binding(
138-
response_binding,
139-
'%s' % resp,
140-
destination,
141-
relay_state,
142-
response=True
143-
)
138+
response_binding,
139+
'%s' % resp,
140+
destination,
141+
relay_state,
142+
response=True)
144143
resp = dict(parse_qsl(urlparse(
145-
dict(http_args["headers"])["Location"]).query))
144+
dict(http_args["headers"])["Location"]).query))
146145

147146
return resp
148147

@@ -166,26 +165,24 @@ def handle_auth_req(self, saml_request, relay_state, binding, userid,
166165
"""
167166

168167
destination, _resp = self.__create_authn_response(
169-
saml_request,
170-
relay_state,
171-
binding,
172-
userid,
173-
response_binding
174-
)
168+
saml_request,
169+
relay_state,
170+
binding,
171+
userid,
172+
response_binding)
175173

176174
resp = self.__apply_binding_to_authn_response(
177-
_resp,
178-
response_binding,
179-
relay_state,
180-
destination
181-
)
175+
_resp,
176+
response_binding,
177+
relay_state,
178+
destination)
182179

183180
return destination, resp
184181

185182
def handle_auth_req_no_name_id(self, saml_request, relay_state, binding,
186183
userid, response_binding=BINDING_HTTP_POST):
187184
"""
188-
Handles a SAML request, validates and creates a SAML response but
185+
Handles a SAML request, validates and creates a SAML response but
189186
without a <NameID> element.
190187
:type saml_request: str
191188
:type relay_state: str
@@ -203,22 +200,20 @@ def handle_auth_req_no_name_id(self, saml_request, relay_state, binding,
203200
"""
204201

205202
destination, _resp = self.__create_authn_response(
206-
saml_request,
207-
relay_state,
208-
binding,
209-
userid,
210-
response_binding
211-
)
203+
saml_request,
204+
relay_state,
205+
binding,
206+
userid,
207+
response_binding)
212208

213209
# Remove the <NameID> element from the response.
214210
_resp.assertion.subject.name_id = None
215211

216212
resp = self.__apply_binding_to_authn_response(
217-
_resp,
218-
response_binding,
219-
relay_state,
220-
destination
221-
)
213+
_resp,
214+
response_binding,
215+
relay_state,
216+
destination)
222217

223218
return destination, resp
224219

0 commit comments

Comments
 (0)