Skip to content

Commit

Permalink
Rename parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
pitbulk committed Dec 22, 2016
1 parent f95abc5 commit 7ac2640
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
8 changes: 4 additions & 4 deletions src/onelogin/saml2/logout_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ def get_session_indexes(request):
session_indexes.append(session_index_node.text)
return session_indexes

def is_valid(self, request_data, raises=False):
def is_valid(self, request_data, raise_exceptions=False):
"""
Checks if the Logout Request received is valid
:param request_data: Request Data
:type request_data: dict
:param raises: Optional argument. If true, the function will raise an exception as soon as first validation test fails
:type raises: bool
:param raise_exceptions: Whether to return false on failure or raise an exception
:type raise_exceptions: Boolean
:return: If the Logout Request is or not valid
:rtype: boolean
Expand Down Expand Up @@ -277,7 +277,7 @@ def is_valid(self, request_data, raises=False):
debug = self.__settings.is_debug_active()
if debug:
print(err)
if raises:
if raise_exceptions:
raise
return False

Expand Down
8 changes: 4 additions & 4 deletions src/onelogin/saml2/logout_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def get_status(self):
status = entries[0].attrib['Value']
return status

def is_valid(self, request_data, request_id=None, raises=False):
def is_valid(self, request_data, request_id=None, raise_exceptions=False):
"""
Determines if the SAML LogoutResponse is valid
:param request_id: The ID of the LogoutRequest sent by this SP to the IdP
:type request_id: string
:param raises: Optional argument. If true, the function will raise an exception as soon as first validation test fails
:type raises: bool
:param raise_exceptions: Whether to return false on failure or raise an exception
:type raise_exceptions: Boolean
:return: Returns if the SAML LogoutResponse is or not valid
:rtype: boolean
Expand Down Expand Up @@ -115,7 +115,7 @@ def is_valid(self, request_data, request_id=None, raises=False):
debug = self.__settings.is_debug_active()
if debug:
print(err)
if raises:
if raise_exceptions:
raise
return False

Expand Down
8 changes: 4 additions & 4 deletions src/onelogin/saml2/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, settings, response):
self.encrypted = True
self.decrypted_document = self.__decrypt_assertion(decrypted_document)

def is_valid(self, request_data, request_id=None, raises=False):
def is_valid(self, request_data, request_id=None, raise_exceptions=False):
"""
Validates the response object.
Expand All @@ -57,8 +57,8 @@ def is_valid(self, request_data, request_id=None, raises=False):
:param request_id: Optional argument. The ID of the AuthNRequest sent by this SP to the IdP
:type request_id: string
:param raises: Optional argument. If true, the function will raise an exception as soon as first validation test fails
:type raises: bool
:param raise_exceptions: Whether to return false on failure or raise an exception
:type raise_exceptions: Boolean
:returns: True if the SAML Response is valid, False if not
:rtype: bool
Expand Down Expand Up @@ -229,7 +229,7 @@ def is_valid(self, request_data, request_id=None, raises=False):
debug = self.__settings.is_debug_active()
if debug:
print(err)
if raises:
if raise_exceptions:
raise
return False

Expand Down
8 changes: 4 additions & 4 deletions tests/src/OneLogin/saml2_tests/logout_request_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def testIsInvalidIssuer(self):
settings.set_strict(True)
logout_request2 = OneLogin_Saml2_Logout_Request(settings, OneLogin_Saml2_Utils.b64encode(request))
with self.assertRaisesRegexp(Exception, 'Invalid issuer in the Logout Request'):
logout_request2.is_valid(request_data, raises=True)
logout_request2.is_valid(request_data, raise_exceptions=True)

def testIsInvalidDestination(self):
"""
Expand All @@ -255,7 +255,7 @@ def testIsInvalidDestination(self):
settings.set_strict(True)
logout_request2 = OneLogin_Saml2_Logout_Request(settings, OneLogin_Saml2_Utils.b64encode(request))
with self.assertRaisesRegexp(Exception, 'The LogoutRequest was received at'):
logout_request2.is_valid(request_data, raises=True)
logout_request2.is_valid(request_data, raise_exceptions=True)

