@@ -125,6 +125,13 @@ def get_next_path(self, request: HttpRequest) -> str:
125
125
next_path = validate_referral_url (request , next_path )
126
126
return next_path
127
127
128
+ def unknown_idp (self , request , idp ):
129
+ msg = (f'Error: IdP EntityID { idp } was not found in metadata' )
130
+ logger .error (msg )
131
+ return HttpResponse (
132
+ msg .format ('Please contact technical support.' ), status = 403
133
+ )
134
+
128
135
def get (self , request , * args , ** kwargs ):
129
136
logger .debug ('Login process started' )
130
137
next_path = self .get_next_path (request )
@@ -149,10 +156,10 @@ def get(self, request, *args, **kwargs):
149
156
150
157
try :
151
158
conf = self .get_sp_config (request )
152
- except SourceNotFound as excp :
153
- msg = ( 'Error, IdP EntityID was not found in metadata: {}' )
154
- logger . exception ( msg . format ( excp ) )
155
- return HttpResponse ( msg . format ( 'Please contact technical support.' ), status = 500 )
159
+ except SourceNotFound as excp : # pragma: no cover
160
+ # this is deprecated and it's here only for the doubts that something
161
+ # would happen the day after I'll remove it! : )
162
+ return self . unknown_idp ( request , idp = 'unknown' )
156
163
157
164
# is a embedded wayf or DiscoveryService needed?
158
165
configured_idps = available_idps (conf )
@@ -186,9 +193,9 @@ def get(self, request, *args, **kwargs):
186
193
})
187
194
188
195
# is the first one, otherwise next logger message will print None
189
- if not configured_idps :
196
+ if not configured_idps : # pragma: no cover
190
197
raise IdPConfigurationMissing (
191
- ('IdP configuration is missing or its metadata is expired.' ))
198
+ ('IdP is missing or its metadata is expired.' ))
192
199
if selected_idp is None :
193
200
selected_idp = list (configured_idps .keys ())[0 ]
194
201
@@ -202,15 +209,17 @@ def get(self, request, *args, **kwargs):
202
209
)
203
210
sso_kwargs ['scoping' ] = idp_scoping
204
211
205
-
206
212
# choose a binding to try first
207
213
binding = getattr (settings , 'SAML_DEFAULT_BINDING' ,
208
214
saml2 .BINDING_HTTP_POST )
209
215
logger .debug (f'Trying binding { binding } for IDP { selected_idp } ' )
210
216
211
217
# ensure our selected binding is supported by the IDP
212
- supported_bindings = get_idp_sso_supported_bindings (
213
- selected_idp , config = conf )
218
+ try :
219
+ supported_bindings = get_idp_sso_supported_bindings (
220
+ selected_idp , config = conf )
221
+ except saml2 .s_utils .UnknownSystemEntity :
222
+ return self .unknown_idp (request , selected_idp )
214
223
215
224
if binding not in supported_bindings :
216
225
logger .debug (
@@ -223,17 +232,17 @@ def get(self, request, *args, **kwargs):
223
232
f'trying { saml2 .BINDING_HTTP_REDIRECT } ' ,
224
233
)
225
234
binding = saml2 .BINDING_HTTP_REDIRECT
226
- else :
235
+ else : # pragma: no cover
227
236
logger .warning (
228
237
f'IDP { selected_idp } does not support { binding } '
229
238
f'trying { saml2 .BINDING_HTTP_POST } ' ,
230
239
)
231
240
binding = saml2 .BINDING_HTTP_POST
232
241
# if switched binding still not supported, give up
233
- if binding not in supported_bindings :
242
+ if binding not in supported_bindings : # pragma: no cover
234
243
raise UnsupportedBinding (
235
244
f'IDP { selected_idp } does not support '
236
- f'{ saml2 .BINDING_HTTP_POST } and { saml2 .BINDING_HTTP_REDIRECT } '
245
+ f'{ saml2 .BINDING_HTTP_POST } or { saml2 .BINDING_HTTP_REDIRECT } '
237
246
)
238
247
239
248
client = Saml2Client (conf )
0 commit comments