From be5e036448d31137326e8e98a6e132ea760bdb57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Mon, 28 Jul 2025 18:03:14 +0200 Subject: [PATCH] fix: patch extension root patching extension roots was raising 'invalidPath' errors --- scim2_server/operators.py | 3 ++- tests/test_operators.py | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/scim2_server/operators.py b/scim2_server/operators.py index 975ab22..b1ae05c 100644 --- a/scim2_server/operators.py +++ b/scim2_server/operators.py @@ -138,7 +138,8 @@ def __call__(self, model: BaseModel): ) return self.do_return() case _: - raise SCIMException(Error.make_invalid_path_error()) + self.call_on_root(model) + return self.do_return() def match_multi_valued_attribute_sub( self, attribute: str, condition: str, model: BaseModel, sub_attribute: str diff --git a/tests/test_operators.py b/tests/test_operators.py index 472c501..ee3d34f 100644 --- a/tests/test_operators.py +++ b/tests/test_operators.py @@ -311,6 +311,14 @@ def test_add_operator_extension_complex(self): ] assert u.EnterpriseUser.manager.value == "1234" + def test_add_operator_extension_root(self): + u = User[EnterpriseUser]() + AddOperator( + "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", + {"employeeNumber": "1234"}, + )(u) + assert u.EnterpriseUser.employee_number == "1234" + def test_add_operator_extension_path(self): u = User[EnterpriseUser]() AddOperator( @@ -422,6 +430,15 @@ def test_replace_operator_root_object(self): assert u.user_name == "foo" assert u.name == Name(formatted="Mr. Foo") + def test_replace_operator_extension_root_object(self): + u = User[EnterpriseUser](user_name="bar") + u.EnterpriseUser = EnterpriseUser(employee_number="4321") + ReplaceOperator( + "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", + {"employeeNumber": "1234"}, + )(u) + assert u.EnterpriseUser.employee_number == "1234" + def test_replace_operator_overwrite_required_attribute(self): u = User(user_name="A") with pytest.raises(SCIMException, match="invalidValue"): @@ -496,10 +513,10 @@ def test_remove_operator_multi_valued_filter_sub_attribute(self): Email(value="home@example.com", primary=False), ] - def test_remove_operator_extension(self): + def test_remove_operator_extension_root(self): u = User[EnterpriseUser]() u.EnterpriseUser = EnterpriseUser(employee_number="123") - with pytest.raises(SCIMException, match="invalidPath"): + with pytest.raises(SCIMException, match="noTarget"): RemoveOperator( "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", None )(u)