Skip to content

Commit 3b94b70

Browse files
committed
Some minor improvements based on suggestions
1 parent 731d01f commit 3b94b70

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

src/onelogin/saml2/errors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class OneLogin_Saml2_Error(Exception):
2525
SETTINGS_INVALID_SYNTAX = 1
2626
SETTINGS_INVALID = 2
2727
METADATA_SP_INVALID = 3
28+
# SP_CERTS_NOT_FOUND is deprecated, use CERT_NOT_FOUND instead
29+
SP_CERTS_NOT_FOUND = 4
2830
CERT_NOT_FOUND = 4
2931
REDIRECT_INVALID_URL = 5
3032
PUBLIC_CERT_FILE_NOT_FOUND = 6

src/onelogin/saml2/logout_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def get_nameid_data(request, key=None):
196196

197197
if name_id is None:
198198
raise OneLogin_Saml2_ValidationError(
199-
'Not NameID found in the Logout Request',
199+
'NameID not found in the Logout Request',
200200
OneLogin_Saml2_ValidationError.NO_NAMEID
201201
)
202202

src/onelogin/saml2/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def get_nameid_data(self):
417417

418418
if security.get('wantNameId', True):
419419
raise OneLogin_Saml2_ValidationError(
420-
'Not NameID found in the assertion of the Response',
420+
'NameID not found in the assertion of the Response',
421421
OneLogin_Saml2_ValidationError.NO_NAMEID
422422
)
423423
else:

src/onelogin/saml2/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,14 @@ def validate_node_sign(signature_node, elem, cert=None, fingerprint=None, finger
11181118

11191119
dsig_ctx.setEnabledKeyData([xmlsec.KeyDataX509])
11201120

1121-
dsig_ctx.verify(signature_node)
1121+
try:
1122+
dsig_ctx.verify(signature_node)
1123+
except Exception as err:
1124+
raise OneLogin_Saml2_ValidationError(
1125+
'Signature validation failed. SAML Response rejected. %s',
1126+
OneLogin_Saml2_ValidationError.INVALID_SIGNATURE,
1127+
err.__str__()
1128+
)
11221129

11231130
return True
11241131

tests/src/OneLogin/saml2_tests/logout_request_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ def testGetNameIdData(self):
131131
encrypted_id_nodes = dom_2.getElementsByTagName('saml:EncryptedID')
132132
encrypted_data = encrypted_id_nodes[0].firstChild.nextSibling
133133
encrypted_id_nodes[0].removeChild(encrypted_data)
134-
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'Not NameID found in the Logout Request'):
134+
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'NameID not found in the Logout Request'):
135135
OneLogin_Saml2_Logout_Request.get_nameid_data(dom_2.toxml(), key)
136136

137137
inv_request = self.file_contents(join(self.data_path, 'logout_requests', 'invalids', 'no_nameId.xml'))
138-
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'Not NameID found in the Logout Request'):
138+
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'NameID not found in the Logout Request'):
139139
OneLogin_Saml2_Logout_Request.get_nameid_data(inv_request)
140140

141141
def testGetNameId(self):

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ def testReturnNameId(self):
100100

101101
xml_4 = self.file_contents(join(self.data_path, 'responses', 'invalids', 'no_nameid.xml.base64'))
102102
response_4 = OneLogin_Saml2_Response(settings, xml_4)
103-
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'Not NameID found in the assertion of the Response'):
103+
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'NameID not found in the assertion of the Response'):
104104
response_4.get_nameid()
105105

106106
json_settings['security']['wantNameId'] = True
107107
settings = OneLogin_Saml2_Settings(json_settings)
108108

109109
response_5 = OneLogin_Saml2_Response(settings, xml_4)
110-
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'Not NameID found in the assertion of the Response'):
110+
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'NameID not found in the assertion of the Response'):
111111
response_5.get_nameid()
112112

113113
json_settings['security']['wantNameId'] = False
@@ -121,7 +121,7 @@ def testReturnNameId(self):
121121
settings = OneLogin_Saml2_Settings(json_settings)
122122

123123
response_7 = OneLogin_Saml2_Response(settings, xml_4)
124-
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'Not NameID found in the assertion of the Response'):
124+
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'NameID not found in the assertion of the Response'):
125125
response_7.get_nameid()
126126

127127
json_settings['strict'] = True
@@ -175,14 +175,14 @@ def testGetNameIdData(self):
175175

176176
xml_4 = self.file_contents(join(self.data_path, 'responses', 'invalids', 'no_nameid.xml.base64'))
177177
response_4 = OneLogin_Saml2_Response(settings, xml_4)
178-
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'Not NameID found in the assertion of the Response'):
178+
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'NameID not found in the assertion of the Response'):
179179
response_4.get_nameid_data()
180180

181181
json_settings['security']['wantNameId'] = True
182182
settings = OneLogin_Saml2_Settings(json_settings)
183183

184184
response_5 = OneLogin_Saml2_Response(settings, xml_4)
185-
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'Not NameID found in the assertion of the Response'):
185+
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'NameID not found in the assertion of the Response'):
186186
response_5.get_nameid_data()
187187

188188
json_settings['security']['wantNameId'] = False
@@ -196,7 +196,7 @@ def testGetNameIdData(self):
196196
settings = OneLogin_Saml2_Settings(json_settings)
197197

198198
response_7 = OneLogin_Saml2_Response(settings, xml_4)
199-
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'Not NameID found in the assertion of the Response'):
199+
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'NameID not found in the assertion of the Response'):
200200
response_7.get_nameid_data()
201201

202202
json_settings['strict'] = True

0 commit comments

Comments
 (0)