Skip to content

Commit

Permalink
Merge pull request #181 from open-zaak/bug/zio-invalid-url
Browse files Browse the repository at this point in the history
Fix crash on invalid URLs for ZIO
  • Loading branch information
joeribekker committed Nov 7, 2019
2 parents c1c5d65 + 937cbfe commit 3e021a4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ django-cors-middleware==1.3.1
django-extra-fields==1.2.4
django-filter==2.0
django-ipware==2.1.0 # via django-axes
django-loose-fk==0.5.5
django-loose-fk==0.5.6
django-markup==1.3
django-ordered-model==2.1.0 # via django-admin-index
django-privates==1.0.1.post0
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ django-cors-middleware==1.3.1
django-extra-fields==1.2.4
django-filter==2.0.0
django-ipware==2.1.0
django-loose-fk==0.5.5
django-loose-fk==0.5.6
django-markup==1.3
django-ordered-model==2.1.0
django-privates==1.0.1.post0
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ django-extensions==2.2.1
django-extra-fields==1.2.4
django-filter==2.0.0
django-ipware==2.1.0
django-loose-fk==0.5.5
django-loose-fk==0.5.6
django-markup==1.3
django-ordered-model==2.1.0
django-privates==1.0.1.post0
Expand Down
19 changes: 19 additions & 0 deletions src/openzaak/components/zaken/tests/test_zaakinformatieobjecten.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ def test_create(self):

self.assertEqual(response.json(), expected_response)

def test_create_invalid_informatieobject(self):
zaak = ZaakFactory.create()
zaak_url = reverse(zaak)

content = {
"zaak": f"http://testserver{zaak_url}",
"informatieobject": "invalidurl",
}

# Send to the API
response = self.client.post(self.list_url, content)

self.assertEqual(
response.status_code, status.HTTP_400_BAD_REQUEST, response.data
)

error = get_validation_errors(response, "informatieobject")
self.assertEqual(error["code"], "bad-url")

@freeze_time("2018-09-20 12:00:00")
def test_registratiedatum_ignored(self):
zaak = ZaakFactory.create()
Expand Down
7 changes: 6 additions & 1 deletion src/openzaak/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ def fetch_object(url: str) -> dict:

client_auth = APICredential.get_auth(url)
headers = client_auth.credentials() if client_auth else {}
response = requests.get(url, headers=headers)

try:
response = requests.get(url, headers=headers)
except requests.exceptions.RequestException as exc:
raise FetchError(exc.args[0]) from exc

try:
response.raise_for_status()
except requests.HTTPError as exc:
Expand Down
4 changes: 1 addition & 3 deletions src/openzaak/utils/validators.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from urllib.parse import urlparse

from django.utils.translation import ugettext_lazy as _

from django_loose_fk.drf import FKOrURLField, FKOrURLValidator, Resolver
from django_loose_fk.drf import FKOrURLField, FKOrURLValidator
from rest_framework import serializers
from vng_api_common.validators import IsImmutableValidator

Expand Down

0 comments on commit 3e021a4

Please sign in to comment.