dom = parseString(request)
dom.documentElement.setAttribute('Destination', None)
Expand Down Expand Up @@ -286,7 +286,7 @@ def testIsInvalidNotOnOrAfter(self):
settings.set_strict(True)
logout_request2 = OneLogin_Saml2_Logout_Request(settings, OneLogin_Saml2_Utils.b64encode(request))
with self.assertRaisesRegexp(Exception, 'Timing issues \(please check your clock settings\)'):
logout_request2.is_valid(request_data, raises=True)
logout_request2.is_valid(request_data, raise_exceptions=True)

def testIsValid(self):
"""
Expand Down Expand Up @@ -334,4 +334,4 @@ def testIsValidRaisesExceptionWhenRaisesArgumentIsTrue(self):
self.assertFalse(logout_request.is_valid(request_data))

with self.assertRaises(Exception):
logout_request.is_valid(request_data, raises=True)
logout_request.is_valid(request_data, raise_exceptions=True)
8 changes: 4 additions & 4 deletions tests/src/OneLogin/saml2_tests/logout_response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def testIsInValidIssuer(self):
settings.set_strict(True)
response_2 = OneLogin_Saml2_Logout_Response(settings, message)
with self.assertRaisesRegexp(Exception, 'Invalid issuer in the Logout Request'):
response_2.is_valid(request_data, raises=True)
response_2.is_valid(request_data, raise_exceptions=True)

def testIsInValidDestination(self):
"""
Expand All @@ -224,7 +224,7 @@ def testIsInValidDestination(self):
settings.set_strict(True)
response_2 = OneLogin_Saml2_Logout_Response(settings, message)
with self.assertRaisesRegexp(Exception, 'The LogoutRequest was received at'):
response_2.is_valid(request_data, raises=True)
response_2.is_valid(request_data, raise_exceptions=True)

# Empty destination
dom = parseString(OneLogin_Saml2_Utils.decode_base64_and_inflate(message))
Expand Down Expand Up @@ -259,7 +259,7 @@ def testIsValid(self):
settings.set_strict(True)
response_2 = OneLogin_Saml2_Logout_Response(settings, message)
with self.assertRaisesRegexp(Exception, 'The LogoutRequest was received at'):
response_2.is_valid(request_data, raises=True)
response_2.is_valid(request_data, raise_exceptions=True)

plain_message = compat.to_string(OneLogin_Saml2_Utils.decode_base64_and_inflate(message))
current_url = OneLogin_Saml2_Utils.get_self_url_no_query(request_data)
Expand All @@ -284,4 +284,4 @@ def testIsValidRaisesExceptionWhenRaisesArgumentIsTrue(self):
self.assertFalse(response.is_valid(request_data))

with self.assertRaises(Exception):
response.is_valid(request_data, raises=True)
response.is_valid(request_data, raise_exceptions=True)
40 changes: 20 additions & 20 deletions tests/src/OneLogin/saml2_tests/response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def testValidateVersion(self):
xml = self.file_contents(join(self.data_path, 'responses', 'invalids', 'no_saml2.xml.base64'))
response = OneLogin_Saml2_Response(settings, xml)
with self.assertRaisesRegexp(Exception, 'Unsupported SAML version'):
response.is_valid(self.get_request_data(), raises=True)
response.is_valid(self.get_request_data(), raise_exceptions=True)

