-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add schedule to CI, fix and improve tests after library refresh
- Loading branch information
1 parent
640198f
commit 1add32c
Showing
9 changed files
with
120 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from onfido.webhook_event_verifier import ( | ||
WebhookEventVerifier, OnfidoInvalidSignatureError | ||
) | ||
from onfido import ( | ||
WebhookEvent, WebhookEventPayload, WebhookEventPayloadObject, | ||
WebhookEventResourceType, WebhookEventType, WebhookEventObjectStatus, | ||
WebhookEventPayloadResource | ||
) | ||
|
||
import pytest | ||
|
||
classic_raw_event = ("{\"payload\":{\"resource_type\":\"check\",\"action\":\"check.completed\"," | ||
"\"object\":{\"id\":\"f2302f45-227d-413d-ad61-09ec077a086a\",\"status\":\"complete\"," | ||
"\"completed_at_iso8601\":\"2024-04-04T09:21:21Z\"," | ||
"\"href\":\"https://api.onfido.com/v3.6/checks/f2302f45-227d-413d-ad61-09ec077a086a\"}}}") | ||
|
||
studio_raw_event = ("{\"payload\":{\"resource_type\":\"workflow_task\",\"action\":\"workflow_task.started\"," | ||
"\"object\":{\"id\":\"profile_1eb92\",\"task_spec_id\":\"profile_1eb92\"," | ||
"\"task_def_id\":\"profile_data\",\"workflow_run_id\":\"bc77c6e5-753a-4580-96a6-aaed3e5a8d19\"" | ||
",\"status\":\"started\",\"started_at_iso8601\":\"2024-07-10T12:49:09Z\"," | ||
"\"href\":\"https://api.eu.onfido.com/v3.6/workflow_runs/" | ||
"bc77c6e5-753a-4580-96a6-aaed3e5a8d19/tasks/profile_1eb92\"}," | ||
"\"resource\":{\"created_at\":\"2024-07-10T12:49:09Z\",\"id\":""\"profile_1eb92\"," | ||
"\"workflow_run_id\":\"bc77c6e5-753a-4580-96a6-aaed3e5a8d19\",\"updated_at\":\"2024-07-10T12:49:09Z\"" | ||
",\"input\":{},\"task_def_version\":null,\"task_def_id\":\"profile_data\",\"output\":null}}}") | ||
|
||
classic_expected_event = WebhookEvent( | ||
payload=WebhookEventPayload( | ||
action=WebhookEventType.CHECK_DOT_COMPLETED, | ||
resource_type=WebhookEventResourceType.CHECK, | ||
object=WebhookEventPayloadObject( | ||
id='f2302f45-227d-413d-ad61-09ec077a086a', | ||
href='https://api.onfido.com/v3.6/checks/f2302f45-227d-413d-ad61-09ec077a086a', | ||
status=WebhookEventObjectStatus.COMPLETE, | ||
completed_at_iso8601='2024-04-04T09:21:21Z' | ||
) | ||
) | ||
) | ||
|
||
studio_expected_event = WebhookEvent( | ||
payload=WebhookEventPayload( | ||
action=WebhookEventType.WORKFLOW_TASK_DOT_STARTED, | ||
resource_type=WebhookEventResourceType.WORKFLOW_TASK, | ||
object=WebhookEventPayloadObject( | ||
id='profile_1eb92', | ||
href='https://api.eu.onfido.com/v3.6/workflow_runs/bc77c6e5-753a-4580-96a6-aaed3e5a8d19/tasks/profile_1eb92', | ||
status=WebhookEventObjectStatus.STARTED, | ||
started_at_iso8601='2024-07-10T12:49:09Z', | ||
task_def_id='profile_data', | ||
task_spec_id='profile_1eb92', | ||
workflow_run_id='bc77c6e5-753a-4580-96a6-aaed3e5a8d19' | ||
), | ||
resource=WebhookEventPayloadResource( | ||
created_at='2024-07-10T12:49:09Z', | ||
id='profile_1eb92', | ||
input={}, | ||
output=None, | ||
task_def_id='profile_data', | ||
task_def_version=None, | ||
updated_at='2024-07-10T12:49:09Z', | ||
workflow_run_id='bc77c6e5-753a-4580-96a6-aaed3e5a8d19' | ||
) | ||
) | ||
) | ||
|
||
|
||
classic_verifier = WebhookEventVerifier("wU99mE6jJ7nXOLFwZ0tJymM1lpI15pZh") | ||
studio_verifier = WebhookEventVerifier("YKOC6mkBxi6yK2zlUIrLMvsJMFEZObP5") | ||
|
||
|
||
def test_classic_webhook_event_verification(): | ||
signature = "77ebc3e418f26be6eebb47f7ebe551321de26734fc273961e075fc9ab163d9c7" | ||
|
||
event = classic_verifier.read_payload(classic_raw_event, signature) | ||
assert event == classic_expected_event | ||
|
||
|
||
def test_classic_webhook_event_verification_invalid_signature(): | ||
signature = "77ebc3e418f26be6eebb47f7ebe551321de26734fc273961e075fc9ab163d9c8" | ||
|
||
with pytest.raises(OnfidoInvalidSignatureError): | ||
classic_verifier.read_payload(classic_raw_event, signature) | ||
|
||
|
||
def test_studio_webhook_event_verification(): | ||
signature = "c95a5b785484f6fa1bc25f381b5595d66bf85cb442eefb06aa007802ee6a4dfa" | ||
|
||
event = studio_verifier.read_payload(studio_raw_event, signature) | ||
event.payload.object.additional_properties = {} # Suppress any additional property in object | ||
assert event == studio_expected_event | ||
|
||
|
||
def test_studio_webhook_event_verification_invalid_signature(): | ||
signature = "c95a5b785484f6fa1bc25f381b5595d66bf85cb442eefb06aa007802ee6a4dfb" | ||
|
||
with pytest.raises(OnfidoInvalidSignatureError): | ||
studio_verifier.read_payload(studio_raw_event, signature) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters