-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh webhook signature unit test (#82)
- Loading branch information
Showing
2 changed files
with
32 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
# Create your tests here. | ||
import json | ||
from django.test import TestCase | ||
|
||
from core.gh_webhook_handling import verify_secret, generate_signature | ||
|
||
|
||
class GHWebhookTestCase(TestCase): | ||
def setUp(self): | ||
self.secret = "UwU" | ||
self.payload = { | ||
"sender": {"login": "test_user"}, | ||
"action": "opened", | ||
"pull_request": {"merged": False}, | ||
"issue": {"state_reason": "completed"}, | ||
} | ||
self.payload_bytes = json.dumps(self.payload).encode("utf-8") | ||
self.signature = generate_signature(self.secret, self.payload_bytes) | ||
|
||
def test_valid_signature(self): | ||
self.assertTrue(verify_secret(self.secret, self.payload_bytes, self.signature)) | ||
|
||
def test_invalid_signature(self): | ||
wrong_signature = "silly:3" | ||
self.assertFalse( | ||
verify_secret(self.secret, self.payload_bytes, wrong_signature) | ||
) |