Skip to content

Commit 37788e2

Browse files
committed
Suggested changes
1 parent a510f16 commit 37788e2

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
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
@@ -166,7 +166,7 @@ def get_nameid_data(request, key=None):
166166

167167
if name_id is None:
168168
raise OneLogin_Saml2_ValidationError(
169-
'Not NameID found in the Logout Request',
169+
'NameID not found in the Logout Request',
170170
OneLogin_Saml2_ValidationError.NO_NAMEID
171171
)
172172

src/onelogin/saml2/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def get_nameid_data(self):
402402
security = self.__settings.get_security_data()
403403
if security.get('wantNameId', True):
404404
raise OneLogin_Saml2_ValidationError(
405-
'Not NameID found in the assertion of the Response',
405+
'NameID not found in the assertion of the Response',
406406
OneLogin_Saml2_ValidationError.NO_NAMEID
407407
)
408408
else:

src/onelogin/saml2/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,15 @@ def validate_node_sign(signature_node, elem, cert=None, fingerprint=None, finger
909909
dsig_ctx.key = xmlsec.Key.from_memory(cert, xmlsec.KeyFormat.CERT_PEM, None)
910910

911911
dsig_ctx.set_enabled_key_data([xmlsec.KeyData.X509])
912-
dsig_ctx.verify(signature_node)
912+
913+
try:
914+
dsig_ctx.verify(signature_node)
915+
except Exception as err:
916+
raise OneLogin_Saml2_ValidationError(
917+
'Signature validation failed. SAML Response rejected',
918+
OneLogin_Saml2_ValidationError.INVALID_SIGNATURE,
919+
str(err)
920+
)
913921

914922
return True
915923

tests/src/OneLogin/saml2_tests/logout_request_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ def testGetNameIdData(self):
138138
encrypted_id_nodes = dom_2.getElementsByTagName('saml:EncryptedID')
139139
encrypted_data = encrypted_id_nodes[0].firstChild.nextSibling
140140
encrypted_id_nodes[0].removeChild(encrypted_data)
141-
with self.assertRaisesRegexp(Exception, 'Not NameID found in the Logout Request'):
141+
with self.assertRaisesRegexp(Exception, 'NameID not found in the Logout Request'):
142142
OneLogin_Saml2_Logout_Request.get_nameid(dom_2.toxml(), key)
143143

144144
inv_request = self.file_contents(join(self.data_path, 'logout_requests', 'invalids', 'no_nameId.xml'))
145-
with self.assertRaisesRegexp(Exception, 'Not NameID found in the Logout Request'):
145+
with self.assertRaisesRegexp(Exception, 'NameID not found in the Logout Request'):
146146
OneLogin_Saml2_Logout_Request.get_nameid(inv_request)
147147

148148
def testGetNameId(self):

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ def testReturnNameId(self):
9898

9999
xml_4 = self.file_contents(join(self.data_path, 'responses', 'invalids', 'no_nameid.xml.base64'))
100100
response_4 = OneLogin_Saml2_Response(settings, xml_4)
101-
with self.assertRaisesRegexp(Exception, 'Not NameID found in the assertion of the Response'):
101+
with self.assertRaisesRegexp(Exception, 'NameID not found in the assertion of the Response'):
102102
response_4.get_nameid()
103103

104104
json_settings['security']['wantNameId'] = True
105105
settings = OneLogin_Saml2_Settings(json_settings)
106106

107107
response_5 = OneLogin_Saml2_Response(settings, xml_4)
108-
with self.assertRaisesRegexp(Exception, 'Not NameID found in the assertion of the Response'):
108+
with self.assertRaisesRegexp(Exception, 'NameID not found in the assertion of the Response'):
109109
response_5.get_nameid()
110110

111111
json_settings['security']['wantNameId'] = False
@@ -119,7 +119,7 @@ def testReturnNameId(self):
119119
settings = OneLogin_Saml2_Settings(json_settings)
120120

121121
response_7 = OneLogin_Saml2_Response(settings, xml_4)
122-
with self.assertRaisesRegexp(Exception, 'Not NameID found in the assertion of the Response'):
122+
with self.assertRaisesRegexp(Exception, 'NameID not found in the assertion of the Response'):
123123
response_7.get_nameid()
124124

125125
json_settings['strict'] = True
@@ -172,14 +172,14 @@ def testGetNameIdData(self):
172172

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

178178
json_settings['security']['wantNameId'] = True
179179
settings = OneLogin_Saml2_Settings(json_settings)
180180

181181
response_5 = OneLogin_Saml2_Response(settings, xml_4)
182-
with self.assertRaisesRegexp(Exception, 'Not NameID found in the assertion of the Response'):
182+
with self.assertRaisesRegexp(Exception, 'NameID not found in the assertion of the Response'):
183183
response_5.get_nameid_data()
184184

185185
json_settings['security']['wantNameId'] = False
@@ -193,7 +193,7 @@ def testGetNameIdData(self):
193193
settings = OneLogin_Saml2_Settings(json_settings)
194194

195195
response_7 = OneLogin_Saml2_Response(settings, xml_4)
196-
with self.assertRaisesRegexp(Exception, 'Not NameID found in the assertion of the Response'):
196+
with self.assertRaisesRegexp(Exception, 'NameID not found in the assertion of the Response'):
197197
response_7.get_nameid_data()
198198

199199
json_settings['security']['wantNameId'] = False
@@ -207,7 +207,7 @@ def testGetNameIdData(self):
207207
settings = OneLogin_Saml2_Settings(json_settings)
208208

209209
response_7 = OneLogin_Saml2_Response(settings, xml_4)
210-
with self.assertRaisesRegexp(Exception, 'Not NameID found in the assertion of the Response'):
210+
with self.assertRaisesRegexp(Exception, 'NameID not found in the assertion of the Response'):
211211
response_7.get_nameid_data()
212212

213213
json_settings['strict'] = True

0 commit comments

Comments
 (0)