Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deflate as parameter #251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ This is the ``settings.json`` file:
// Enable debug mode (outputs errors).
"debug": true,

// Enable deflate mode (request compression).
"deflate": true,

// Service Provider Data that we are deploying.
"sp": {
// Identifier of the SP entity (must be a URI)
Expand Down Expand Up @@ -1049,6 +1052,7 @@ Configuration of the OneLogin Python Toolkit
* ***set_strict*** Activates or deactivates the strict mode.
* ***is_strict*** Returns if the ``strict`` mode is active.
* ***is_debug_active*** Returns if the debug is active.
* ***is_deflate_active*** Returns if the deflate is active.

#### OneLogin_Saml2_Metadata - metadata.py ####

Expand Down
6 changes: 2 additions & 4 deletions src/onelogin/saml2/authn_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,13 @@ def _generate_request_id(self):
"""
return OneLogin_Saml2_Utils.generate_unique_id()

def get_request(self, deflate=True):
def get_request(self):
"""
Returns unsigned AuthnRequest.
:param deflate: It makes the deflate process optional
:type: bool
:return: AuthnRequest maybe deflated and base64 encoded
:rtype: str object
"""
if deflate:
if self.__settings.is_deflate_active():
request = OneLogin_Saml2_Utils.deflate_and_base64_encode(self.__authn_request)
else:
request = OneLogin_Saml2_Utils.b64encode(self.__authn_request)
Expand Down
6 changes: 2 additions & 4 deletions src/onelogin/saml2/logout_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,13 @@ def __init__(self, settings, request=None, name_id=None, session_index=None, nq=

self.__logout_request = compat.to_string(logout_request)

def get_request(self, deflate=True):
def get_request(self):
"""
Returns the Logout Request deflated, base64encoded
:param deflate: It makes the deflate process optional
:type: bool
:return: Logout Request maybe deflated and base64 encoded
:rtype: str object
"""
if deflate:
if self.__settings.is_deflate_active():
request = OneLogin_Saml2_Utils.deflate_and_base64_encode(self.__logout_request)
else:
request = OneLogin_Saml2_Utils.b64encode(self.__logout_request)
Expand Down
11 changes: 11 additions & 0 deletions src/onelogin/saml2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(self, settings=None, custom_base_path=None, sp_validation_only=Fals
self.__paths = {}
self.__strict = True
self.__debug = False
self.__deflate = True
self.__sp = {}
self.__idp = {}
self.__security = {}
Expand Down Expand Up @@ -229,6 +230,7 @@ def __load_settings_from_dict(self, settings):
self.__idp = settings.get('idp', {})
self.__strict = settings.get('strict', True)
self.__debug = settings.get('debug', False)
self.__deflate = settings.get('deflate', True)
self.__security = settings.get('security', {})
self.__contacts = settings.get('contactPerson', {})
self.__organization = settings.get('organization', {})
Expand Down Expand Up @@ -849,6 +851,15 @@ def is_debug_active(self):
"""
return self.__debug

def is_deflate_active(self):
"""
Returns if the deflate is active.

:returns: Deflate parameter
:rtype: boolean
"""
return self.__deflate

def _get_allow_single_label_domain(self, settings):
security = settings.get('security', {})
return 'allowSingleLabelDomains' in security.keys() and security['allowSingleLabelDomains']
1 change: 1 addition & 0 deletions tests/settings/settings1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
"entityId": "http://stuff.com/endpoints/metadata.php",
Expand Down
1 change: 1 addition & 0 deletions tests/settings/settings10.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"sp": {
"entityId": "http://stuff.com/endpoints/metadata.php",
"assertionConsumerService": {
Expand Down
1 change: 1 addition & 0 deletions tests/settings/settings2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
"entityId": "http://stuff.com/endpoints/metadata.php",
Expand Down
1 change: 1 addition & 0 deletions tests/settings/settings3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
"entityId": "http://pytoolkit.com:8000/metadata/",
Expand Down
1 change: 1 addition & 0 deletions tests/settings/settings4.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
"entityId": "http://pytoolkit.com:8000/metadata/",
Expand Down
1 change: 1 addition & 0 deletions tests/settings/settings5.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
"entityId": "http://pytoolkit.com:8000/metadata/",
Expand Down
1 change: 1 addition & 0 deletions tests/settings/settings6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
"entityId": "http://stuff.com/endpoints/metadata.php",
Expand Down
1 change: 1 addition & 0 deletions tests/settings/settings7.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
"entityId": "http://stuff.com/endpoints/metadata.php",
Expand Down
1 change: 1 addition & 0 deletions tests/settings/settings8.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
"entityId": "http://stuff.com/endpoints/metadata.php",
Expand Down
1 change: 1 addition & 0 deletions tests/settings/settings9.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"strict": false,
"debug": false,
"deflate": true,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
"entityId": "http://stuff.com/endpoints/metadata.php",
Expand Down
2 changes: 1 addition & 1 deletion tests/src/OneLogin/saml2_tests/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ def testIsInValidLogoutResponseSign(self):

def testIsValidLogoutRequestSign(self):
"""
Tests the is_valid method of the OneLogin_Saml2_LogoutRequest
Tests the is_valid method of the OneLogin_Saml2_Logout_Request
"""
request_data = {
'http_host': 'example.com',
Expand Down
23 changes: 23 additions & 0 deletions tests/src/OneLogin/saml2_tests/authn_request_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,26 @@ def testAttributeConsumingService(self):
inflated = compat.to_string(OneLogin_Saml2_Utils.decode_base64_and_inflate(authn_request_encoded))

self.assertRegex(inflated, 'AttributeConsumingServiceIndex="1"')

def testGetRequest(self):
"""
Tests the get_request method of the OneLogin_Saml2_Authn_Request.
"""
saml_settings = self.loadSettingsJSON()
saml_settings['deflate'] = True
settings = OneLogin_Saml2_Settings(saml_settings)

authn_request = OneLogin_Saml2_Authn_Request(settings)
authn_request_xml = authn_request.get_xml()

authn_request_encoded = authn_request.get_request()
self.assertEqual(authn_request_encoded, OneLogin_Saml2_Utils.deflate_and_base64_encode(authn_request_xml))

saml_settings['deflate'] = False
settings = OneLogin_Saml2_Settings(saml_settings)

authn_request = OneLogin_Saml2_Authn_Request(settings)
authn_request_xml = authn_request.get_xml()

authn_request_encoded = authn_request.get_request()
self.assertEqual(authn_request_encoded, OneLogin_Saml2_Utils.b64encode(authn_request_xml))
3 changes: 3 additions & 0 deletions tests/src/OneLogin/saml2_tests/idp_metadata_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def test_merge_settings(self):
"signMetadata": false
},
"debug": false,
"deflate": true,
"organization": {
"en-US": {
"displayname": "SP test",
Expand All @@ -532,6 +533,7 @@ def test_merge_settings(self):
expected_settings2_json = """
{
"debug": false,
"deflate": true,
"idp": {
"singleLogoutService": {
"url": "http://idp.example.com/SingleLogoutService.php"
Expand Down Expand Up @@ -589,6 +591,7 @@ def test_merge_settings(self):
expected_settings3_json = """
{
"debug": false,
"deflate": true,
"strict": false,
"custom_base_path": "../../../tests/data/customPath/",
"sp": {
Expand Down
Loading