[Backport] Fixing gitlab requests with empty payloads

remotes/origin/issue/4795/notification_even_they_are_disabled
Alejandro Alonso 2016-02-10 11:17:38 +01:00 committed by David Barragán Merino
parent 1cf3aa22cd
commit b48d514271
2 changed files with 18 additions and 1 deletions

View File

@ -79,4 +79,4 @@ class GitLabViewSet(BaseWebhookApiViewSet):
def _get_event_name(self, request): def _get_event_name(self, request):
payload = json.loads(request.body.decode("utf-8")) payload = json.loads(request.body.decode("utf-8"))
return payload.get('object_kind', 'push') return payload.get('object_kind', 'push') if payload is not None else 'empty'

View File

@ -59,6 +59,23 @@ def test_ok_signature(client):
assert response.status_code == 204 assert response.status_code == 204
def test_ok_empty_payload(client):
project = f.ProjectFactory()
f.ProjectModulesConfigFactory(project=project, config={
"gitlab": {
"secret": "tpnIwJDz4e",
"valid_origin_ips": ["111.111.111.111"],
}
})
url = reverse("gitlab-hook-list")
url = "{}?project={}&key={}".format(url, project.id, "tpnIwJDz4e")
data = {}
response = client.post(url,"null", content_type="application/json", REMOTE_ADDR="111.111.111.111")
assert response.status_code == 204
def test_ok_signature_ip_in_network(client): def test_ok_signature_ip_in_network(client):
project = f.ProjectFactory() project = f.ProjectFactory()
f.ProjectModulesConfigFactory(project=project, config={ f.ProjectModulesConfigFactory(project=project, config={