diff --git a/src/nrc/api/tests/test_validation.py b/src/nrc/api/tests/test_validation.py index 863aea65..7b9664b8 100644 --- a/src/nrc/api/tests/test_validation.py +++ b/src/nrc/api/tests/test_validation.py @@ -196,7 +196,7 @@ def test_subscriptions_invalid_sink(self): # Let callback url return 201 instead of required 204 when # sending a notification m.register_uri( - "POST", "https://endpoint.example.com/webhook", status_code=201 + "POST", "https://endpoint.example.com/webhook", status_code=302 ) response = self.client.post(subscription_create_url, data) @@ -207,6 +207,39 @@ def test_subscriptions_invalid_sink(self): error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "invalid-callback-url") + @override_settings( + LINK_FETCHER="vng_api_common.mocks.link_fetcher_404", + ZDS_CLIENT_CLASS="vng_api_common.mocks.MockClient", + ) + def test_subscriptions_callback_url_accept_20x_status_codes(self): + DomainFactory.create(name="nl.vng.zaken") + + subscription_create_url = get_operation_url("subscription_create") + + data = { + "protocol": ProtocolChoices.HTTP, + "source": "urn:nld:oin:00000001234567890000:systeem:Zaaksysteem", + "sink": "https://endpoint.example.com/webhook", + "domain": "nl.vng.zaken", + } + + accepted_status_codes = range(200, 210) + for status_code in accepted_status_codes: + with self.subTest(callback_status_code=status_code): + with requests_mock.mock() as m: + # Let callback url return a 20x status code + m.register_uri( + "POST", + "https://endpoint.example.com/webhook", + status_code=status_code, + ) + response = self.client.post(subscription_create_url, data) + + self.assertEqual( + response.status_code, status.HTTP_201_CREATED, response.data + ) + Subscription.objects.get().delete() + @override_settings( LINK_FETCHER="vng_api_common.mocks.link_fetcher_404", ZDS_CLIENT_CLASS="vng_api_common.mocks.MockClient", diff --git a/src/nrc/api/validators.py b/src/nrc/api/validators.py index 9aef2a53..41ab993f 100644 --- a/src/nrc/api/validators.py +++ b/src/nrc/api/validators.py @@ -61,7 +61,7 @@ def __call__(self, attrs): except requests.RequestException: raise serializers.ValidationError(self.message, code=self.code) - if response.status_code != 204: + if not (200 <= response.status_code <= 209): raise serializers.ValidationError(self.message, code=self.code)