fix webhook code we hope
This commit is contained in:
1 parent
a8ce535985
commit
4320b4cba9
4 files changed
+126
-126
No files matched your search
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Simple test script to verify Square webhook signature verification works correctly.
|
||||
|
||||
This uses the same test data from Square's documentation to ensure our implementation
|
||||
matches their expected behavior.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, "src")
|
||||
|
||||
from square.utilities.webhooks_helper import is_valid_webhook_event_signature
|
||||
|
||||
# Test data from Square's documentation
|
||||
TEST_BODY = '{"hello":"world"}'
|
||||
TEST_SIGNATURE = "2kRE5qRU2tR+tBGlDwMEw2avJ7QM4ikPYD/PJ3bd9Og="
|
||||
TEST_SIGNATURE_KEY = "asdf1234"
|
||||
TEST_NOTIFICATION_URL = "https://example.com/webhook"
|
||||
|
||||
|
||||
def test_signature_validation():
|
||||
"""Test that signature validation works with Square SDK"""
|
||||
|
||||
print("Testing Square webhook signature validation...")
|
||||
print(f"Body: {TEST_BODY}")
|
||||
print(f"Signature: {TEST_SIGNATURE}")
|
||||
print(f"Key: {TEST_SIGNATURE_KEY}")
|
||||
print(f"URL: {TEST_NOTIFICATION_URL}")
|
||||
print()
|
||||
|
||||
# This should return True with Square's test data
|
||||
is_valid = is_valid_webhook_event_signature(
|
||||
TEST_BODY, TEST_SIGNATURE, TEST_SIGNATURE_KEY, TEST_NOTIFICATION_URL
|
||||
)
|
||||
|
||||
if is_valid:
|
||||
print("✅ SUCCESS: Signature validation passed!")
|
||||
print("The webhook implementation is using Square SDK correctly.")
|
||||
return True
|
||||
else:
|
||||
print("❌ FAILURE: Signature validation failed!")
|
||||
print("Something is wrong with the signature verification.")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_signature_validation()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in new issue
Block a user