From 512be5bcb1505472a97a0032232b95c3b6291dd3 Mon Sep 17 00:00:00 2001 From: Josh Cheng Date: Fri, 17 Nov 2023 13:41:26 -0500 Subject: [PATCH 1/3] feat: Add verification push methods to client --- duo_client/admin.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/duo_client/admin.py b/duo_client/admin.py index 884c6c3..c71087d 100644 --- a/duo_client/admin.py +++ b/duo_client/admin.py @@ -3245,6 +3245,19 @@ def sync_user(self, username, directory_key): directory_key=directory_key) return self.json_api_call('POST', path, params) + def send_verification_push(self, user_id, phone_id): + return self.json_api_call( + 'POST', + f'/admin/v1/users/{user_id}/send_verification_push', + {'phone_id': phone_id} + ) + + def get_verification_push_response(self, user_id, txid): + return self.json_api_call( + 'GET', + f'/admin/v1/users/{user_id}/verification_push_response', + {'txid': txid}, + ) def get_trust_monitor_events_iterator( self, mintime, From 38fb2b568ee63c6c8f843dc7455a9d30e31cd1fb Mon Sep 17 00:00:00 2001 From: Josh Cheng Date: Fri, 17 Nov 2023 14:34:08 -0500 Subject: [PATCH 2/3] Add tests --- tests/admin/test_verification_push.py | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/admin/test_verification_push.py diff --git a/tests/admin/test_verification_push.py b/tests/admin/test_verification_push.py new file mode 100644 index 0000000..96629f4 --- /dev/null +++ b/tests/admin/test_verification_push.py @@ -0,0 +1,30 @@ +import json +from .. import util +from .base import TestAdmin + + +class TestVerificationPush(TestAdmin): + def test_send_verification_push(self): + """ + Test sending a verification push to a user. + """ + response = self.client.send_verification_push('test_user_id', 'test_phone_id') + self.assertEqual(response['method'], 'POST') + self.assertEqual(response['uri'], + '/admin/v1/users/test_user_id/send_verification_push') + self.assertEqual( + json.loads(response['body']), + {'phone_id': 'test_phone_id', 'account_id': self.client.account_id}) + + def test_get_verification_push_response(self): + """ + Test getting the verification push response. + """ + response = self.client.get_verification_push_response('test_user_id', 'test_txid') + (uri, args) = response['uri'].split('?') + self.assertEqual(response['method'], 'GET') + self.assertEqual(uri, '/admin/v1/users/test_user_id/verification_push_response') + + self.assertEqual( + util.params_to_dict(args), + {'txid': ['test_txid'], 'account_id': [self.client.account_id]}) From 8770100b956c279e161801cc102f8b556709d206 Mon Sep 17 00:00:00 2001 From: Josh Cheng Date: Fri, 17 Nov 2023 16:46:05 -0500 Subject: [PATCH 3/3] Improve params --- duo_client/admin.py | 4 ++-- tests/admin/test_verification_push.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/duo_client/admin.py b/duo_client/admin.py index c71087d..03c058c 100644 --- a/duo_client/admin.py +++ b/duo_client/admin.py @@ -3252,11 +3252,11 @@ def send_verification_push(self, user_id, phone_id): {'phone_id': phone_id} ) - def get_verification_push_response(self, user_id, txid): + def get_verification_push_response(self, user_id, push_id): return self.json_api_call( 'GET', f'/admin/v1/users/{user_id}/verification_push_response', - {'txid': txid}, + {'push_id': push_id}, ) def get_trust_monitor_events_iterator( self, diff --git a/tests/admin/test_verification_push.py b/tests/admin/test_verification_push.py index 96629f4..151e9b1 100644 --- a/tests/admin/test_verification_push.py +++ b/tests/admin/test_verification_push.py @@ -20,11 +20,11 @@ def test_get_verification_push_response(self): """ Test getting the verification push response. """ - response = self.client.get_verification_push_response('test_user_id', 'test_txid') + response = self.client.get_verification_push_response('test_user_id', 'test_push_id') (uri, args) = response['uri'].split('?') self.assertEqual(response['method'], 'GET') self.assertEqual(uri, '/admin/v1/users/test_user_id/verification_push_response') self.assertEqual( util.params_to_dict(args), - {'txid': ['test_txid'], 'account_id': [self.client.account_id]}) + {'push_id': ['test_push_id'], 'account_id': [self.client.account_id]})