Skip to content

Commit 8710516

Browse files
committed
feat: rename Webhook class to WebhookValidation
1 parent deac0a0 commit 8710516

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

.changeset/rude-kids-rhyme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"fingerprint-pro-server-api-python-sdk": major
3+
---
4+
5+
Rename `Webhook` class to `WebhookValidation`.
6+
Right now, `Webhook` class points to the actual data model.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ This SDK provides utility method for verifying the HMAC signature of the incomin
208208
```python
209209
import os
210210
from flask import Flask, request, jsonify
211-
from fingerprint_pro_server_api_sdk import Webhook
211+
from fingerprint_pro_server_api_sdk import WebhookValidation
212212

213213
app = Flask(__name__)
214214

@@ -229,7 +229,7 @@ def webhook_handler():
229229
data = request.get_data()
230230

231231
# Validate the webhook signature
232-
is_valid = Webhook.is_valid_webhook_signature(header, data, secret)
232+
is_valid = WebhookValidation.is_valid_webhook_signature(header, data, secret)
233233
if not is_valid:
234234
return jsonify({"message": "Webhook signature is invalid."}), 403
235235

fingerprint_pro_server_api_sdk/webhook.py renamed to fingerprint_pro_server_api_sdk/webhook_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import hashlib
33

44

5-
class Webhook:
5+
class WebhookValidation:
66
"""Manages work with webhooks."""
77
@staticmethod
88
def is_valid_hmac_signature(signature: str, data: bytes, secret: str) -> bool:
@@ -23,7 +23,7 @@ def is_valid_webhook_signature(header: str, data: bytes, secret: str) -> bool:
2323
parts = signature.split('=')
2424
if len(parts) == 2:
2525
version, hash_value = parts
26-
if version == "v1" and Webhook.is_valid_hmac_signature(hash_value, data, secret):
26+
if version == "v1" and WebhookValidation.is_valid_hmac_signature(hash_value, data, secret):
2727
return True
2828

2929
return False

template/README.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ This SDK provides utility method for verifying the HMAC signature of the incomin
214214
```python
215215
import os
216216
from flask import Flask, request, jsonify
217-
from fingerprint_pro_server_api_sdk import Webhook
217+
from fingerprint_pro_server_api_sdk import WebhookValidation
218218

219219
app = Flask(__name__)
220220

@@ -235,7 +235,7 @@ def webhook_handler():
235235
data = request.get_data()
236236

237237
# Validate the webhook signature
238-
is_valid = Webhook.is_valid_webhook_signature(header, data, secret)
238+
is_valid = WebhookValidation.is_valid_webhook_signature(header, data, secret)
239239
if not is_valid:
240240
return jsonify({"message": "Webhook signature is invalid."}), 403
241241

test/test_webhook_validation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from fingerprint_pro_server_api_sdk import Webhook
3+
from fingerprint_pro_server_api_sdk import WebhookValidation
44

55

66
class TestWebhookValidation(unittest.TestCase):
@@ -10,31 +10,31 @@ class TestWebhookValidation(unittest.TestCase):
1010
data = b"data"
1111

1212
def test_valid_header(self):
13-
result = Webhook.is_valid_webhook_signature(self.valid_header, self.data, self.secret)
13+
result = WebhookValidation.is_valid_webhook_signature(self.valid_header, self.data, self.secret)
1414
self.assertTrue(result)
1515

1616
def test_invalid_header(self):
17-
result = Webhook.is_valid_webhook_signature("v2=invalid", self.data, self.secret)
17+
result = WebhookValidation.is_valid_webhook_signature("v2=invalid", self.data, self.secret)
1818
self.assertFalse(result)
1919

2020
def test_header_without_version(self):
21-
result = Webhook.is_valid_webhook_signature("invalid", self.data, self.secret)
21+
result = WebhookValidation.is_valid_webhook_signature("invalid", self.data, self.secret)
2222
self.assertFalse(result)
2323

2424
def test_header_with_unsupported_version(self):
25-
result = Webhook.is_valid_webhook_signature(self.valid_header_v2, self.data, self.secret)
25+
result = WebhookValidation.is_valid_webhook_signature(self.valid_header_v2, self.data, self.secret)
2626
self.assertFalse(result)
2727

2828
def test_empty_header(self):
29-
result = Webhook.is_valid_webhook_signature("", self.data, self.secret)
29+
result = WebhookValidation.is_valid_webhook_signature("", self.data, self.secret)
3030
self.assertFalse(result)
3131

3232
def test_empty_secret(self):
33-
result = Webhook.is_valid_webhook_signature("invalid", self.data, "")
33+
result = WebhookValidation.is_valid_webhook_signature("invalid", self.data, "")
3434
self.assertFalse(result)
3535

3636
def test_empty_data(self):
37-
result = Webhook.is_valid_webhook_signature(self.valid_header, b"", self.secret)
37+
result = WebhookValidation.is_valid_webhook_signature(self.valid_header, b"", self.secret)
3838
self.assertFalse(result)
3939

4040

webhook_signature_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from fingerprint_pro_server_api_sdk import Webhook
1+
from fingerprint_pro_server_api_sdk import WebhookValidation
22

33
header = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db"
44
secret = "secret"
55
data = b"data"
66

7-
is_valid = Webhook.is_valid_webhook_signature(header, data, secret)
7+
is_valid = WebhookValidation.is_valid_webhook_signature(header, data, secret)
88

99
print("Webhook signature is correct!" if is_valid else "Webhook signature is incorrect!")

0 commit comments

Comments
 (0)