Skip to content

Commit

Permalink
Update the update_settings with new helpdesk enrollment email param (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jcheng-duo committed Jul 16, 2021
1 parent 338c385 commit 7c5b115
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 21 deletions.
31 changes: 14 additions & 17 deletions duo_client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -1755,11 +1756,11 @@ def update_settings(self,
timezone - <str:IANA timezone>|None
telephony_warning_min - <int:credits>
caller_id - <str:phone number>
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 - <int:positive number of credits>
minimum_password_length - <int:length>|None
password_requires_upper_alpha - True|False|None
Expand All @@ -1769,6 +1770,7 @@ def update_settings(self,
helpdesk_bypass - "allow"|"limit"|"deny"|None
helpdesk_bypass_expiration - <int:minutes>|0
helpdesk_message - <str:message|None>
helpdesk_can_send_enroll_email - True|False|None
reactivation_url - <str:url>|None
reactivation_integration_key - <str:url>|None
security_checkup_enabled - True|False|None
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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")
Expand Down
76 changes: 76 additions & 0 deletions tests/admin/test_settings.py
Original file line number Diff line number Diff line change
@@ -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'],
})
4 changes: 2 additions & 2 deletions tests/admin/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import
import json
import collections
import urllib

from json import JSONEncoder
import duo_client
Expand All @@ -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


Expand Down

0 comments on commit 7c5b115

Please sign in to comment.