Skip to content

Commit

Permalink
Omit action_code from validate_challenge response
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenclouston committed Oct 29, 2024
1 parent 6f3380f commit ce26cb6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 12 additions & 0 deletions authsignal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
13 changes: 7 additions & 6 deletions authsignal/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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'
},
Expand Down

0 comments on commit ce26cb6

Please sign in to comment.