From b8a8d172f652f63c5094d0598e29fb6e0dc965d1 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Mon, 17 Oct 2016 10:47:48 +0200 Subject: [PATCH] [Backport] Fixing project validation on hooks app --- taiga/hooks/api.py | 2 +- tests/integration/test_hooks_github.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/taiga/hooks/api.py b/taiga/hooks/api.py index eef06cf8..baf94e9d 100644 --- a/taiga/hooks/api.py +++ b/taiga/hooks/api.py @@ -44,7 +44,7 @@ class BaseWebhookApiViewSet(GenericViewSet): try: project = Project.objects.get(id=project_id) return project - except Project.DoesNotExist: + except (ValueError, Project.DoesNotExist): return None def _get_payload(self, request): diff --git a/tests/integration/test_hooks_github.py b/tests/integration/test_hooks_github.py index 1bcbcdbe..cf3b8bad 100644 --- a/tests/integration/test_hooks_github.py +++ b/tests/integration/test_hooks_github.py @@ -43,6 +43,19 @@ from .. import factories as f pytestmark = pytest.mark.django_db +def test_bad_project(client): + project = f.ProjectFactory() + url = reverse("github-hook-list") + url = "%s?project=%s-extra-text-added" % (url, project.id) + data = {"test:": "data"} + response = client.post(url, json.dumps(data), + HTTP_X_HUB_SIGNATURE="sha1=3c8e83fdaa266f81c036ea0b71e98eb5e054581a", + content_type="application/json") + response_content = response.data + assert response.status_code == 400 + assert "The project doesn't exist" in response_content["_error_message"] + + def test_bad_signature(client): project = f.ProjectFactory() url = reverse("github-hook-list")