Skip to content

Commit e5b1682

Browse files
committed
add checks for silent auth workflow parameters
1 parent 36ddbe4 commit e5b1682

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 3.11.1
2+
- Add checks for silent auth workflow optional parameters `redirect_url` and `sandbox`
3+
14
# 3.11.0
25
- Add method to check JWT signatures of Voice API webhooks: `vonage.Voice.verify_signature`
36

src/vonage/verify2.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def check_valid_workflow(cls, v):
8484
Verify2._check_app_hash(workflow)
8585
if workflow['channel'] == 'whatsapp' and 'from' in workflow:
8686
Verify2._check_whatsapp_sender(workflow)
87+
if workflow['channel'] == 'silent_auth':
88+
Verify2._check_silent_auth_workflow(workflow)
8789

8890
def _check_valid_channel(workflow):
8991
if 'channel' not in workflow or workflow['channel'] not in Verify2.valid_channels:
@@ -113,4 +115,12 @@ def _check_app_hash(workflow):
113115

114116
def _check_whatsapp_sender(workflow):
115117
if not re.search(r'^[1-9]\d{6,14}$', workflow['from']):
116-
raise Verify2Error(f'You must specify a valid "from" value if included.')
118+
raise Verify2Error('You must specify a valid "from" value if included.')
119+
120+
def _check_silent_auth_workflow(workflow):
121+
if 'redirect_url' in workflow:
122+
if type(workflow['redirect_url']) != str:
123+
raise Verify2Error('"redirect_url" must be a string if specified.')
124+
if 'sandbox' in workflow:
125+
if type(workflow['sandbox']) != bool:
126+
raise Verify2Error('"sandbox" must be a boolean if specified.')

tests/test_verify2.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,17 @@ def test_new_request_silent_auth():
396396
status_code=202,
397397
)
398398

399-
params = {'brand': 'ACME, Inc', 'workflow': [{'channel': 'silent_auth', 'to': '447700900000'}]}
399+
params = {
400+
'brand': 'ACME, Inc',
401+
'workflow': [
402+
{
403+
'channel': 'silent_auth',
404+
'to': '447000000000',
405+
'redirect_url': 'https://acme-app.com/sa/redirect',
406+
'sandbox': False,
407+
}
408+
],
409+
}
400410
verify_request = verify2.new_request(params)
401411

402412
assert verify_request['request_id'] == 'b3a2f4bd-7bda-4e5e-978a-81514702d2ce'
@@ -406,6 +416,38 @@ def test_new_request_silent_auth():
406416
)
407417

408418

419+
def test_silent_auth_redirect_url_error():
420+
params = {
421+
'brand': 'ACME, Inc',
422+
'workflow': [
423+
{
424+
'channel': 'silent_auth',
425+
'to': '447000000000',
426+
'redirect_url': ['https://acme-app.com/sa/redirect'],
427+
}
428+
],
429+
}
430+
with raises(Verify2Error) as err:
431+
verify2.new_request(params)
432+
assert str(err.value) == '"redirect_url" must be a string if specified.'
433+
434+
435+
def test_silent_auth_sandbox_error():
436+
params = {
437+
'brand': 'ACME, Inc',
438+
'workflow': [
439+
{
440+
'channel': 'silent_auth',
441+
'to': '447000000000',
442+
'sandbox': 'true',
443+
}
444+
],
445+
}
446+
with raises(Verify2Error) as err:
447+
verify2.new_request(params)
448+
assert str(err.value) == '"sandbox" must be a boolean if specified.'
449+
450+
409451
@responses.activate
410452
def test_new_request_error_conflict():
411453
stub(

0 commit comments

Comments
 (0)