-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d74b1ae
commit fdbf249
Showing
25 changed files
with
253 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Empty file.
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,9 @@ | ||
query TT | ||
select data ->> 'source', data->> 'auth_algo' from github_sha256; | ||
---- | ||
github sha256 | ||
|
||
query TT | ||
select data ->> 'source', data->> 'auth_algo' from github_sha1; | ||
---- | ||
github sha1 |
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,11 @@ | ||
query TT | ||
select data ->> 'source', data->> 'auth_algo' from github_sha256; | ||
---- | ||
github sha256 | ||
github sha256 | ||
|
||
query TT | ||
select data ->> 'source', data->> 'auth_algo' from github_sha1; | ||
---- | ||
github sha1 | ||
github sha1 |
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,13 @@ | ||
query TT | ||
select data ->> 'source', data->> 'auth_algo' from github_sha256; | ||
---- | ||
github sha256 | ||
github sha256 | ||
github sha256 | ||
|
||
query TT | ||
select data ->> 'source', data->> 'auth_algo' from github_sha1; | ||
---- | ||
github sha1 | ||
github sha1 | ||
github sha1 |
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,7 @@ | ||
|
||
statement ok | ||
DROP TABLE github_sha256; | ||
|
||
statement ok | ||
DROP TABLE github_sha1; | ||
|
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,88 @@ | ||
import argparse | ||
import requests | ||
import json | ||
import sys | ||
import hmac | ||
import hashlib | ||
|
||
message = { | ||
"event": "order.created", | ||
"source": "placeholder", | ||
"auth_algo": "placeholder", | ||
"data": { | ||
"order_id": 1234, | ||
"customer_name": "Alice", | ||
"amount": 99.99, | ||
"currency": "USD" | ||
}, | ||
"timestamp": 1639581841 | ||
} | ||
|
||
SERVER_URL = "http://127.0.0.1:8080/message/root/dev/public/" | ||
|
||
|
||
def generate_signature_hmac(secret, payload, auth_algo): | ||
secret_bytes = bytes(secret, 'utf-8') | ||
payload_bytes = bytes(payload, 'utf-8') | ||
signature = "" | ||
if auth_algo == "sha1": | ||
signature = "sha1=" + hmac.new(secret_bytes, payload_bytes, digestmod=hashlib.sha1).hexdigest() | ||
elif auth_algo == "sha256": | ||
signature = "sha256=" + hmac.new(secret_bytes, payload_bytes, digestmod=hashlib.sha256).hexdigest() | ||
else: | ||
print("Unsupported auth type") | ||
sys.exit(1) | ||
return signature | ||
|
||
|
||
def send_webhook(url, headers, payload_json): | ||
response = requests.post(url, headers=headers, data=payload_json) | ||
|
||
# Check response status and exit on failure | ||
if response.status_code == 200: | ||
print("Webhook sent successfully:", response) | ||
else: | ||
print(f"Webhook failed to send, Status Code: {response.status_code}, Response: {response.text}") | ||
sys.exit(1) # Exit the program with an error | ||
|
||
|
||
def send_github_sha1(secret): | ||
payload = message | ||
payload['source'] = "github" | ||
payload['auth_algo'] = "sha1" | ||
url = SERVER_URL + "github_sha1" | ||
|
||
payload_json = json.dumps(payload) | ||
signature = generate_signature_hmac(secret, payload_json, 'sha1') | ||
# Webhook message headers | ||
headers = { | ||
"Content-Type": "application/json", | ||
"X-Hub-Signature": signature # Custom signature header | ||
} | ||
send_webhook(url, headers, payload_json) | ||
|
||
|
||
def send_github_sha256(secret): | ||
payload = message | ||
payload['source'] = "github" | ||
payload['auth_algo'] = "sha256" | ||
url = SERVER_URL + "github_sha256" | ||
|
||
payload_json = json.dumps(payload) | ||
signature = generate_signature_hmac(secret, payload_json, 'sha256') | ||
# Webhook message headers | ||
headers = { | ||
"Content-Type": "application/json", | ||
"X-Hub-Signature-256": signature # Custom signature header | ||
} | ||
send_webhook(url, headers, payload_json) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Simulate sending Webhook messages") | ||
parser.add_argument("--secret", required=True, help="Secret key for generating signature") | ||
args = parser.parse_args() | ||
secret = args.secret | ||
# send data | ||
send_github_sha1(secret) | ||
send_github_sha256(secret) |
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 |
---|---|---|
@@ -1,4 +1,27 @@ | ||
# Simulation test for table with webhook source | ||
|
||
control substitution on | ||
|
||
statement ok | ||
SET RW_IMPLICIT_FLUSH TO true; | ||
|
||
statement ok | ||
CREATE SECRET test_secret WITH ( backend = 'meta') AS 'TEST_WEBHOOK'; | ||
|
||
include ../create_table.slt.part | ||
include ./create_table.slt.part | ||
|
||
# insert once | ||
system ok | ||
python3 e2e_test/webhook/sender.py --secret TEST_WEBHOOK | ||
|
||
sleep 3s | ||
|
||
include ./check_1.slt.part | ||
|
||
# insert again | ||
system ok | ||
python3 e2e_test/webhook/sender.py --secret TEST_WEBHOOK | ||
|
||
sleep 3s | ||
|
||
include ./check_2.slt.part |
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,19 @@ | ||
# Simulation test for table with webhook source after recovery | ||
|
||
control substitution on | ||
|
||
statement ok | ||
SET RW_IMPLICIT_FLUSH TO true; | ||
|
||
# insert once | ||
system ok | ||
python3 e2e_test/webhook/sender.py --secret TEST_WEBHOOK | ||
|
||
sleep 3s | ||
|
||
include ./check_3.slt.part | ||
|
||
include ./drop_table.slt.part | ||
|
||
statement ok | ||
DROP SECRET test_secret |
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
Oops, something went wrong.