Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete_user and delete_user_authenticator method #22

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add delete_user_authenticator method
stevenclouston committed Oct 8, 2024
commit da0bc528f857bc003130c9bf4a0e14d7cd4b9ea8
21 changes: 21 additions & 0 deletions authsignal/client.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions authsignal/client_tests.py
Original file line number Diff line number Diff line change
@@ -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",