scim2-server 0.8.7__tar.gz → 0.8.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scim2_server-0.8.7 → scim2_server-0.8.9}/PKG-INFO +2 -2
- {scim2_server-0.8.7 → scim2_server-0.8.9}/pyproject.toml +2 -2
- {scim2_server-0.8.7 → scim2_server-0.8.9}/pyproject.toml.orig +2 -2
- scim2_server-0.8.9/scim2_server/keyset.py +219 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/memory.py +44 -55
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/storage.py +14 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/testing.py +169 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/LICENSE +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/README.md +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/__init__.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/applications/__init__.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/applications/asgi.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/applications/base.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/applications/wsgi.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/bulk.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/conditions.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/cursor.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/errors.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/handler.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/py.typed +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/requests.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/resources/default-resource-types.json +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/resources/default-schemas.json +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/resources/default-service-provider-config.json +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/responses.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/routing.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/service.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/testserver/__init__.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/testserver/application.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/testserver/cli.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/testserver/oauth.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/testserver/precis.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: scim2-server
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.9
|
|
4
4
|
Summary: SCIM server core for any storage and web framework
|
|
5
5
|
Keywords: scim,scim2,provisioning,rfc7643,rfc7644
|
|
6
6
|
Author: Yaal Coop, Christian Friedrich Coors
|
|
@@ -218,7 +218,7 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
|
218
218
|
Classifier: Environment :: Web Environment
|
|
219
219
|
Classifier: Programming Language :: Python
|
|
220
220
|
Classifier: Operating System :: OS Independent
|
|
221
|
-
Requires-Dist: scim2-models>=0.12.
|
|
221
|
+
Requires-Dist: scim2-models>=0.12.7
|
|
222
222
|
Requires-Dist: cryptography>=50.0.1 ; extra == 'cursor'
|
|
223
223
|
Requires-Dist: authlib>=1.10.0b1 ; extra == 'oauth'
|
|
224
224
|
Requires-Dist: precis-i18n>=1.1.2 ; extra == 'precis'
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "scim2-server"
|
|
7
|
-
version = "0.8.
|
|
7
|
+
version = "0.8.9"
|
|
8
8
|
description = "SCIM server core for any storage and web framework"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
keywords = [
|
|
@@ -29,7 +29,7 @@ classifiers = [
|
|
|
29
29
|
"Operating System :: OS Independent",
|
|
30
30
|
]
|
|
31
31
|
requires-python = ">= 3.11"
|
|
32
|
-
dependencies = ["scim2-models>=0.12.
|
|
32
|
+
dependencies = ["scim2-models>=0.12.7"]
|
|
33
33
|
|
|
34
34
|
[[project.authors]]
|
|
35
35
|
name = "Yaal Coop"
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "scim2-server"
|
|
7
|
-
version = "0.8.
|
|
7
|
+
version = "0.8.9"
|
|
8
8
|
description = "SCIM server core for any storage and web framework"
|
|
9
9
|
authors = [
|
|
10
10
|
{name="Yaal Coop", email="contact@yaal.coop"},
|
|
@@ -30,7 +30,7 @@ classifiers = [
|
|
|
30
30
|
|
|
31
31
|
requires-python = ">= 3.11"
|
|
32
32
|
dependencies = [
|
|
33
|
-
"scim2-models>=0.12.
|
|
33
|
+
"scim2-models>=0.12.7",
|
|
34
34
|
]
|
|
35
35
|
|
|
36
36
|
[project.optional-dependencies]
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""Helpers for a storage that pages with cursors by keyset.
|
|
2
|
+
|
|
3
|
+
A keyset storage orders the rows by the sort value, then by identifier. A
|
|
4
|
+
position holds the sort value and the identifier of the row a page starts
|
|
5
|
+
after, or ends before. These helpers read and write such positions, and build
|
|
6
|
+
the pages around them. A storage may use its own positions instead.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import datetime
|
|
10
|
+
import decimal
|
|
11
|
+
import uuid
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from collections.abc import Sequence
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from scim2_models import InvalidCursorException
|
|
18
|
+
from scim2_models import Resource
|
|
19
|
+
from scim2_models import SearchRequest
|
|
20
|
+
|
|
21
|
+
from scim2_server.storage import SearchPage
|
|
22
|
+
|
|
23
|
+
_TAGGED: dict[str, tuple[type, Callable[[Any], str], Callable[[str], Any]]] = {
|
|
24
|
+
"datetime": (
|
|
25
|
+
datetime.datetime,
|
|
26
|
+
datetime.datetime.isoformat,
|
|
27
|
+
datetime.datetime.fromisoformat,
|
|
28
|
+
),
|
|
29
|
+
"date": (datetime.date, datetime.date.isoformat, datetime.date.fromisoformat),
|
|
30
|
+
"decimal": (decimal.Decimal, str, decimal.Decimal),
|
|
31
|
+
"uuid": (uuid.UUID, str, uuid.UUID),
|
|
32
|
+
}
|
|
33
|
+
"""The sort values JSON has no type for, by tag. A datetime is a date too, so it comes first."""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def encode_sort_value(value: Any) -> Any:
|
|
37
|
+
"""Return a sort value as a value JSON can hold.
|
|
38
|
+
|
|
39
|
+
:data:`None`, booleans, numbers and strings are returned as they are.
|
|
40
|
+
A :class:`~datetime.datetime`, a :class:`~datetime.date`, a
|
|
41
|
+
:class:`~decimal.Decimal` or a :class:`~uuid.UUID` is returned as an
|
|
42
|
+
object with a tag, such as ``{"date": "2026-10-09"}``, so that
|
|
43
|
+
:func:`decode_sort_value` gives it back in its own type.
|
|
44
|
+
|
|
45
|
+
:raises TypeError: if the value has another type.
|
|
46
|
+
"""
|
|
47
|
+
if value is None or isinstance(value, bool | int | float | str):
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
for tag, (python_type, dump, _) in _TAGGED.items():
|
|
51
|
+
if isinstance(value, python_type):
|
|
52
|
+
return {tag: dump(value)}
|
|
53
|
+
|
|
54
|
+
raise TypeError(f"Cannot page on a sort value of type {type(value).__name__}")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def decode_sort_value(value: Any) -> Any:
|
|
58
|
+
"""Return the sort value that :func:`encode_sort_value` gave.
|
|
59
|
+
|
|
60
|
+
:raises ~scim2_models.InvalidCursorException: if no sort value gives this value.
|
|
61
|
+
"""
|
|
62
|
+
if value is None or isinstance(value, bool | int | float | str):
|
|
63
|
+
return value
|
|
64
|
+
|
|
65
|
+
if not isinstance(value, dict) or len(value) != 1:
|
|
66
|
+
raise InvalidCursorException
|
|
67
|
+
|
|
68
|
+
((tag, text),) = value.items()
|
|
69
|
+
if tag not in _TAGGED or not isinstance(text, str):
|
|
70
|
+
raise InvalidCursorException
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
return _TAGGED[tag][2](text)
|
|
74
|
+
except (ValueError, decimal.InvalidOperation):
|
|
75
|
+
raise InvalidCursorException from None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass(frozen=True)
|
|
79
|
+
class Bound:
|
|
80
|
+
"""The first or the last row of a page, as :func:`keyset_page` needs it."""
|
|
81
|
+
|
|
82
|
+
key: Any
|
|
83
|
+
"""The sort value of the row, or :data:`None` when it has none, or when the search has no sort."""
|
|
84
|
+
|
|
85
|
+
id: str
|
|
86
|
+
"""The identifier of the resource of the row."""
|
|
87
|
+
|
|
88
|
+
type_index: int | None = None
|
|
89
|
+
"""The index of the resource type of the row, in a search at the root that orders the rows by resource type."""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass(frozen=True)
|
|
93
|
+
class Position:
|
|
94
|
+
"""The row a cursor page starts after, or ends before.
|
|
95
|
+
|
|
96
|
+
The rows with the same sort value are ordered by identifier. In a search
|
|
97
|
+
at the root, a storage may order them by the index of their resource type
|
|
98
|
+
first, so that two resources of different types can share an identifier.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
forward: bool
|
|
102
|
+
"""Whether the page starts after the row, rather than ending before it."""
|
|
103
|
+
|
|
104
|
+
key: Any
|
|
105
|
+
"""The sort value of the row, or :data:`None` when it has none, or when the search has no sort."""
|
|
106
|
+
|
|
107
|
+
id: str
|
|
108
|
+
"""The identifier of the resource of the row."""
|
|
109
|
+
|
|
110
|
+
type_index: int | None = None
|
|
111
|
+
"""The index of the resource type of the row, in a search at the root that orders the rows by resource type."""
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def load(
|
|
115
|
+
cls, value: Any, *, has_sort: bool, type_count: int | None = None
|
|
116
|
+
) -> "Position | None":
|
|
117
|
+
"""Read a position that :meth:`dump` wrote, or return :data:`None` for the first page.
|
|
118
|
+
|
|
119
|
+
``has_sort`` tells whether the search has a sort. Without one, the
|
|
120
|
+
position holds no sort value.
|
|
121
|
+
|
|
122
|
+
``type_count`` is the number of resource types that the storage
|
|
123
|
+
orders the rows by. A storage that does not order the rows by
|
|
124
|
+
resource type leaves it out. The position holds the index of a
|
|
125
|
+
resource type when ``type_count`` is given, and holds none
|
|
126
|
+
otherwise. :meth:`dump` writes this index when
|
|
127
|
+
:attr:`type_index` is not :data:`None`.
|
|
128
|
+
|
|
129
|
+
:raises ~scim2_models.InvalidCursorException: if the value is not such
|
|
130
|
+
a position.
|
|
131
|
+
"""
|
|
132
|
+
if value is None:
|
|
133
|
+
return None
|
|
134
|
+
|
|
135
|
+
by_type = type_count is not None
|
|
136
|
+
names = {"d", "k", "t", "i"} if by_type else {"d", "k", "i"}
|
|
137
|
+
if not isinstance(value, dict) or set(value) != names:
|
|
138
|
+
raise InvalidCursorException
|
|
139
|
+
|
|
140
|
+
if value["d"] not in ("next", "previous") or not isinstance(value["i"], str):
|
|
141
|
+
raise InvalidCursorException
|
|
142
|
+
|
|
143
|
+
if not has_sort and value["k"] is not None:
|
|
144
|
+
raise InvalidCursorException
|
|
145
|
+
|
|
146
|
+
type_index = value.get("t")
|
|
147
|
+
if by_type and (
|
|
148
|
+
type(type_index) is not int or type_index not in range(type_count or 0)
|
|
149
|
+
):
|
|
150
|
+
raise InvalidCursorException
|
|
151
|
+
|
|
152
|
+
key = decode_sort_value(value["k"])
|
|
153
|
+
return cls(value["d"] == "next", key, value["i"], type_index)
|
|
154
|
+
|
|
155
|
+
def dump(self) -> dict[str, Any]:
|
|
156
|
+
"""Return the position as a value JSON can hold.
|
|
157
|
+
|
|
158
|
+
:raises TypeError: if :func:`encode_sort_value` cannot hold the sort value.
|
|
159
|
+
"""
|
|
160
|
+
position: dict[str, Any] = {
|
|
161
|
+
"d": "next" if self.forward else "previous",
|
|
162
|
+
"k": encode_sort_value(self.key),
|
|
163
|
+
}
|
|
164
|
+
if self.type_index is not None:
|
|
165
|
+
position["t"] = self.type_index
|
|
166
|
+
|
|
167
|
+
position["i"] = self.id
|
|
168
|
+
return position
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def page_rows(
|
|
172
|
+
rows: Sequence[Any], search_request: SearchRequest[Any], position: Position | None
|
|
173
|
+
) -> tuple[list[Any], bool]:
|
|
174
|
+
"""Return the rows of a page in the sort order, and whether more rows follow in the reading direction.
|
|
175
|
+
|
|
176
|
+
For a cursor page, the storage reads ``count + 1`` rows, in the reverse
|
|
177
|
+
order for a page that ends before the position. Without a cursor, the
|
|
178
|
+
rows are returned as they are.
|
|
179
|
+
"""
|
|
180
|
+
if search_request.cursor is None:
|
|
181
|
+
return list(rows), False
|
|
182
|
+
|
|
183
|
+
count = search_request.count
|
|
184
|
+
more = count is not None and len(rows) > count
|
|
185
|
+
page = list(rows if count is None else rows[:count])
|
|
186
|
+
if position is not None and not position.forward:
|
|
187
|
+
page.reverse()
|
|
188
|
+
|
|
189
|
+
return page, more
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def keyset_page(
|
|
193
|
+
total: int | None,
|
|
194
|
+
resources: Sequence[Resource[Any]],
|
|
195
|
+
first: Bound | None,
|
|
196
|
+
last: Bound | None,
|
|
197
|
+
more: bool,
|
|
198
|
+
position: Position | None,
|
|
199
|
+
) -> SearchPage:
|
|
200
|
+
"""Return a cursor page, with the positions of the pages around it.
|
|
201
|
+
|
|
202
|
+
``first`` and ``last`` are the first and the last rows of the page, or
|
|
203
|
+
:data:`None` when the page is empty. ``more`` tells whether more rows
|
|
204
|
+
follow in the reading direction, as :func:`page_rows` gives it. In the
|
|
205
|
+
other direction, the page the client comes from is assumed to still
|
|
206
|
+
exist.
|
|
207
|
+
"""
|
|
208
|
+
page = SearchPage(total, list(resources))
|
|
209
|
+
if first is None or last is None:
|
|
210
|
+
return page
|
|
211
|
+
|
|
212
|
+
forward = position is None or position.forward
|
|
213
|
+
if more or not forward:
|
|
214
|
+
page.next = Position(True, last.key, last.id, last.type_index).dump()
|
|
215
|
+
|
|
216
|
+
if position is not None and (more or forward):
|
|
217
|
+
page.previous = Position(False, first.key, first.id, first.type_index).dump()
|
|
218
|
+
|
|
219
|
+
return page
|
|
@@ -10,7 +10,6 @@ from typing import Union
|
|
|
10
10
|
from typing import cast
|
|
11
11
|
|
|
12
12
|
from scim2_models import AttributeBinding
|
|
13
|
-
from scim2_models import InvalidCursorException
|
|
14
13
|
from scim2_models import Meta
|
|
15
14
|
from scim2_models import NotFoundException
|
|
16
15
|
from scim2_models import Path
|
|
@@ -25,6 +24,7 @@ from scim2_models import UniquenessException
|
|
|
25
24
|
from scim2_models.path import CompareOperator
|
|
26
25
|
from scim2_models.path import Comparison
|
|
27
26
|
|
|
27
|
+
from scim2_server.keyset import Position
|
|
28
28
|
from scim2_server.storage import AsyncScimStorage
|
|
29
29
|
from scim2_server.storage import ScimStorage
|
|
30
30
|
from scim2_server.storage import SearchPage
|
|
@@ -39,19 +39,28 @@ def utcnow() -> datetime.datetime:
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
def _page(
|
|
42
|
-
search_request: SearchRequest[Any],
|
|
42
|
+
search_request: SearchRequest[Any],
|
|
43
|
+
position: Any,
|
|
44
|
+
resources: list[Resource[Any]],
|
|
45
|
+
names: list[str | None],
|
|
43
46
|
) -> SearchPage:
|
|
44
|
-
"""Sort every matching resource by its sort value then its identifier, and return the page a search asks for.
|
|
47
|
+
"""Sort every matching resource by its sort value, its resource type then its identifier, and return the page a search asks for.
|
|
45
48
|
|
|
46
|
-
A cursor position holds the sort value
|
|
47
|
-
the page starts after, or ends before, so the
|
|
49
|
+
A cursor position holds the sort value, the resource type and the
|
|
50
|
+
identifier of the resource the page starts after, or ends before, so the
|
|
51
|
+
pages stay stable. The resource type is left out of the positions of a
|
|
52
|
+
search on a single resource type.
|
|
48
53
|
"""
|
|
54
|
+
types = {name: index for index, name in enumerate(names)}
|
|
49
55
|
descending = (
|
|
50
56
|
search_request.sort_by is not None
|
|
51
57
|
and search_request.sort_order == SearchRequest.SortOrder.descending
|
|
52
58
|
)
|
|
53
59
|
pairs = sorted(
|
|
54
|
-
(
|
|
60
|
+
(
|
|
61
|
+
(_sort_key(search_request, types, resource), resource)
|
|
62
|
+
for resource in resources
|
|
63
|
+
),
|
|
55
64
|
key=lambda pair: pair[0],
|
|
56
65
|
reverse=descending,
|
|
57
66
|
)
|
|
@@ -64,40 +73,51 @@ def _page(
|
|
|
64
73
|
if search_request.count == 0:
|
|
65
74
|
return SearchPage(len(found), [])
|
|
66
75
|
|
|
76
|
+
type_count = len(types) if len(types) > 1 else None
|
|
77
|
+
anchor = Position.load(
|
|
78
|
+
position, has_sort=search_request.sort_by is not None, type_count=type_count
|
|
79
|
+
)
|
|
67
80
|
start, stop = _bounds(
|
|
68
|
-
[key for key, _ in pairs],
|
|
81
|
+
[key for key, _ in pairs], anchor, search_request.count, descending
|
|
69
82
|
)
|
|
70
83
|
page = SearchPage(len(found), found[start:stop])
|
|
71
84
|
if page.resources and stop < len(found):
|
|
72
|
-
page.next = _position(
|
|
85
|
+
page.next = _position(True, pairs[stop - 1][0], type_count)
|
|
73
86
|
if page.resources and start > 0:
|
|
74
|
-
page.previous = _position(
|
|
87
|
+
page.previous = _position(False, pairs[start][0], type_count)
|
|
75
88
|
return page
|
|
76
89
|
|
|
77
90
|
|
|
78
|
-
SortKey = tuple[bool, Any, str]
|
|
91
|
+
SortKey = tuple[bool, Any, int, str]
|
|
79
92
|
|
|
80
93
|
|
|
81
|
-
def _sort_key(
|
|
82
|
-
|
|
94
|
+
def _sort_key(
|
|
95
|
+
search_request: SearchRequest[Any],
|
|
96
|
+
types: dict[str | None, int],
|
|
97
|
+
resource: Resource[Any],
|
|
98
|
+
) -> SortKey:
|
|
99
|
+
"""Return the key that orders a resource: its sort value, missing values last, then its resource type and its identifier."""
|
|
83
100
|
value = search_request.sort_value(resource)
|
|
84
|
-
|
|
101
|
+
type_index = types[cast(Meta, resource.meta).resource_type]
|
|
102
|
+
missing = value is None
|
|
103
|
+
return missing, "" if missing else value, type_index, cast(str, resource.id)
|
|
85
104
|
|
|
86
105
|
|
|
87
106
|
def _bounds(
|
|
88
|
-
keys: list[SortKey],
|
|
107
|
+
keys: list[SortKey], anchor: Position | None, count: int | None, descending: bool
|
|
89
108
|
) -> tuple[int, int]:
|
|
90
109
|
"""Return the slice of the sorted keys that a cursor page covers."""
|
|
91
|
-
if
|
|
110
|
+
if anchor is None:
|
|
92
111
|
return 0, len(keys) if count is None else min(count, len(keys))
|
|
93
112
|
|
|
94
|
-
|
|
113
|
+
missing = anchor.key is None
|
|
114
|
+
bound = (missing, "" if missing else anchor.key, anchor.type_index or 0, anchor.id)
|
|
95
115
|
|
|
96
116
|
def before(key: SortKey) -> bool:
|
|
97
|
-
return key >
|
|
117
|
+
return key > bound if descending else key < bound
|
|
98
118
|
|
|
99
|
-
if
|
|
100
|
-
start = sum(1 for key in keys if before(key) or key ==
|
|
119
|
+
if anchor.forward:
|
|
120
|
+
start = sum(1 for key in keys if before(key) or key == bound)
|
|
101
121
|
stop = len(keys) if count is None else min(start + count, len(keys))
|
|
102
122
|
return start, stop
|
|
103
123
|
|
|
@@ -106,42 +126,11 @@ def _bounds(
|
|
|
106
126
|
return start, stop
|
|
107
127
|
|
|
108
128
|
|
|
109
|
-
def _position(
|
|
129
|
+
def _position(forward: bool, key: SortKey, type_count: int | None) -> dict[str, Any]:
|
|
110
130
|
"""Return the position of the page that starts after, or ends before, a sort key."""
|
|
111
|
-
missing, value, identifier = key
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def _read_position(position: Any) -> tuple[str, SortKey]:
|
|
116
|
-
"""Return the direction and the sort key of a position that _page gave."""
|
|
117
|
-
try:
|
|
118
|
-
direction, value, identifier = position["d"], position["k"], position["i"]
|
|
119
|
-
except (TypeError, KeyError):
|
|
120
|
-
raise InvalidCursorException from None
|
|
121
|
-
if direction not in ("next", "previous") or not isinstance(identifier, str):
|
|
122
|
-
raise InvalidCursorException
|
|
123
|
-
if value is None:
|
|
124
|
-
return direction, (True, "", identifier)
|
|
125
|
-
return direction, (False, _decode(value), identifier)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def _encode(value: Any) -> Any:
|
|
129
|
-
"""Return a sort value in a form JSON can hold."""
|
|
130
|
-
if isinstance(value, datetime.datetime):
|
|
131
|
-
return {"datetime": value.isoformat()}
|
|
132
|
-
if isinstance(value, str | bool | int | float):
|
|
133
|
-
return value
|
|
134
|
-
raise TypeError(f"A cursor cannot hold a sort value of type {type(value).__name__}")
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def _decode(value: Any) -> Any:
|
|
138
|
-
"""Return the sort value that _encode gave."""
|
|
139
|
-
if not isinstance(value, dict):
|
|
140
|
-
return value
|
|
141
|
-
try:
|
|
142
|
-
return datetime.datetime.fromisoformat(value["datetime"])
|
|
143
|
-
except (KeyError, TypeError, ValueError):
|
|
144
|
-
raise InvalidCursorException from None
|
|
131
|
+
missing, value, type_index, identifier = key
|
|
132
|
+
by_type = None if type_count is None else type_index
|
|
133
|
+
return Position(forward, None if missing else value, identifier, by_type).dump()
|
|
145
134
|
|
|
146
135
|
|
|
147
136
|
Key = tuple[str | None, str]
|
|
@@ -298,7 +287,7 @@ class InMemoryStorage(ScimStorage):
|
|
|
298
287
|
found = [
|
|
299
288
|
r for r in candidates if scim_filter is None or scim_filter.match(r)
|
|
300
289
|
]
|
|
301
|
-
page = _page(search_request, position, found)
|
|
290
|
+
page = _page(search_request, position, found, names)
|
|
302
291
|
page.resources = [r.model_copy(deep=True) for r in page.resources]
|
|
303
292
|
return page
|
|
304
293
|
|
|
@@ -173,6 +173,14 @@ class ScimStorage(ABC):
|
|
|
173
173
|
Without ``response_parameters``, the storage returns the whole
|
|
174
174
|
resource.
|
|
175
175
|
|
|
176
|
+
The whole resource holds the write-only and never returned
|
|
177
|
+
attributes, such as ``password``, in the form the storage keeps them,
|
|
178
|
+
a hash for instance. The server never returns them to the client
|
|
179
|
+
(:rfc:`RFC 7643 §2.2 <7643#section-2.2>`). It needs them to keep a
|
|
180
|
+
value that a PUT leaves out (:rfc:`RFC 7644 §3.5.1
|
|
181
|
+
<7644#section-3.5.1>`), and to clear one that a PATCH removes
|
|
182
|
+
(:rfc:`RFC 7644 §3.5.2.2 <7644#section-3.5.2.2>`).
|
|
183
|
+
|
|
176
184
|
A ``get`` method without ``response_parameters`` is deprecated, and
|
|
177
185
|
raises a :class:`DeprecationWarning`. The server then does not pass
|
|
178
186
|
the parameters. scim2-server 0.9 will require it.
|
|
@@ -252,6 +260,12 @@ class ScimStorage(ABC):
|
|
|
252
260
|
request to the stored resource first, so ``resource`` is the whole new
|
|
253
261
|
state of the resource.
|
|
254
262
|
|
|
263
|
+
A write-only or never returned value that :meth:`get` returned comes
|
|
264
|
+
back unchanged
|
|
265
|
+
when the request does not change it. The storage keeps it as it is,
|
|
266
|
+
and does not hash it again. It clears the value when it comes back as
|
|
267
|
+
:data:`None`.
|
|
268
|
+
|
|
255
269
|
:param expected_version: The version the stored resource must still
|
|
256
270
|
have, when given.
|
|
257
271
|
:raises ~scim2_models.NotFoundException: When the resource does not exist.
|
|
@@ -180,6 +180,16 @@ class ScimStorageContract:
|
|
|
180
180
|
empty.
|
|
181
181
|
"""
|
|
182
182
|
|
|
183
|
+
stores_password: bool = True
|
|
184
|
+
"""Whether the storage stores the ``password`` of the users.
|
|
185
|
+
|
|
186
|
+
Set it to :data:`False` only for a storage that does not keep the
|
|
187
|
+
password at all. The tests of the write-only and never returned
|
|
188
|
+
attributes are then skipped. A storage that keeps a hash of the password
|
|
189
|
+
stores it: its :meth:`~scim2_server.storage.ScimStorage.get` returns the
|
|
190
|
+
hash.
|
|
191
|
+
"""
|
|
192
|
+
|
|
183
193
|
@pytest.fixture
|
|
184
194
|
def provider(self) -> ScimProvider:
|
|
185
195
|
"""Return the description of the service the storage serves."""
|
|
@@ -447,6 +457,62 @@ class ScimStorageContract:
|
|
|
447
457
|
|
|
448
458
|
assert storage.get(user_type, user.id).user_name == "bjensen"
|
|
449
459
|
|
|
460
|
+
def create_user_with_password(
|
|
461
|
+
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
462
|
+
) -> Any:
|
|
463
|
+
"""Create a user with a password, and read it back, as the server does before a PUT or a PATCH."""
|
|
464
|
+
self.require(self.stores_password, "the password")
|
|
465
|
+
user = storage.create(
|
|
466
|
+
user_type, user_model(user_name="bjensen", password="secret")
|
|
467
|
+
)
|
|
468
|
+
return storage.get(user_type, user.id)
|
|
469
|
+
|
|
470
|
+
def test_get_returns_the_write_only_values(
|
|
471
|
+
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
472
|
+
) -> None:
|
|
473
|
+
"""A whole resource holds its password, in the form the storage keeps it."""
|
|
474
|
+
user = self.create_user_with_password(storage, user_type, user_model)
|
|
475
|
+
|
|
476
|
+
assert user.password is not None
|
|
477
|
+
|
|
478
|
+
def test_update_keeps_the_write_only_values_read_back(
|
|
479
|
+
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
480
|
+
) -> None:
|
|
481
|
+
"""The password read back and given to update unchanged stays as it is.
|
|
482
|
+
|
|
483
|
+
It is what a PUT without password gives, per :rfc:`RFC 7644 §3.5.1
|
|
484
|
+
<7644#section-3.5.1>`.
|
|
485
|
+
"""
|
|
486
|
+
user = self.create_user_with_password(storage, user_type, user_model)
|
|
487
|
+
user.display_name = "Barbara"
|
|
488
|
+
|
|
489
|
+
storage.update(user_type, user)
|
|
490
|
+
|
|
491
|
+
assert storage.get(user_type, user.id).password == user.password
|
|
492
|
+
|
|
493
|
+
def test_update_clears_a_write_only_value(
|
|
494
|
+
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
495
|
+
) -> None:
|
|
496
|
+
"""A PATCH removing the password clears it."""
|
|
497
|
+
user = self.create_user_with_password(storage, user_type, user_model)
|
|
498
|
+
user.password = None
|
|
499
|
+
|
|
500
|
+
storage.update(user_type, user)
|
|
501
|
+
|
|
502
|
+
assert storage.get(user_type, user.id).password is None
|
|
503
|
+
|
|
504
|
+
def test_update_changes_a_write_only_value(
|
|
505
|
+
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
506
|
+
) -> None:
|
|
507
|
+
"""A new password replaces the stored one."""
|
|
508
|
+
user = self.create_user_with_password(storage, user_type, user_model)
|
|
509
|
+
former = user.password
|
|
510
|
+
user.password = "other"
|
|
511
|
+
|
|
512
|
+
storage.update(user_type, user)
|
|
513
|
+
|
|
514
|
+
assert storage.get(user_type, user.id).password not in (None, former)
|
|
515
|
+
|
|
450
516
|
def test_update_an_unknown_resource(
|
|
451
517
|
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
452
518
|
) -> None:
|
|
@@ -1028,6 +1094,109 @@ class ScimStorageContract:
|
|
|
1028
1094
|
|
|
1029
1095
|
assert sorted(self.ids(pages)) == sorted([users[0].id, users[1].id, group.id])
|
|
1030
1096
|
|
|
1097
|
+
def test_cursor_pages_back_at_the_root(
|
|
1098
|
+
self,
|
|
1099
|
+
storage: Any,
|
|
1100
|
+
user_type: ResourceType,
|
|
1101
|
+
group_type: ResourceType,
|
|
1102
|
+
user_model: Any,
|
|
1103
|
+
group_model: Any,
|
|
1104
|
+
) -> None:
|
|
1105
|
+
"""Following the previous cursors at the root returns the same pages, back to the first."""
|
|
1106
|
+
self.require(storage.supports_cursors, "cursor pagination")
|
|
1107
|
+
self.require(self.supports_root_search, "searching at the root")
|
|
1108
|
+
users = self.create_users(storage, user_type, user_model, "alice", "bob")
|
|
1109
|
+
self.create_group(storage, group_type, group_model, users[0])
|
|
1110
|
+
resource_types = [user_type, group_type]
|
|
1111
|
+
search_request = self.search_request(
|
|
1112
|
+
[user_model, group_model], cursor="", count=1
|
|
1113
|
+
)
|
|
1114
|
+
forward = self.walk(storage, resource_types, search_request)
|
|
1115
|
+
|
|
1116
|
+
backward = self.walk_back(storage, resource_types, search_request, forward[-1])
|
|
1117
|
+
|
|
1118
|
+
assert [[r.id for r in page.resources] for page in reversed(backward)] == [
|
|
1119
|
+
[r.id for r in page.resources] for page in forward[:-1]
|
|
1120
|
+
]
|
|
1121
|
+
assert backward[-1].previous is None
|
|
1122
|
+
|
|
1123
|
+
def test_cursor_pages_back_in_descending_order_with_missing_values(
|
|
1124
|
+
self,
|
|
1125
|
+
storage: Any,
|
|
1126
|
+
provider: ScimProvider,
|
|
1127
|
+
user_type: ResourceType,
|
|
1128
|
+
user_model: Any,
|
|
1129
|
+
) -> None:
|
|
1130
|
+
"""Following the previous cursors of a descending sort returns the same pages, with the resources without value first."""
|
|
1131
|
+
self.require(storage.supports_cursors, "cursor pagination")
|
|
1132
|
+
self.require(self.announces(provider, "sort"), "sorting")
|
|
1133
|
+
self.require("nick_name" in user_model.model_fields, "nickName")
|
|
1134
|
+
for user_name, nick_name in [
|
|
1135
|
+
("alice", "a"),
|
|
1136
|
+
("bob", None),
|
|
1137
|
+
("carol", "c"),
|
|
1138
|
+
("dave", "b"),
|
|
1139
|
+
("erin", None),
|
|
1140
|
+
]:
|
|
1141
|
+
storage.create(
|
|
1142
|
+
user_type, user_model(user_name=user_name, nick_name=nick_name)
|
|
1143
|
+
)
|
|
1144
|
+
|
|
1145
|
+
search_request = self.search_request(
|
|
1146
|
+
[user_model],
|
|
1147
|
+
cursor="",
|
|
1148
|
+
count=2,
|
|
1149
|
+
sort_by="nickName",
|
|
1150
|
+
sort_order="descending",
|
|
1151
|
+
)
|
|
1152
|
+
forward = self.walk(storage, [user_type], search_request)
|
|
1153
|
+
backward = self.walk_back(storage, [user_type], search_request, forward[-1])
|
|
1154
|
+
|
|
1155
|
+
names = [r.user_name for page in forward for r in page.resources]
|
|
1156
|
+
assert sorted(names[:2]) == ["bob", "erin"]
|
|
1157
|
+
assert names[2:] == ["carol", "dave", "alice"]
|
|
1158
|
+
assert [[r.id for r in page.resources] for page in reversed(backward)] == [
|
|
1159
|
+
[r.id for r in page.resources] for page in forward[:-1]
|
|
1160
|
+
]
|
|
1161
|
+
assert backward[-1].previous is None
|
|
1162
|
+
|
|
1163
|
+
def test_cursor_pages_by_date(
|
|
1164
|
+
self,
|
|
1165
|
+
storage: Any,
|
|
1166
|
+
provider: ScimProvider,
|
|
1167
|
+
user_type: ResourceType,
|
|
1168
|
+
user_model: Any,
|
|
1169
|
+
) -> None:
|
|
1170
|
+
"""A cursor pages a search sorted by date, in both directions.
|
|
1171
|
+
|
|
1172
|
+
Resources modified at the same time may come in any order.
|
|
1173
|
+
"""
|
|
1174
|
+
self.require(storage.supports_cursors, "cursor pagination")
|
|
1175
|
+
self.require(self.announces(provider, "sort"), "sorting")
|
|
1176
|
+
self.require(self.stores_last_modified, "meta.lastModified")
|
|
1177
|
+
created = self.create_users(
|
|
1178
|
+
storage, user_type, user_model, "alice", "bob", "carol", "dave", "erin"
|
|
1179
|
+
)
|
|
1180
|
+
search_request = self.search_request(
|
|
1181
|
+
[user_model], cursor="", count=2, sort_by="meta.lastModified"
|
|
1182
|
+
)
|
|
1183
|
+
first = self.search_or_skip(storage, [user_type], search_request)
|
|
1184
|
+
forward = [first]
|
|
1185
|
+
while forward[-1].next is not None:
|
|
1186
|
+
forward.append(
|
|
1187
|
+
self.search(storage, [user_type], search_request, forward[-1].next)
|
|
1188
|
+
)
|
|
1189
|
+
|
|
1190
|
+
backward = self.walk_back(storage, [user_type], search_request, forward[-1])
|
|
1191
|
+
|
|
1192
|
+
dates = [r.meta.last_modified for page in forward for r in page.resources]
|
|
1193
|
+
assert sorted(self.ids(forward)) == sorted(user.id for user in created)
|
|
1194
|
+
assert dates == sorted(dates)
|
|
1195
|
+
assert [[r.id for r in page.resources] for page in reversed(backward)] == [
|
|
1196
|
+
[r.id for r in page.resources] for page in forward[:-1]
|
|
1197
|
+
]
|
|
1198
|
+
assert backward[-1].previous is None
|
|
1199
|
+
|
|
1031
1200
|
def test_operation(
|
|
1032
1201
|
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
1033
1202
|
) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scim2_server-0.8.7 → scim2_server-0.8.9}/scim2_server/resources/default-resource-types.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|