Skip to content

Commit 285c80d

Browse files
committed
Format code
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 8ee08e2 commit 285c80d

File tree

1 file changed

+46
-51
lines changed

1 file changed

+46
-51
lines changed

src/satosa/frontends/saml2.py

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ class SAMLUnsolicitedFrontend(SAMLFrontend):
10271027
unsolicted SAML flows. The unsolicited SAML flows are not part of any
10281028
SAML standard.
10291029
"""
1030+
10301031
KEY_ENDPOINT = "endpoint"
10311032
KEY_DISCO_URL_WHITE = "discovery_service_url_whitelist"
10321033
KEY_DISCO_POLICY_WHITE = "discovery_service_policy_whitelist"
@@ -1037,15 +1038,15 @@ class SAMLUnsolicitedFrontend(SAMLFrontend):
10371038
KEY_QUERY_DISCO_URL = "discoveryURL"
10381039
KEY_QUERY_DISCO_POLICY = "discoveryPolicy"
10391040
KEY_SAML_DISCOVERY_SERVICE_URL = SAMLBackend.KEY_SAML_DISCOVERY_SERVICE_URL
1040-
KEY_SAML_DISCOVERY_SERVICE_POLICY = (
1041-
SAMLBackend.KEY_SAML_DISCOVERY_SERVICE_POLICY
1042-
)
1041+
KEY_SAML_DISCOVERY_SERVICE_POLICY = SAMLBackend.KEY_SAML_DISCOVERY_SERVICE_POLICY
10431042
KEY_UNSOLICITED = "unsolicited"
10441043

1045-
def __init__(self, auth_req_callback_func, internal_attributes, config,
1046-
base_url, name):
1047-
super().__init__(auth_req_callback_func, internal_attributes, config,
1048-
base_url, name)
1044+
def __init__(
1045+
self, auth_req_callback_func, internal_attributes, config, base_url, name
1046+
):
1047+
super().__init__(
1048+
auth_req_callback_func, internal_attributes, config, base_url, name
1049+
)
10491050

10501051
def register_endpoints(self, backend_names):
10511052
"""
@@ -1060,12 +1061,10 @@ def register_endpoints(self, backend_names):
10601061
"""
10611062
url_map = super().register_endpoints(backend_names)
10621063

1063-
path = urlparse(
1064-
self.config[self.KEY_UNSOLICITED]
1065-
.get(self.KEY_ENDPOINT)).path
1064+
path = urlparse(self.config[self.KEY_UNSOLICITED].get(self.KEY_ENDPOINT)).path
10661065

10671066
for backend in backend_names:
1068-
pat = '(^{})/{}$'.format(backend, path)
1067+
pat = "(^{})/{}$".format(backend, path)
10691068
url_map.append((pat, self.unsolicited_endpoint))
10701069

10711070
logger.debug("URL maps to be registered are {}".format(url_map))
@@ -1092,16 +1091,14 @@ def unsolicited_endpoint(self, context):
10921091
requested_disco_url = request.get(self.KEY_QUERY_DISCO_URL, None)
10931092
requested_disco_policy = request.get(self.KEY_QUERY_DISCO_POLICY, None)
10941093

1095-
logger.debug("Unsolicited target authenticating IdP is {}".format(
1096-
target_idp_entity_id))
1094+
logger.debug(
1095+
"Unsolicited target authenticating IdP is {}".format(target_idp_entity_id)
1096+
)
10971097
logger.debug("Unsolicited target SP is {}".format(target_sp_entity_id))
10981098
logger.debug("Unsolicited ACS URL is {}".format(target_sp_acs_url))
1099-
logger.debug("Unsolicited relay state is {}".format(
1100-
target_sp_relay_state_url))
1101-
logger.debug("Unsolicted discovery URL is {}".format(
1102-
requested_disco_url))
1103-
logger.debug("Unsolicted discovery policy is {}".format(
1104-
requested_disco_policy))
1099+
logger.debug("Unsolicited relay state is {}".format(target_sp_relay_state_url))
1100+
logger.debug("Unsolicted discovery URL is {}".format(requested_disco_url))
1101+
logger.debug("Unsolicted discovery policy is {}".format(requested_disco_policy))
11051102

11061103
# We only proceed with known federated SPs.
11071104
try:
@@ -1114,9 +1111,10 @@ def unsolicited_endpoint(self, context):
11141111

11151112
# The SP ACS URL if input must match one from the trusted metadata.
11161113
# We assume the SP only has one SPSSODescriptor element in metadata.
1117-
acs_ob_list = (target_sp_metadata.get("spsso_descriptor", [{}])[0]
1118-
.get("assertion_consumer_service", [{}]))
1119-
acs_locations = [acs_ob['location'] for acs_ob in acs_ob_list]
1114+
acs_ob_list = target_sp_metadata.get("spsso_descriptor", [{}])[0].get(
1115+
"assertion_consumer_service", [{}]
1116+
)
1117+
acs_locations = [acs_ob["location"] for acs_ob in acs_ob_list]
11201118

11211119
if target_sp_acs_url:
11221120
if target_sp_acs_url not in acs_locations:
@@ -1128,10 +1126,11 @@ def unsolicited_endpoint(self, context):
11281126
for acs_ob in acs_ob_list:
11291127
# We assume the SP has HTTP_POST binding and we simply
11301128
# take the first one we find.
1131-
if acs_ob['binding'] == BINDING_HTTP_POST:
1132-
target_sp_acs_url = acs_ob['location']
1133-
logger.debug("Unsolicited found SP ACS URL {}".format(
1134-
target_sp_acs_url))
1129+
if acs_ob["binding"] == BINDING_HTTP_POST:
1130+
target_sp_acs_url = acs_ob["location"]
1131+
logger.debug(
1132+
"Unsolicited found SP ACS URL {}".format(target_sp_acs_url)
1133+
)
11351134
break
11361135

11371136
if not target_sp_acs_url:
@@ -1144,8 +1143,11 @@ def unsolicited_endpoint(self, context):
11441143
if target_sp_relay_state_url:
11451144
target = urlparse(target_sp_relay_state_url)
11461145
acs = urlparse(target_sp_acs_url)
1147-
if not (target.scheme == acs.scheme and
1148-
target.netloc == acs.netloc and target.port == acs.port):
1146+
if not (
1147+
target.scheme == acs.scheme
1148+
and target.netloc == acs.netloc
1149+
and target.port == acs.port
1150+
):
11491151
msg = "RelayState {} is not permitted"
11501152
msg = msg.format(target_sp_relay_state_url)
11511153
satosa_logging(logger, logging.ERROR, msg, context.state)
@@ -1155,14 +1157,8 @@ def unsolicited_endpoint(self, context):
11551157
acs = [[target_sp_acs_url, BINDING_HTTP_POST]]
11561158
sp_config_dict = {
11571159
"entityid": target_sp_entity_id,
1158-
"service": {
1159-
"sp": {
1160-
"endpoints": {
1161-
"assertion_consumer_service": acs
1162-
}
1163-
}
1164-
}
1165-
}
1160+
"service": {"sp": {"endpoints": {"assertion_consumer_service": acs}}},
1161+
}
11661162
sp_config = SPConfig().load(sp_config_dict, False)
11671163

11681164
# Create a temporary SP object and use it to create a authn request
@@ -1171,16 +1167,18 @@ def unsolicited_endpoint(self, context):
11711167
target_sp = Base(sp_config)
11721168

11731169
destination = None
1174-
endpoints = self.idp.config.getattr('endpoints')
1175-
sso_service_list = endpoints['single_sign_on_service']
1170+
endpoints = self.idp.config.getattr("endpoints")
1171+
sso_service_list = endpoints["single_sign_on_service"]
11761172
for location, binding in sso_service_list:
11771173
if binding == BINDING_HTTP_POST:
11781174
destination = location
11791175
break
11801176

11811177
if not destination:
1182-
msg = ("Could not determine location for SingleSignOnService "
1183-
"with HTTP-POST binding")
1178+
msg = (
1179+
"Could not determine location for SingleSignOnService "
1180+
"with HTTP-POST binding"
1181+
)
11841182
satosa_logging(logger, logging.ERROR, msg, context.state)
11851183
raise SATOSAError(msg)
11861184

@@ -1190,9 +1188,8 @@ def unsolicited_endpoint(self, context):
11901188

11911189
# Convert the authn request object to an encoded set of bytes.
11921190
authn_request_str = "{}".format(authn_request)
1193-
logger.debug("Unsolicted authn request is {}".format(
1194-
authn_request_str))
1195-
authn_request_bytes = authn_request_str.encode('utf-8')
1191+
logger.debug("Unsolicted authn request is {}".format(authn_request_str))
1192+
authn_request_bytes = authn_request_str.encode("utf-8")
11961193
authn_request_encoded = b64encode(authn_request_bytes)
11971194

11981195
# Add the authn request to the context as if it arrived through
@@ -1205,29 +1202,27 @@ def unsolicited_endpoint(self, context):
12051202

12061203
# If provided and is whitelisted set the discovery service to use.
12071204
if requested_disco_url:
1208-
allowed = (self.config[self.KEY_UNSOLICITED]
1209-
.get(self.KEY_DISCO_URL_WHITE))
1205+
allowed = self.config[self.KEY_UNSOLICITED].get(self.KEY_DISCO_URL_WHITE)
12101206
if requested_disco_url not in allowed:
12111207
msg = "Discovery service URL {} not allowed"
12121208
msg = msg.format(requested_disco_url)
12131209
satosa_logging(logger, logging.ERROR, msg, context.state)
12141210
raise SATOSAError(msg)
12151211

1216-
context.decorate(self.KEY_SAML_DISCOVERY_SERVICE_URL,
1217-
requested_disco_url)
1212+
context.decorate(self.KEY_SAML_DISCOVERY_SERVICE_URL, requested_disco_url)
12181213

12191214
# If provided and is whitelisted set the discovery policy to use.
12201215
if requested_disco_policy:
1221-
allowed = (self.config[self.KEY_UNSOLICITED]
1222-
.get(self.KEY_DISCO_POLICY_WHITE))
1216+
allowed = self.config[self.KEY_UNSOLICITED].get(self.KEY_DISCO_POLICY_WHITE)
12231217
if requested_disco_policy not in allowed:
12241218
msg = "Discovery service policy {} not allowed"
12251219
msg = msg.format(requested_disco_policy)
12261220
satosa_logging(logger, logging.ERROR, msg, context.state)
12271221
raise SATOSAError(msg)
12281222

1229-
context.decorate(self.KEY_SAML_DISCOVERY_SERVICE_POLICY,
1230-
requested_disco_policy)
1223+
context.decorate(
1224+
self.KEY_SAML_DISCOVERY_SERVICE_POLICY, requested_disco_policy
1225+
)
12311226

12321227
# If provided and known in the SAML metadata set the entityID for
12331228
# the IdP to use for authentication.

0 commit comments

Comments
 (0)