Skip to content

Commit b8d142b

Browse files
✅ [#4650] Add tests for optional ownership check
* Added tests for configuration validation * Added tests for runtime behaviour
1 parent 671145c commit b8d142b

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/openforms/prefill/contrib/objects_api/tests/test_initial_data_ownership_validation.py

+16
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,19 @@ def test_verify_initial_data_ownership_missing_auth_attribute_path_causes_failin
159159
logs.filter_event("object_ownership_check_success").exists()
160160
)
161161
self.assertFalse(logs.filter_event("prefill_retrieve_success").exists())
162+
163+
def test_allow_prefill_when_ownership_check_is_skipped(self):
164+
self.variable.prefill_options["skip_ownership_check"] = True
165+
self.variable.save()
166+
submission = SubmissionFactory.create(
167+
form=self.form,
168+
# invalid BSN
169+
auth_info__value="000XXX000",
170+
auth_info__attribute=AuthAttribute.bsn,
171+
initial_data_reference=self.object_ref,
172+
)
173+
174+
try:
175+
prefill_variables(submission=submission)
176+
except PermissionDenied as exc:
177+
raise self.failureException("Ownership check should be skipped") from exc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import uuid
2+
3+
from rest_framework.test import APITestCase
4+
5+
from openforms.contrib.objects_api.tests.factories import ObjectsAPIGroupConfigFactory
6+
7+
from ..api.serializers import ObjectsAPIOptionsSerializer
8+
9+
10+
class OptionValidationTests(APITestCase):
11+
"""
12+
Test the serializer used for options validation.
13+
"""
14+
15+
def test_auth_attribute_not_required(self):
16+
api_group = ObjectsAPIGroupConfigFactory.create()
17+
data = {
18+
"objects_api_group": api_group.pk,
19+
"objecttype_uuid": uuid.uuid4(),
20+
"objecttype_version": 3,
21+
"skip_ownership_check": True,
22+
"auth_attribute_path": [],
23+
"variables_mapping": [],
24+
}
25+
serializer = ObjectsAPIOptionsSerializer(data=data)
26+
27+
is_valid = serializer.is_valid()
28+
29+
self.assertTrue(is_valid)
30+
31+
def test_auth_attribute_required(self):
32+
api_group = ObjectsAPIGroupConfigFactory.create()
33+
data = {
34+
"objects_api_group": api_group.pk,
35+
"objecttype_uuid": uuid.uuid4(),
36+
"objecttype_version": 3,
37+
"skip_ownership_check": False,
38+
"auth_attribute_path": [],
39+
"variables_mapping": [],
40+
}
41+
serializer = ObjectsAPIOptionsSerializer(data=data)
42+
43+
is_valid = serializer.is_valid()
44+
45+
self.assertFalse(is_valid)
46+
error = serializer.errors["auth_attribute_path"][0]
47+
self.assertEqual(error.code, "empty")

0 commit comments

Comments
 (0)