def test_push_with_valid_signature(self, mock): data = b'{"ref": "refs/heads/master"}' request = self.FACTORY.post("/", data=data, content_type="application/json") request.META["HTTP_X_HUB_SIGNATURE"] = compute_signature(data, self.KEY) request.META["HTTP_X_GITHUB_EVENT"] = "push" response = webhook_handler(request) self.assertEqual(response.status_code, 200) self.assertEqual(mock.call_count, 1)
def test_not_modified_when_ref_not_master(self, mock): data = b'{"ref": "refs/heads/develop"}' request = self.FACTORY.post("/", data=data, content_type="application/json") request.META["HTTP_X_HUB_SIGNATURE"] = compute_signature(data, self.KEY) request.META["HTTP_X_GITHUB_EVENT"] = "push" response = webhook_handler(request) self.assertContains(response, "Event ignored") self.assertEqual(mock.call_count, 0)
def test_not_modified_when_ref_not_master(self, mock): data = b'{"ref": "refs/heads/develop"}' request = self.FACTORY.post('/', data=data, content_type='application/json') request.META['HTTP_X_HUB_SIGNATURE'] = compute_signature(data, self.KEY) request.META['HTTP_X_GITHUB_EVENT'] = 'push' response = webhook_handler(request) self.assertContains(response, 'Event ignored') self.assertEqual(mock.call_count, 0)
def test_push_with_valid_signature(self, mock): data = b'{"ref": "refs/heads/master"}' request = self.FACTORY.post('/', data=data, content_type='application/json') request.META['HTTP_X_HUB_SIGNATURE'] = compute_signature(data, self.KEY) request.META['HTTP_X_GITHUB_EVENT'] = 'push' response = webhook_handler(request) self.assertEqual(response.status_code, 200) self.assertEqual(mock.call_count, 1)
def test_push_with_invalid_json(self, mock): data = b'<xml-is-not-json/>' request = self.FACTORY.post("/", data=data, content_type="application/json") request.META["HTTP_X_HUB_SIGNATURE"] = compute_signature(data, self.KEY) request.META["HTTP_X_GITHUB_EVENT"] = "push" response = webhook_handler(request) self.assertEqual(response.status_code, 400) self.assertTrue(b"malformed" in response.content.lower()) self.assertEqual(mock.call_count, 0)
def test_push_with_invalid_json(self, mock): data = b'<xml-is-not-json/>' request = self.FACTORY.post('/', data=data, content_type='application/json') request.META['HTTP_X_HUB_SIGNATURE'] = compute_signature(data, self.KEY) request.META['HTTP_X_GITHUB_EVENT'] = 'push' response = webhook_handler(request) self.assertEqual(response.status_code, 400) self.assertTrue(b'malformed' in response.content.lower()) self.assertEqual(mock.call_count, 0)
def test_not_modified_when_event_not_push(self, mock): data = b'{"ref": "refs/heads/master"}' request = self.FACTORY.post("/", data=data, content_type="application/json") request.META["HTTP_X_HUB_SIGNATURE"] = compute_signature( data, self.KEY) request.META["HTTP_X_GITHUB_EVENT"] = "ping" response = webhook_handler(request) self.assertContains(response, "Event ignored") self.assertEqual(mock.call_count, 0)
def test_compute_signature_bytes(self): self.assertEqual(compute_signature(b"foo", key=b"secret"), "sha1=9baed91be7f58b57c824b60da7cb262b2ecafbd2")
def test_compute_signature_bytes(self): self.assertEqual( compute_signature(b"foo", key=b"secret"), "sha1=9baed91be7f58b57c824b60da7cb262b2ecafbd2" )
def test_compute_signature_bytes(self): self.assertEqual( compute_signature(b'foo', key=b'secret'), 'sha1=9baed91be7f58b57c824b60da7cb262b2ecafbd2' )