Skip to content

Commit 1c7e6e6

Browse files
authored
Merge pull request #3 from yaal-coop/issue-2-optional-version-prefix
make the `/v2` version prefix optional
2 parents 661e333 + 0e84e77 commit 1c7e6e6

2 files changed

Lines changed: 41 additions & 13 deletions

File tree

scim2_server/provider.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
import json
23
import logging
34
import traceback
@@ -54,63 +55,66 @@ def __init__(self, backend: Backend):
5455
self.log = logging.getLogger("SCIMProvider")
5556

5657
# Register the URL mapping. The endpoint refers to the name of the function to be called in this SCIMProvider ("call_" + endpoint).
57-
self.url_map = Map(
58+
rules = itertools.chain.from_iterable(
5859
[
5960
Rule(
60-
"/v2/ServiceProviderConfig",
61+
f"{prefix}/ServiceProviderConfig",
6162
endpoint="service_provider_config",
6263
methods=("GET",),
6364
),
6465
Rule(
65-
"/v2/ResourceTypes",
66+
f"{prefix}/ResourceTypes",
6667
endpoint="resource_types",
6768
methods=("GET",),
6869
),
6970
Rule(
70-
"/v2/ResourceTypes/<string:resource_type>",
71+
f"{prefix}/ResourceTypes/<string:resource_type>",
7172
endpoint="resource_type",
7273
methods=("GET",),
7374
),
7475
Rule(
75-
"/v2/Schemas",
76+
f"{prefix}/Schemas",
7677
endpoint="schemas",
7778
methods=("GET",),
7879
),
7980
Rule(
80-
"/v2/Schemas/<string:schema_id>",
81+
f"{prefix}/Schemas/<string:schema_id>",
8182
endpoint="schema",
8283
methods=("GET",),
8384
),
8485
Rule(
85-
"/v2/Me",
86+
f"{prefix}/Me",
8687
endpoint="me",
8788
methods=("GET", "POST", "PUT", "PATCH", "DELETE"),
8889
),
8990
Rule(
90-
"/v2/<string:resource_endpoint>",
91+
f"{prefix}/<string:resource_endpoint>",
9192
endpoint="resource",
9293
methods=("GET", "POST"),
9394
),
9495
Rule(
95-
"/v2/<string:resource_endpoint>/.search",
96+
f"{prefix}/<string:resource_endpoint>/.search",
9697
endpoint="resource_search",
9798
methods=("POST",),
9899
),
99100
Rule(
100-
"/v2/<string:resource_endpoint>/<string:resource_id>",
101+
f"{prefix}/<string:resource_endpoint>/<string:resource_id>",
101102
endpoint="single_resource",
102103
methods=("GET", "PUT", "PATCH", "DELETE"),
103104
),
104105
Rule(
105-
"/v2/Bulk",
106+
f"{prefix}/Bulk",
106107
endpoint="bulk",
107108
methods=("POST",),
108109
),
109-
Rule("/v2/", endpoint="query_all", methods=("GET",)),
110-
Rule("/v2/.search", endpoint="query_all", methods=("POST",)),
110+
Rule(f"{prefix}/", endpoint="query_all", methods=("GET",)),
111+
Rule(f"{prefix}/.search", endpoint="query_all", methods=("POST",)),
111112
]
113+
for prefix in ("", "/v2")
112114
)
113115

116+
self.url_map = Map(rules)
117+
114118
@staticmethod
115119
def adjust_location(
116120
request: Request, resource: Resource, cp=False

tests/integration/test_scim_provider.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ def test_service_provider_configuration(self, wsgi):
5353
"sort": {"supported": True},
5454
}
5555

56+
def test_no_version_prefix(self, wsgi):
57+
"""Test a location without the /v2 version prefix."""
58+
59+
r = wsgi.get("/ServiceProviderConfig")
60+
assert r.status_code == 200
61+
assert r.headers["Location"] == "https://scim.example.com/ServiceProviderConfig"
62+
assert r.json() == {
63+
"authenticationSchemes": [],
64+
"bulk": {
65+
"supported": False,
66+
},
67+
"changePassword": {"supported": True},
68+
"documentationUri": "https://www.example.com/",
69+
"etag": {"supported": True},
70+
"filter": {"maxResults": 1000, "supported": True},
71+
"meta": {
72+
"location": "https://scim.example.com/ServiceProviderConfig",
73+
"resourceType": "ServiceProviderConfig",
74+
},
75+
"patch": {"supported": True},
76+
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
77+
"sort": {"supported": True},
78+
}
79+
5680
def test_schemas(self, wsgi):
5781
r = wsgi.get("/v2/Schemas")
5882
assert r.status_code == 200

0 commit comments

Comments
 (0)