From 7c5b1158448281c181e7a181859963e9945d4a88 Mon Sep 17 00:00:00 2001 From: jchenggggg Date: Fri, 16 Jul 2021 11:08:06 -0400 Subject: [PATCH] Update the update_settings with new helpdesk enrollment email param (#147) * Update the update_settings with new helpdesk enrollment email param, and mark legacy params as deprecated * Remove extra files and try to fix tests * Remove unneeded files --- duo_client/admin.py | 31 +++++++-------- tests/admin/test_settings.py | 76 ++++++++++++++++++++++++++++++++++++ tests/admin/test_users.py | 4 +- tests/test_client.py | 2 +- tests/util.py | 3 +- 5 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 tests/admin/test_settings.py diff --git a/duo_client/admin.py b/duo_client/admin.py index f8bd79f..b2cffdb 100644 --- a/duo_client/admin.py +++ b/duo_client/admin.py @@ -1733,6 +1733,7 @@ def update_settings(self, helpdesk_bypass=None, helpdesk_bypass_expiration=None, helpdesk_message=None, + helpdesk_can_send_enroll_email=None, reactivation_url=None, reactivation_integration_key=None, security_checkup_enabled=None, @@ -1755,11 +1756,11 @@ def update_settings(self, timezone - |None telephony_warning_min - caller_id - - push_enabled - True|False|None - sms_enabled - True|False|None - voice_enabled - True|False|None - mobile_otp_enabled - True|False|None - u2f_enabled - True|False|None + push_enabled - Deprecated; ignored if specified. + sms_enabled - Deprecated; ignored if specified. + voice_enabled - Deprecated; ignored if specified. + mobile_otp_enabled - Deprecated; ignored if specified. + u2f_enabled - Deprecated; ignored if specified. user_telephony_cost_max - minimum_password_length - |None password_requires_upper_alpha - True|False|None @@ -1769,6 +1770,7 @@ def update_settings(self, helpdesk_bypass - "allow"|"limit"|"deny"|None helpdesk_bypass_expiration - |0 helpdesk_message - + helpdesk_can_send_enroll_email - True|False|None reactivation_url - |None reactivation_integration_key - |None security_checkup_enabled - True|False|None @@ -1798,7 +1800,8 @@ def update_settings(self, if fraud_email is not None: params['fraud_email'] = fraud_email if fraud_email_enabled is not None: - params['fraud_email_enabled'] = fraud_email_enabled + params['fraud_email_enabled'] = ('1' if + fraud_email_enabled else '0') if keypress_confirm is not None: params['keypress_confirm'] = keypress_confirm if keypress_fraud is not None: @@ -1809,16 +1812,6 @@ def update_settings(self, params['telephony_warning_min'] = str(telephony_warning_min) if caller_id is not None: params['caller_id'] = caller_id - if push_enabled is not None: - params['push_enabled'] = '1' if push_enabled else '0' - if sms_enabled is not None: - params['sms_enabled'] = '1' if sms_enabled else '0' - if voice_enabled is not None: - params['voice_enabled'] = '1' if voice_enabled else '0' - if mobile_otp_enabled is not None: - params['mobile_otp_enabled'] = '1' if mobile_otp_enabled else '0' - if u2f_enabled is not None: - params['u2f_enabled'] = '1' if u2f_enabled else '0' if user_telephony_cost_max is not None: params['user_telephony_cost_max'] = str(user_telephony_cost_max) if minimum_password_length is not None: @@ -1841,12 +1834,16 @@ def update_settings(self, params['helpdesk_bypass_expiration'] = str(helpdesk_bypass_expiration) if helpdesk_message is not None: params['helpdesk_message'] = str(helpdesk_message) + if helpdesk_can_send_enroll_email is not None: + params['helpdesk_can_send_enroll_email'] = ('1' if + helpdesk_can_send_enroll_email else '0') if reactivation_url is not None: params['reactivation_url'] = reactivation_url if reactivation_integration_key is not None: params['reactivation_integration_key'] = reactivation_integration_key if security_checkup_enabled is not None: - params['security_checkup_enabled'] = security_checkup_enabled + params['security_checkup_enabled'] = ('1' if + security_checkup_enabled else '0') if not params: raise TypeError("No settings were provided") diff --git a/tests/admin/test_settings.py b/tests/admin/test_settings.py new file mode 100644 index 0000000..207d222 --- /dev/null +++ b/tests/admin/test_settings.py @@ -0,0 +1,76 @@ +from .. import util +import duo_client.admin +from .base import TestAdmin + + +class TestSettings(TestAdmin): + + def test_update_settings(self): + """ Test updating settings + """ + response = self.client_list.update_settings( + lockout_threshold=10, + lockout_expire_duration=60, + inactive_user_expiration=30, + log_retention_days=180, + sms_batch=5, + sms_expiration=60, + sms_refresh=True, + sms_message='test_message', + fraud_email='test@example.com', + fraud_email_enabled=True, + keypress_confirm='0', + keypress_fraud='9', + timezone='UTC', + telephony_warning_min=50, + caller_id='+15035551000', + user_telephony_cost_max=10, + minimum_password_length=12, + password_requires_upper_alpha=True, + password_requires_lower_alpha=True, + password_requires_numeric=True, + password_requires_special=True, + helpdesk_bypass="allow", + helpdesk_bypass_expiration=60, + helpdesk_message="test_message", + helpdesk_can_send_enroll_email=True, + reactivation_url="https://www.example.com", + reactivation_integration_key='DINTEGRATIONKEYTEST0', + security_checkup_enabled=True, + ) + response = response[0] + self.assertEqual(response['method'], 'POST') + self.assertEqual(response['uri'], '/admin/v1/settings') + self.assertEqual( + util.params_to_dict(response['body']), + { + 'account_id': [self.client.account_id], + 'lockout_threshold': ['10'], + 'lockout_expire_duration': ['60'], + 'inactive_user_expiration': ['30'], + 'log_retention_days': ['180'], + 'sms_batch': ['5'], + 'sms_expiration': ['60'], + 'sms_refresh': ['1'], + 'sms_message': ['test_message'], + 'fraud_email': ['test@example.com'], + 'fraud_email_enabled': ['1'], + 'keypress_confirm': ['0'], + 'keypress_fraud': ['9'], + 'timezone': ['UTC'], + 'telephony_warning_min': ['50'], + 'caller_id': ['+15035551000'], + 'user_telephony_cost_max': ['10'], + 'minimum_password_length': ['12'], + 'password_requires_upper_alpha': ['1'], + 'password_requires_lower_alpha': ['1'], + 'password_requires_numeric': ['1'], + 'password_requires_special': ['1'], + 'helpdesk_bypass': ['allow'], + 'helpdesk_bypass_expiration': ['60'], + 'helpdesk_message': ['test_message'], + 'helpdesk_can_send_enroll_email': ['1'], + 'reactivation_url': ['https://www.example.com'], + 'reactivation_integration_key': ['DINTEGRATIONKEYTEST0'], + 'security_checkup_enabled': ['1'], + }) diff --git a/tests/admin/test_users.py b/tests/admin/test_users.py index 6877cd0..6ad8323 100644 --- a/tests/admin/test_users.py +++ b/tests/admin/test_users.py @@ -117,7 +117,7 @@ def test_add_user(self): 'notes': ['notes'], 'username': ['foo'], 'status': ['active'], - 'email': ['foobar%40baz.com'], + 'email': ['foobar@baz.com'], 'firstname': ['fName'], 'lastname': ['lName'], 'account_id': [self.client.account_id], @@ -151,7 +151,7 @@ def test_update_user(self): 'notes': ['notes'], 'username': ['foo'], 'status': ['active'], - 'email': ['foobar%40baz.com'], + 'email': ['foobar@baz.com'], 'firstname': ['fName'], 'lastname': ['lName'], 'account_id': [self.client.account_id], diff --git a/tests/test_client.py b/tests/test_client.py index dc9138f..b4a53db 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -284,7 +284,7 @@ class TestRequest(unittest.TestCase): 'foo':['bar'], 'baz':['qux', 'quux=quuux', 'foobar=foobar&barbaz=barbaz']} args_out = dict( - (key, [six.moves.urllib.parse.quote(v) for v in val]) + (key, [v for v in val]) for (key, val) in list(args_in.items())) def setUp(self): diff --git a/tests/util.py b/tests/util.py index da5d0b1..68d6af5 100644 --- a/tests/util.py +++ b/tests/util.py @@ -1,6 +1,7 @@ from __future__ import absolute_import import json import collections +import urllib from json import JSONEncoder import duo_client @@ -14,7 +15,7 @@ def default(self, obj): def params_to_dict(param_str): param_dict = collections.defaultdict(list) for (key, val) in (param.split('=') for param in param_str.split('&')): - param_dict[key].append(val) + param_dict[key].append(six.moves.urllib.parse.unquote(val)) return param_dict