@@ -42,6 +42,49 @@ def test_location_mapping(self, app):
4242 == "https://sub.testserver.company:1234/foo/bar/v2/ServiceProviderConfig"
4343 )
4444
45+ def test_resource_location_under_a_mount_prefix (self , app , fake_user_data ):
46+ """The location of a resource keeps the prefix the application is mounted under."""
47+ transport = httpx2 .WSGITransport (app = app , script_name = "/foo/bar" )
48+ with httpx2 .Client (
49+ transport = transport , base_url = "https://scim.example.com"
50+ ) as client :
51+ r = client .post ("/v2/Users" , json = fake_user_data [0 ])
52+ location = f"https://scim.example.com/foo/bar/v2/Users/{ r .json ()['id' ]} "
53+ assert r .headers ["Location" ] == location
54+ assert r .json ()["meta" ]["location" ] == location
55+ assert client .get ("/Users" ).json ()["Resources" ][0 ]["meta" ]["location" ] == (
56+ location
57+ )
58+
59+ r = client .post (
60+ "/v2/Bulk" ,
61+ json = {
62+ "schemas" : ["urn:ietf:params:scim:api:messages:2.0:BulkRequest" ],
63+ "Operations" : [
64+ {
65+ "method" : "POST" ,
66+ "path" : "/Users" ,
67+ "bulkId" : "u" ,
68+ "data" : fake_user_data [1 ],
69+ }
70+ ],
71+ },
72+ )
73+ assert r .json ()["Operations" ][0 ]["location" ].startswith (
74+ "https://scim.example.com/foo/bar/v2/Users/"
75+ )
76+
77+ def test_absolute_location_from_the_backend_is_kept (self , app , fake_user_data ):
78+ """A backend may store an absolute location, which is published as it is."""
79+ transport = httpx2 .WSGITransport (app = app , script_name = "/foo" )
80+ with httpx2 .Client (
81+ transport = transport , base_url = "https://scim.example.com"
82+ ) as client :
83+ user_id = client .post ("/v2/Users" , json = fake_user_data [0 ]).json ()["id" ]
84+ app .backend .resources [0 ].meta .location = "https://other.example/Users/x"
85+ r = client .get (f"/v2/Users/{ user_id } " )
86+ assert r .json ()["meta" ]["location" ] == "https://other.example/Users/x"
87+
4588 def test_service_provider_configuration (self , wsgi ):
4689 r = wsgi .get ("/v2/ServiceProviderConfig" )
4790 assert r .status_code == 200
0 commit comments