diff --git a/src/openforms/registrations/contrib/objects_api/config.py b/src/openforms/registrations/contrib/objects_api/config.py index 272d3f852a..c2c083fce7 100644 --- a/src/openforms/registrations/contrib/objects_api/config.py +++ b/src/openforms/registrations/contrib/objects_api/config.py @@ -5,6 +5,7 @@ from django.utils.translation import gettext_lazy as _ from drf_spectacular.utils import OpenApiExample, extend_schema_serializer +from furl import furl from rest_framework import serializers from rest_framework.exceptions import ErrorDetail @@ -411,9 +412,13 @@ def _validate_catalogue_and_document_types(attrs: RegistrationOptions) -> None: informatieobjecttypen_urls = catalogus["informatieobjecttypen"] else: - informatieobjecttypen_urls = [ - iot["url"] for iot in client.get_all_informatieobjecttypen() - ] + # Previously all informatieobjecttypen were fetched here, if there were no + # catalogue domain and RSIN specified and the legacy fields were used. + # This led to bad performance if the Catalogi service has a lot of IOtypen however + # So instead we validate each URL separately by checking if the prefix of the + # URL matches and if we can retrieve it (see below) + # issue: https://github.com/open-formulieren/open-forms/issues/4695 + informatieobjecttypen_urls = None _errors = {} for field in ( @@ -446,27 +451,55 @@ def _validate_catalogue_and_document_types(attrs: RegistrationOptions) -> None: if _errors: raise serializers.ValidationError(_errors) - # Remove these legacy fields in Open Forms 3.0 - for field in ( - "informatieobjecttype_submission_report", - "informatieobjecttype_submission_csv", - "informatieobjecttype_attachment", - ): - url = attrs.get(field) - if url: + # Remove these legacy fields in Open Forms 3.0 + for field in ( + "informatieobjecttype_submission_report", + "informatieobjecttype_submission_csv", + "informatieobjecttype_attachment", + ): + url = attrs.get(field) + if not url: + continue + warnings.warn( "URL references to document types are deprecated and will be remove in " "Open Forms 3.0", DeprecationWarning, ) - if url and url not in informatieobjecttypen_urls: + err_tpl = ( _("The provided {field} does not exist in the Catalogi API.") if catalogus is None else _("The provided {field} does not exist in the selected catalogue.") ) err_msg = err_tpl.format(field=field) - raise serializers.ValidationError({field: err_msg}, code="not-found") + + if informatieobjecttypen_urls is not None: + if url not in informatieobjecttypen_urls: + raise serializers.ValidationError( + {field: err_msg}, code="not-found" + ) + else: + assert api_group.catalogi_service + iotypen_endpoint = ( + furl(api_group.catalogi_service.api_root) / "informatieobjecttypen/" + ).url + + if not url.startswith(iotypen_endpoint): + raise serializers.ValidationError( + {field: err_msg}, code="not-found" + ) + + response = ( + client.head(url) + if client.api_version >= (1, 1, 0) + else client.get(url) + ) + + if response.status_code != 200: + raise serializers.ValidationError( + {field: err_msg}, code="not-found" + ) def _validate_objecttype_and_version(attrs: RegistrationOptions) -> None: diff --git a/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_informatieobjecttype.yaml b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_informatieobjecttype.yaml index fbc4281982..a304394df5 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_informatieobjecttype.yaml +++ b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_informatieobjecttype.yaml @@ -7,37 +7,23 @@ interactions: Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNjQ5NjM2NiwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.ivsKCx7lC9BYZIrSQ66SbzTz5HWdWd9Wqp74X4Y32C0 + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNzE2NDE1NywiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.CSC5wsXZm7PtIWsiJh1CvkxVL6v17lmi22AwZIzHQY8 Connection: - keep-alive User-Agent: - python-requests/2.32.2 - method: GET - uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen + method: HEAD + uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen/5e48c3a3-9b12-4692-98ee-5c4576b13465 response: body: - string: '{"count":7,"next":null,"previous":null,"results":[{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/cd6aeaf2-ca37-416f-b78c-1cc302f81a81","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/630271f6-568a-485e-b1c4-4ed2d6ab3a58","omschrijving":"Attachment - Informatieobjecttype other catalog","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-07-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/f2908f6f-aa07-42ef-8760-74c5234f2d25","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/630271f6-568a-485e-b1c4-4ed2d6ab3a58","omschrijving":"PDF - Informatieobjecttype other catalog","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-07-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/d1cfb1d8-8593-4814-919d-72e38e80388f","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/630271f6-568a-485e-b1c4-4ed2d6ab3a58","omschrijving":"CSV - Informatieobjecttype other catalog","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-07-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/29b63e5c-3835-4f68-8fad-f2aea9ae6b71","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"PDF - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-11","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"Attachment - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":"2024-07-10","concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/b79d9c2f-5ec4-4e23-bb66-ec6dd959a400","http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc"],"beginObject":"2024-03-19","eindeObject":"2024-07-10"},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"CSV - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"PDF - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":"2024-07-10","concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null}]}' + string: '' headers: API-version: - 1.3.1 Allow: - - GET, POST, HEAD, OPTIONS + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS Content-Length: - - '5841' + - '195' Content-Type: - application/json Cross-Origin-Opener-Policy: @@ -51,6 +37,6 @@ interactions: X-Frame-Options: - DENY status: - code: 200 - message: OK + code: 404 + message: Not Found version: 1 diff --git a/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_informatieobjecttype_validate_with_get_request.yaml b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_informatieobjecttype_validate_with_get_request.yaml new file mode 100644 index 0000000000..b2a688e8cd --- /dev/null +++ b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_informatieobjecttype_validate_with_get_request.yaml @@ -0,0 +1,43 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNzE3NjAzMSwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.uinuVRpht4kQ3mmgoIeKKswerdxpAWJioPj8j0QD9vo + Connection: + - keep-alive + User-Agent: + - python-requests/2.32.2 + method: GET + uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen/5e48c3a3-9b12-4692-98ee-5c4576b13465 + response: + body: + string: '{"type":"http://localhost:8003/ref/fouten/NotFound/","code":"not_found","title":"Niet + gevonden.","status":404,"detail":"Niet gevonden.","instance":"urn:uuid:5fc06676-764b-425f-ab16-df814e859b19"}' + headers: + API-version: + - 1.3.1 + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Length: + - '195' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Referrer-Policy: + - same-origin + Vary: + - Accept, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 404 + message: Not Found +version: 1 diff --git a/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_objecttype.yaml b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_objecttype.yaml index 81f9040927..a1d45d76d6 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_objecttype.yaml +++ b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_unknown_objecttype.yaml @@ -1,58 +1,4 @@ interactions: -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate, br - Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNjQ5NjM2NiwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.ivsKCx7lC9BYZIrSQ66SbzTz5HWdWd9Wqp74X4Y32C0 - Connection: - - keep-alive - User-Agent: - - python-requests/2.32.2 - method: GET - uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen - response: - body: - string: '{"count":7,"next":null,"previous":null,"results":[{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/cd6aeaf2-ca37-416f-b78c-1cc302f81a81","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/630271f6-568a-485e-b1c4-4ed2d6ab3a58","omschrijving":"Attachment - Informatieobjecttype other catalog","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-07-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/f2908f6f-aa07-42ef-8760-74c5234f2d25","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/630271f6-568a-485e-b1c4-4ed2d6ab3a58","omschrijving":"PDF - Informatieobjecttype other catalog","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-07-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/d1cfb1d8-8593-4814-919d-72e38e80388f","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/630271f6-568a-485e-b1c4-4ed2d6ab3a58","omschrijving":"CSV - Informatieobjecttype other catalog","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-07-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/29b63e5c-3835-4f68-8fad-f2aea9ae6b71","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"PDF - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-11","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"Attachment - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":"2024-07-10","concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/b79d9c2f-5ec4-4e23-bb66-ec6dd959a400","http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc"],"beginObject":"2024-03-19","eindeObject":"2024-07-10"},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"CSV - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"PDF - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":"2024-07-10","concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null}]}' - headers: - API-version: - - 1.3.1 - Allow: - - GET, POST, HEAD, OPTIONS - Content-Length: - - '5841' - Content-Type: - - application/json - Cross-Origin-Opener-Policy: - - same-origin - Referrer-Policy: - - same-origin - Vary: - - Accept, origin - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - status: - code: 200 - message: OK - request: body: null headers: @@ -87,7 +33,7 @@ interactions: Cross-Origin-Opener-Policy: - same-origin Date: - - Mon, 16 Sep 2024 14:19:26 GMT + - Tue, 24 Sep 2024 11:07:12 GMT Referrer-Policy: - same-origin Server: diff --git a/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_valid_serializer.yaml b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_valid_serializer.yaml index 4ac681be55..e1a5ece82e 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_valid_serializer.yaml +++ b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIOptionsSerializerTest/ObjectsAPIOptionsSerializerTest.test_valid_serializer.yaml @@ -7,37 +7,23 @@ interactions: Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNjQ5NjM2NiwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.ivsKCx7lC9BYZIrSQ66SbzTz5HWdWd9Wqp74X4Y32C0 + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNzE3NjAzMiwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.uBwpbboKud0lxg_04NYq-J8nxcnWbwUIAV16ei5gHHM Connection: - keep-alive User-Agent: - python-requests/2.32.2 method: GET - uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen + uri: http://localhost:8003/catalogi/api/v1/catalogussen?domein=VRSN response: body: - string: '{"count":7,"next":null,"previous":null,"results":[{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/cd6aeaf2-ca37-416f-b78c-1cc302f81a81","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/630271f6-568a-485e-b1c4-4ed2d6ab3a58","omschrijving":"Attachment - Informatieobjecttype other catalog","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-07-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/f2908f6f-aa07-42ef-8760-74c5234f2d25","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/630271f6-568a-485e-b1c4-4ed2d6ab3a58","omschrijving":"PDF - Informatieobjecttype other catalog","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-07-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/d1cfb1d8-8593-4814-919d-72e38e80388f","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/630271f6-568a-485e-b1c4-4ed2d6ab3a58","omschrijving":"CSV - Informatieobjecttype other catalog","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-07-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/29b63e5c-3835-4f68-8fad-f2aea9ae6b71","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"PDF - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-07-11","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"Attachment - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":"2024-07-10","concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/b79d9c2f-5ec4-4e23-bb66-ec6dd959a400","http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc"],"beginObject":"2024-03-19","eindeObject":"2024-07-10"},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"CSV - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"PDF - Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":"2024-07-10","concept":false,"besluittypen":[],"informatieobjectcategorie":"Test - category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null}]}' + string: '{"count":0,"next":null,"previous":null,"results":[]}' headers: API-version: - 1.3.1 Allow: - GET, POST, HEAD, OPTIONS Content-Length: - - '5841' + - '52' Content-Type: - application/json Cross-Origin-Opener-Policy: @@ -53,6 +39,132 @@ interactions: status: code: 200 message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNzE3NjAzMiwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.uBwpbboKud0lxg_04NYq-J8nxcnWbwUIAV16ei5gHHM + Connection: + - keep-alive + User-Agent: + - python-requests/2.32.2 + method: HEAD + uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3 + response: + body: + string: '' + headers: + API-version: + - 1.3.1 + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Length: + - '790' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + ETag: + - '"89d53439caa01c2f00ab822679e80c7b"' + Referrer-Policy: + - same-origin + Vary: + - Accept, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNzE3NjAzMiwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.uBwpbboKud0lxg_04NYq-J8nxcnWbwUIAV16ei5gHHM + Connection: + - keep-alive + User-Agent: + - python-requests/2.32.2 + method: HEAD + uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7 + response: + body: + string: '' + headers: + API-version: + - 1.3.1 + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Length: + - '986' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + ETag: + - '"9b92accfbfdb5c0d2c8d040a5825abfd"' + Referrer-Policy: + - same-origin + Vary: + - Accept, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNzE3NjAzMiwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.uBwpbboKud0lxg_04NYq-J8nxcnWbwUIAV16ei5gHHM + Connection: + - keep-alive + User-Agent: + - python-requests/2.32.2 + method: HEAD + uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b + response: + body: + string: '' + headers: + API-version: + - 1.3.1 + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Length: + - '798' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + ETag: + - '"bfa6b74c27efa9845576bf1d54281820"' + Referrer-Policy: + - same-origin + Vary: + - Accept, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 200 + message: OK - request: body: null headers: @@ -87,7 +199,7 @@ interactions: Cross-Origin-Opener-Policy: - same-origin Date: - - Mon, 16 Sep 2024 14:19:27 GMT + - Tue, 24 Sep 2024 11:07:12 GMT Referrer-Policy: - same-origin Server: @@ -137,7 +249,7 @@ interactions: Cross-Origin-Opener-Policy: - same-origin Date: - - Mon, 16 Sep 2024 14:19:27 GMT + - Tue, 24 Sep 2024 11:07:12 GMT Referrer-Policy: - same-origin Server: diff --git a/src/openforms/registrations/contrib/objects_api/tests/test_serializer.py b/src/openforms/registrations/contrib/objects_api/tests/test_serializer.py index 3c3ae6ad73..59dc1e7332 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/test_serializer.py +++ b/src/openforms/registrations/contrib/objects_api/tests/test_serializer.py @@ -1,4 +1,5 @@ from pathlib import Path +from unittest.mock import PropertyMock, patch from django.test import TestCase @@ -69,14 +70,67 @@ def test_invalid_fields_v2(self): ) self.assertFalse(options.is_valid()) - def test_unknown_informatieobjecttype(self): + @patch( + "openforms.contrib.zgw.clients.catalogi.CatalogiClient.api_version", + return_value=(1, 2, 0), + new_callable=PropertyMock, + ) + def test_unknown_informatieobjecttype(self, mock_api_version): options = ObjectsAPIOptionsSerializer( data={ "objects_api_group": self.objects_api_group.pk, "version": 2, "objecttype": "8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", "objecttype_version": 1, - "informatieobjecttype_attachment": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/1", + "informatieobjecttype_attachment": ( + "http://localhost:8003/catalogi/api/v1/" + "informatieobjecttypen/5e48c3a3-9b12-4692-98ee-5c4576b13465" + ), + }, + ) + + self.assertFalse(options.is_valid()) + self.assertIn("informatieobjecttype_attachment", options.errors) + error = options.errors["informatieobjecttype_attachment"][0] + self.assertEqual(error.code, "not-found") + + @patch( + "openforms.contrib.zgw.clients.catalogi.CatalogiClient.api_version", + return_value=(1, 0, 0), + new_callable=PropertyMock, + ) + def test_unknown_informatieobjecttype_validate_with_get_request( + self, mock_api_version + ): + options = ObjectsAPIOptionsSerializer( + data={ + "objects_api_group": self.objects_api_group.pk, + "version": 2, + "objecttype": "8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", + "objecttype_version": 1, + "informatieobjecttype_attachment": ( + "http://localhost:8003/catalogi/api/v1/" + "informatieobjecttypen/5e48c3a3-9b12-4692-98ee-5c4576b13465" + ), + }, + ) + + self.assertFalse(options.is_valid()) + self.assertIn("informatieobjecttype_attachment", options.errors) + error = options.errors["informatieobjecttype_attachment"][0] + self.assertEqual(error.code, "not-found") + + def test_using_zaaktype_instead_of_informatieobjecttype(self): + options = ObjectsAPIOptionsSerializer( + data={ + "objects_api_group": self.objects_api_group.pk, + "version": 2, + "objecttype": "8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", + "objecttype_version": 1, + "informatieobjecttype_attachment": ( + "http://localhost:8003/catalogi/api/v1/" + "zaaktypen/5e48c3a3-9b12-4692-98ee-5c4576b13465" # incorrect endpoint + ), }, )