Skip to content

Commit

Permalink
Add delete_user_authenticator method
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenclouston committed Oct 8, 2024
1 parent 5a3b8de commit da0bc52
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions authsignal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ def delete_user(self, user_id):
return humps.decamelize(response.json())
except requests.exceptions.RequestException as e:
raise ApiException(str(e), path) from e

def delete_user_authenticator(self, user_id: str, user_authenticator_id: str) -> Dict[str, Any]:
_assert_non_empty_unicode(user_id, 'user_id')
_assert_non_empty_unicode(user_authenticator_id, 'user_authenticator_id')

user_id = urllib.parse.quote(user_id)
user_authenticator_id = urllib.parse.quote(user_authenticator_id)
path = f'{self.url}/v1/users/{user_id}/authenticators/{user_authenticator_id}'
headers = self._default_headers()

try:
response = self.session.delete(
path,
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
headers=headers,
timeout=self.timeout
)
response.raise_for_status()
return humps.decamelize(response.json())
except requests.exceptions.RequestException as e:
raise ApiException(str(e), path) from e

def enroll_verified_authenticator(self, user_id, authenticator_payload, path=None):
"""Enrols an authenticator like a phone number for SMS on behalf of the user
Expand Down
17 changes: 17 additions & 0 deletions authsignal/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ def test_it_returns_success_if_user_id_is_correct(self):
self.assertEqual(response["state"], "CHALLENGE_SUCCEEDED")
self.assertTrue(response["is_valid"])


@responses.activate
def test_delete_user_authenticator(self):
self.authsignal_client = client.Client(api_key='test_api_key')
user_id = 'test_user'
user_authenticator_id = 'test_authenticator'
expected_url = f'{self.authsignal_client.url}/v1/users/{user_id}/authenticators/{user_authenticator_id}'

responses.add(responses.DELETE, expected_url, json={"success": True}, status=200)

response = self.authsignal_client.delete_user_authenticator(user_id, user_authenticator_id)

self.assertEqual(response["success"], True)
self.assertEqual(len(responses.calls), 1)
self.assertEqual(responses.calls[0].request.url, expected_url)
self.assertEqual(responses.calls[0].response.status_code, 200)

@responses.activate
def test_it_returns_success_false_if_user_id_is_incorrect(self):
responses.add(responses.POST, f"{base_challenge_url}/validate",
Expand Down

0 comments on commit da0bc52

Please sign in to comment.