11import datetime
2- import pytz
32import inspect
43import logging
54
5+ import pytz
66from saml2 import samlp
77
88# to load state from a cookie
@@ -34,7 +34,7 @@ def __init__(
3434 authn_context_class_ref = "https://www.spid.gov.it/SpidL2" ,
3535 return_addrs = [],
3636 allowed_acrs = [],
37- cie_mode = False
37+ cie_mode = False
3838 ):
3939
4040 self .response = samlp .response_from_string (authn_response )
@@ -67,7 +67,8 @@ def validate_destination(self):
6767 or self .response .destination not in self .return_addrs
6868 ):
6969 _msg = (
70- f'Destination is not valid: { self .response .destination or "" } not in { self .return_addrs } .'
70+ f'Destination is not valid: {
71+ self .response .destination or "" } not in { self .return_addrs } .'
7172 f"{ _ERROR_TROUBLESHOOT } "
7273 )
7374 raise SPIDValidatorException (_msg )
@@ -86,7 +87,8 @@ def validate_issuer(self):
8687 != "urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
8788 ):
8889 raise SPIDValidatorException (
89- f"Issuer NameFormat is invalid: { self .response .issuer .format } "
90+ f"Issuer NameFormat is invalid: {
91+ self .response .issuer .format } "
9092 '!= "urn:oasis:names:tc:SAML:2.0:nameid-format:entity"'
9193 )
9294
@@ -96,7 +98,8 @@ def validate_issuer(self):
9698 assiss = self .response .assertion [0 ].issuer
9799 if not hasattr (assiss , "format" ) or not getattr (assiss , "format" , None ):
98100 raise SPIDValidatorException (
99- msg .format (self .response .issuer .format , _ERROR_TROUBLESHOOT )
101+ msg .format (self .response .issuer .format ,
102+ _ERROR_TROUBLESHOOT )
100103 )
101104
102105 # 72
@@ -158,11 +161,13 @@ def validate_name_qualifier(self):
158161 )
159162 if not i .subject .name_id .format :
160163 raise SPIDValidatorException (
161- "Not a valid subject.name_id.format" f"{ _ERROR_TROUBLESHOOT } "
164+ "Not a valid subject.name_id.format" f"{
165+ _ERROR_TROUBLESHOOT } "
162166 )
163167 if i .subject .name_id .format not in self .nameid_formats :
164168 msg = (
165- f"Not a valid subject.name_id.format: { i .subject .name_id .format } "
169+ f"Not a valid subject.name_id.format: {
170+ i .subject .name_id .format } "
166171 f"{ _ERROR_TROUBLESHOOT } "
167172 )
168173 raise SPIDValidatorException (msg )
@@ -248,7 +253,8 @@ def validate_assertion_conditions(self):
248253 if not hasattr (i , "conditions" ) or not getattr (i , "conditions" , None ):
249254 # or not i.conditions.text.strip(' ').strip('\n'):
250255 raise SPIDValidatorException (
251- "Assertion conditions not present. " f"{ _ERROR_TROUBLESHOOT } "
256+ "Assertion conditions not present. " f"{
257+ _ERROR_TROUBLESHOOT } "
252258 )
253259
254260 # 75, 76
@@ -327,7 +333,8 @@ def validate_assertion_authn_statement(self):
327333 ):
328334 _msg = (
329335 "Invalid Spid authn_context_class_ref, requested: "
330- f"{ self .authn_context_class_ref } , got { authns .authn_context .authn_context_class_ref .text } "
336+ f"{ self .authn_context_class_ref } , got {
337+ authns .authn_context .authn_context_class_ref .text } "
331338 )
332339 try :
333340 level_sp = int (self .authn_context_class_ref [- 1 ])
0 commit comments