forked from GithubBackups/healthchecks
Add logic to handle exceptions thrown by the fido2 library
This commit is contained in:
parent
c8d387aee4
commit
0b4251bdee
@ -80,3 +80,19 @@ class AddCredentialTestCase(BaseTestCase):
|
|||||||
|
|
||||||
r = self.client.post(self.url, payload)
|
r = self.client.post(self.url, payload)
|
||||||
self.assertEqual(r.status_code, 400)
|
self.assertEqual(r.status_code, 400)
|
||||||
|
|
||||||
|
@patch("hc.accounts.views._get_credential_data")
|
||||||
|
def test_it_handles_authentication_failure(self, mock_get_credential_data):
|
||||||
|
mock_get_credential_data.return_value = None
|
||||||
|
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
self.set_sudo_flag()
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"name": "My New Key",
|
||||||
|
"client_data_json": "e30=",
|
||||||
|
"attestation_object": "e30=",
|
||||||
|
}
|
||||||
|
|
||||||
|
r = self.client.post(self.url, payload, follow=True)
|
||||||
|
self.assertEqual(r.status_code, 400)
|
||||||
|
@ -590,11 +590,14 @@ def _get_credential_data(request, form):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
auth_data = FIDO2_SERVER.register_complete(
|
try:
|
||||||
request.session["state"],
|
auth_data = FIDO2_SERVER.register_complete(
|
||||||
ClientData(form.cleaned_data["client_data_json"]),
|
request.session["state"],
|
||||||
AttestationObject(form.cleaned_data["attestation_object"]),
|
ClientData(form.cleaned_data["client_data_json"]),
|
||||||
)
|
AttestationObject(form.cleaned_data["attestation_object"]),
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
return auth_data.credential_data
|
return auth_data.credential_data
|
||||||
|
|
||||||
@ -677,14 +680,17 @@ def _check_credential(request, form, credentials):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
FIDO2_SERVER.authenticate_complete(
|
try:
|
||||||
request.session["state"],
|
FIDO2_SERVER.authenticate_complete(
|
||||||
credentials,
|
request.session["state"],
|
||||||
form.cleaned_data["credential_id"],
|
credentials,
|
||||||
ClientData(form.cleaned_data["client_data_json"]),
|
form.cleaned_data["credential_id"],
|
||||||
AuthenticatorData(form.cleaned_data["authenticator_data"]),
|
ClientData(form.cleaned_data["client_data_json"]),
|
||||||
form.cleaned_data["signature"],
|
AuthenticatorData(form.cleaned_data["authenticator_data"]),
|
||||||
)
|
form.cleaned_data["signature"],
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user