def testValidateID(self):
"""
Expand All @@ -504,7 +504,7 @@ def testValidateID(self):
xml = self.file_contents(join(self.data_path, 'responses', 'invalids', 'no_id.xml.base64'))
response = OneLogin_Saml2_Response(settings, xml)
with self.assertRaisesRegexp(Exception, 'Missing ID attribute on SAML Response'):
response.is_valid(self.get_request_data(), raises=True)
response.is_valid(self.get_request_data(), raise_exceptions=True)

def testIsInValidReference(self):
"""
Expand Down Expand Up @@ -534,7 +534,7 @@ def testIsInValidExpired(self):
settings.set_strict(True)
response_2 = OneLogin_Saml2_Response(settings, xml)
with self.assertRaisesRegexp(Exception, 'Timing issues \(please check your clock settings\)'):
response_2.is_valid(self.get_request_data(), raises=True)
response_2.is_valid(self.get_request_data(), raise_exceptions=True)

def testIsInValidNoStatement(self):
"""
Expand Down Expand Up @@ -592,7 +592,7 @@ def testIsInValidNoKey(self):
xml = self.file_contents(join(self.data_path, 'responses', 'invalids', 'no_key.xml.base64'))
response = OneLogin_Saml2_Response(settings, xml)
with self.assertRaisesRegexp(Exception, 'Signature validation failed. SAML Response rejected'):
response.is_valid(self.get_request_data(), raises=True)
response.is_valid(self.get_request_data(), raise_exceptions=True)

def testIsInValidMultipleAssertions(self):
"""
Expand All @@ -604,7 +604,7 @@ def testIsInValidMultipleAssertions(self):
xml = self.file_contents(join(self.data_path, 'responses', 'invalids', 'multiple_assertions.xml.base64'))
response = OneLogin_Saml2_Response(settings, xml)
with self.assertRaisesRegexp(Exception, 'SAML Response must contain 1 assertion'):
response.is_valid(self.get_request_data(), raises=True)
response.is_valid(self.get_request_data(), raise_exceptions=True)

def testIsInValidEncAttrs(self):
"""
Expand All @@ -620,7 +620,7 @@ def testIsInValidEncAttrs(self):
settings.set_strict(True)
response_2 = OneLogin_Saml2_Response(settings, xml)
with self.assertRaisesRegexp(Exception, 'There is an EncryptedAttribute in the Response and this SP not support them'):
response_2.is_valid(self.get_request_data(), raises=True)
response_2.is_valid(self.get_request_data(), raise_exceptions=True)

def testIsInValidDuplicatedAttrs(self):
"""
Expand Down Expand Up @@ -723,11 +723,11 @@ def testIsInValidIssuer(self):
settings.set_strict(True)
response_3 = OneLogin_Saml2_Response(settings, message)
with self.assertRaisesRegexp(Exception, 'Invalid issuer in the Assertion/Response'):
response_3.is_valid(request_data, raises=True)
response_3.is_valid(request_data, raise_exceptions=True)

response_4 = OneLogin_Saml2_Response(settings, message_2)
with self.assertRaisesRegexp(Exception, 'Invalid issuer in the Assertion/Response'):
response_4.is_valid(request_data, raises=True)
response_4.is_valid(request_data, raise_exceptions=True)

def testIsInValidSessionIndex(self):
"""
Expand All @@ -752,7 +752,7 @@ def testIsInValidSessionIndex(self):
settings.set_strict(True)
response_2 = OneLogin_Saml2_Response(settings, message)
with self.assertRaisesRegexp(Exception, 'The attributes have expired, based on the SessionNotOnOrAfter of the AttributeStatement of this Response'):
response_2.is_valid(request_data, raises=True)
response_2.is_valid(request_data, raise_exceptions=True)

def testDatetimeWithMiliseconds(self):
"""
Expand Down Expand Up @@ -843,27 +843,27 @@ def testIsInValidSubjectConfirmation(self):
settings.set_strict(True)
response = OneLogin_Saml2_Response(settings, message)
with self.assertRaisesRegexp(Exception, 'A valid SubjectConfirmation was not found on this Response'):
response.is_valid(request_data, raises=True)
response.is_valid(request_data, raise_exceptions=True)

