Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions smoothcode_auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ def is_dashboard_request(self, shop: str):
def is_webhook_request(self, webhook_data: dict):
webhook_id = webhook_data.get('id')
return generate_hmac(self.client_secret, str(webhook_id)) == self.hmac

def is_gdpr_webhook_request(self, webhook_data: dict):
shop_id = webhook_data.get('shop_id')
return generate_hmac(self.client_secret, str(shop_id)) == self.hmac
10 changes: 10 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ def test_is_webhook_request_with_incorrect_data(self):
client_secret = 'client_secret'
request_hmac = 'request_hmac'
assert not SmoothCodeAuth(request_hmac, client_secret).is_webhook_request({'id': 'webhook'})

def test_is_gdpr_webhook_request_with_correct_data(self):
client_secret = 'client_secret'
request_hmac = '3999c5c10e23bee670e28ad67f446ac5e7b9c47ca1ee39c4bdf0c7bf056f8d71'
assert SmoothCodeAuth(request_hmac, client_secret).is_gdpr_webhook_request({'shop_id': 1235643534})

def test_is_gdpr_webhook_request_with_incorrect_data(self):
client_secret = 'client_secret'
request_hmac = 'request_hmac'
assert not SmoothCodeAuth(request_hmac, client_secret).is_gdpr_webhook_request({'shop_id': 'webhook'})