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

Omit action_code from validate_challenge response #27

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
Next Next commit
Omit action_code from validate_challenge response
stevenclouston committed Oct 29, 2024
commit ce26cb6df5e47ab158eefa5e10c8c0ccb3ecc4b8
12 changes: 12 additions & 0 deletions authsignal/client.py
Original file line number Diff line number Diff line change
@@ -50,6 +50,18 @@ def _remove_none_values(d: Dict[str, Any]) -> Dict[str, Any]:
"""Remove keys with None values from a dictionary."""
return {k: v for k, v in d.items() if v is not None}

def send(self, request, **kwargs):
response = super().send(request, **kwargs)
if response.headers.get('Content-Type') == 'application/json':
try:
data = response.json()
if isinstance(data, dict) and 'actionCode' in data:
del data['actionCode']
response._content = json.dumps(data).encode('utf-8')
except json.JSONDecodeError:
pass
return response

class Client(object):

def __init__(
13 changes: 7 additions & 6 deletions authsignal/client_tests.py
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ def setUp(self):
"tenantId": "555159e4-adc3-454b-82b1-b55a2783f712",
"publishableKey": "2fff14a6600b7a58170793109c78b876",
"userId": "legitimate_user_id",
"actionCode": "alwaysChallenge",
"action": "alwaysChallenge",
"idempotencyKey": "a682af7d-c929-4c29-9c2a-71e69ab5c603"
}
}
@@ -137,7 +137,7 @@ def test_it_returns_success_if_user_id_is_correct(self):
'state': 'CHALLENGE_SUCCEEDED',
'stateUpdatedAt': '2024-07-11T22:03:39.037Z',
'userId': 'legitimate_user_id',
'actionCode': 'signin',
'action': 'signin',
'idempotencyKey': 'f2a0275e-bdbb-464a-8398-13c60c98097c'
},
status=200
@@ -167,7 +167,7 @@ def test_delete_authenticator(self):
self.assertEqual(responses.calls[0].response.status_code, 200)

@responses.activate
def test_it_returns_success_false_if_user_id_is_incorrect(self):
def test_validate_challenge_returns_success_false_if_user_id_is_incorrect(self):
responses.add(responses.POST, f"{base_url}/validate",
json={'isValid': False, 'error': 'User is invalid.'},
status=400
@@ -179,7 +179,7 @@ def test_it_returns_success_false_if_user_id_is_incorrect(self):
self.assertEqual(response.get("error"), "User is invalid.")

@responses.activate
def test_it_returns_isValid_false_if_action_is_incorrect(self):
def test_validate_challenge_returns_isValid_false_if_action_is_incorrect(self):
responses.add(responses.POST, f"{base_url}/validate",
json={
'isValid': False,
@@ -194,14 +194,15 @@ def test_it_returns_isValid_false_if_action_is_incorrect(self):
self.assertFalse(response["is_valid"])

@responses.activate
def test_it_returns_success_true_if_no_user_id_is_provided(self):
def test_validate_challenge_returns_success_true_if_no_user_id_is_provided(self):
responses.add(responses.POST, f"{base_url}/validate",
json={
'isValid': True,
'state': 'CHALLENGE_SUCCEEDED',
'stateUpdatedAt': '2024-07-11T22:39:23.613Z',
'userId': 'legitimate_user_id',
'actionCode': 'signin',
'action': 'signin',
'actionCode': 'signin',
'idempotencyKey': '6d09db21-1aa9-4b7f-826f-dbc6a0af79eb',
'verificationMethod': 'EMAIL_MAGIC_LINK'
},