response_2 = OneLogin_Saml2_Response(settings, message_2)
with self.assertRaisesRegexp(Exception, 'A valid SubjectConfirmation was not found on this Response'):
response_2.is_valid(request_data, raises=True)
response_2.is_valid(request_data, raise_exceptions=True)

response_3 = OneLogin_Saml2_Response(settings, message_3)
with self.assertRaisesRegexp(Exception, 'A valid SubjectConfirmation was not found on this Response'):
response_3.is_valid(request_data, raises=True)
response_3.is_valid(request_data, raise_exceptions=True)

response_4 = OneLogin_Saml2_Response(settings, message_4)
with self.assertRaisesRegexp(Exception, 'A valid SubjectConfirmation was not found on this Response'):
response_4.is_valid(request_data, raises=True)
response_4.is_valid(request_data, raise_exceptions=True)

response_5 = OneLogin_Saml2_Response(settings, message_5)
with self.assertRaisesRegexp(Exception, 'A valid SubjectConfirmation was not found on this Response'):
response_5.is_valid(request_data, raises=True)
response_5.is_valid(request_data, raise_exceptions=True)

response_6 = OneLogin_Saml2_Response(settings, message_6)
with self.assertRaisesRegexp(Exception, 'A valid SubjectConfirmation was not found on this Response'):
response_6.is_valid(request_data, raises=True)
response_6.is_valid(request_data, raise_exceptions=True)

def testIsInValidRequestId(self):
"""
Expand All @@ -889,7 +889,7 @@ def testIsInValidRequestId(self):
settings.set_strict(True)
response = OneLogin_Saml2_Response(settings, message)
with self.assertRaisesRegexp(Exception, 'The InResponseTo of the Response'):
response.is_valid(request_data, request_id, raises=True)
response.is_valid(request_data, request_id, raise_exceptions=True)

valid_request_id = '_57bcbf70-7b1f-012e-c821-782bcb13bb38'
response.is_valid(request_data, valid_request_id)
Expand Down Expand Up @@ -934,7 +934,7 @@ def testIsInValidSignIssues(self):
settings_4 = OneLogin_Saml2_Settings(settings_info)
response_4 = OneLogin_Saml2_Response(settings_4, message)
with self.assertRaisesRegexp(Exception, 'The Assertion of the Response is not signed and the SP require it'):
response_4.is_valid(request_data, raises=True)
response_4.is_valid(request_data, raise_exceptions=True)

settings_info['security']['wantAssertionsSigned'] = False
settings_info['strict'] = False
Expand Down Expand Up @@ -962,7 +962,7 @@ def testIsInValidSignIssues(self):
settings_8 = OneLogin_Saml2_Settings(settings_info)
response_8 = OneLogin_Saml2_Response(settings_8, message)
with self.assertRaisesRegexp(Exception, 'The Message of the Response is not signed and the SP require it'):
response_8.is_valid(request_data, raises=True)
response_8.is_valid(request_data, raise_exceptions=True)

def testIsInValidEncIssues(self):
"""
Expand Down Expand Up @@ -1044,7 +1044,7 @@ def testIsInValidCert(self):
response = OneLogin_Saml2_Response(settings, xml)

with self.assertRaisesRegexp(Exception, 'failed to load key'):
response.is_valid(self.get_request_data(), raises=True)
response.is_valid(self.get_request_data(), raise_exceptions=True)

def testIsInValidCert2(self):
"""
Expand Down Expand Up @@ -1270,4 +1270,4 @@ def testIsValidRaisesExceptionWhenRaisesArgumentIsTrue(self):
self.assertFalse(response.is_valid(self.get_request_data()))

with self.assertRaises(Exception):
response.is_valid(self.get_request_data(), raises=True)
response.is_valid(self.get_request_data(), raise_exceptions=True)

0 comments on commit 7ac2640

Please sign in to comment.