示例#1
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)
示例#2
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)
示例#3
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)
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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)
示例#8
0
 def test_push_with_invalid_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"] = "invalid"
     request.META["HTTP_X_GITHUB_EVENT"] = "push"
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 400)
     self.assertTrue(b"invalid" in response.content.lower())
     self.assertEqual(mock.call_count, 0)
示例#9
0
 def test_get_not_allowed(self, mock):
     request = self.FACTORY.get("/")
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 405)
     self.assertEqual(mock.call_count, 0)
示例#10
0
 def test_get_not_allowed(self, mock):
     request = self.FACTORY.get("/")
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 405)
     self.assertEqual(mock.call_count, 0)