Skip to content

Commit

Permalink
Fixes kiwitcms#1612 - Add test for tcms.utils.github
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Nov 13, 2020
1 parent 54fcd23 commit 978c016
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tcms/utils/tests/test_github.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Copyright (c) 2019 Alexander Todorov <[email protected]>

import hmac
import hashlib

from http import HTTPStatus

from django import test
Expand All @@ -8,6 +11,12 @@
from tcms.utils import github


class CalculateSignatureTestCase(test.TestCase):
def test_return_format(self):
self.assertEqual(github.calculate_signature(b'secret', b'content'),
'sha1=0bd98d1a7514a85bbb8377bb8d750b6e01494056')


class VerifySignatureTestCase(test.TestCase):
def setUp(self):
self.factory = test.RequestFactory()
Expand All @@ -27,3 +36,12 @@ def test_invalid_signature_header(self):

self.assertIsInstance(result, HttpResponseForbidden)
self.assertEqual(HTTPStatus.FORBIDDEN, result.status_code)

def test_valid_signature_header(self):
request = self.factory.post(self.url)
request.META['HTTP_X_HUB_SIGNATURE'] = (
github.calculate_signature(b'secret', request.body)
)
result = github.verify_signature(request, b'secret')
self.assertIsInstance(result, bool)
self.assertTrue(result)

0 comments on commit 978c016

Please sign in to comment.