Skip to content

Commit

Permalink
providers/scim: fix missing schemas attribute for User and Group (#7477)
Browse files Browse the repository at this point in the history
* providers/scim: fix missing schemas attribute for User and Group

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* make things actually work

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu authored Nov 16, 2023
1 parent 6a8eae6 commit 51d3511
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
4 changes: 3 additions & 1 deletion authentik/providers/scim/clients/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def delete(self, obj: Group):

def to_scim(self, obj: Group) -> SCIMGroupSchema:
"""Convert authentik user into SCIM"""
raw_scim_group = {}
raw_scim_group = {
"schemas": ("urn:ietf:params:scim:schemas:core:2.0:Group",),
}
for mapping in (
self.provider.property_mappings_group.all().order_by("name").select_subclasses()
):
Expand Down
2 changes: 2 additions & 0 deletions authentik/providers/scim/clients/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
class User(BaseUser):
"""Modified User schema with added externalId field"""

schemas: tuple[str] = ("urn:ietf:params:scim:schemas:core:2.0:User",)
externalId: Optional[str] = None


class Group(BaseGroup):
"""Modified Group schema with added externalId field"""

schemas: tuple[str] = ("urn:ietf:params:scim:schemas:core:2.0:Group",)
externalId: Optional[str] = None


Expand Down
4 changes: 3 additions & 1 deletion authentik/providers/scim/clients/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def delete(self, obj: User):

def to_scim(self, obj: User) -> SCIMUserSchema:
"""Convert authentik user into SCIM"""
raw_scim_user = {}
raw_scim_user = {
"schemas": ("urn:ietf:params:scim:schemas:core:2.0:User",),
}
for mapping in self.provider.property_mappings.all().order_by("name").select_subclasses():
if not isinstance(mapping, SCIMMapping):
continue
Expand Down
18 changes: 15 additions & 3 deletions authentik/providers/scim/tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def test_group_create(self, mock: Mocker):
self.assertEqual(mock.request_history[1].method, "POST")
self.assertJSONEqual(
mock.request_history[1].body,
{"externalId": str(group.pk), "displayName": group.name},
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
"externalId": str(group.pk),
"displayName": group.name,
},
)

@Mocker()
Expand Down Expand Up @@ -96,7 +100,11 @@ def test_group_create_update(self, mock: Mocker):
validate(body, loads(schema.read()))
self.assertEqual(
body,
{"externalId": str(group.pk), "displayName": group.name},
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
"externalId": str(group.pk),
"displayName": group.name,
},
)
group.save()
self.assertEqual(mock.call_count, 4)
Expand Down Expand Up @@ -129,7 +137,11 @@ def test_group_create_delete(self, mock: Mocker):
self.assertEqual(mock.request_history[1].method, "POST")
self.assertJSONEqual(
mock.request_history[1].body,
{"externalId": str(group.pk), "displayName": group.name},
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
"externalId": str(group.pk),
"displayName": group.name,
},
)
group.delete()
self.assertEqual(mock.call_count, 4)
Expand Down
20 changes: 15 additions & 5 deletions authentik/providers/scim/tests/test_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def test_member_add(self):
self.assertJSONEqual(
mocker.request_history[3].body,
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"emails": [],
"active": True,
"externalId": user.uid,
Expand All @@ -99,7 +100,11 @@ def test_member_add(self):
)
self.assertJSONEqual(
mocker.request_history[5].body,
{"externalId": str(group.pk), "displayName": group.name},
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
"externalId": str(group.pk),
"displayName": group.name,
},
)

with Mocker() as mocker:
Expand All @@ -118,14 +123,14 @@ def test_member_add(self):
self.assertJSONEqual(
mocker.request_history[1].body,
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
"Operations": [
{
"op": "add",
"path": "members",
"value": [{"value": user_scim_id}],
}
],
"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
},
)

Expand Down Expand Up @@ -174,6 +179,7 @@ def test_member_remove(self):
self.assertJSONEqual(
mocker.request_history[3].body,
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"active": True,
"displayName": "",
"emails": [],
Expand All @@ -184,7 +190,11 @@ def test_member_remove(self):
)
self.assertJSONEqual(
mocker.request_history[5].body,
{"externalId": str(group.pk), "displayName": group.name},
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
"externalId": str(group.pk),
"displayName": group.name,
},
)

with Mocker() as mocker:
Expand All @@ -203,14 +213,14 @@ def test_member_remove(self):
self.assertJSONEqual(
mocker.request_history[1].body,
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
"Operations": [
{
"op": "add",
"path": "members",
"value": [{"value": user_scim_id}],
}
],
"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
},
)

Expand All @@ -230,13 +240,13 @@ def test_member_remove(self):
self.assertJSONEqual(
mocker.request_history[1].body,
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
"Operations": [
{
"op": "remove",
"path": "members",
"value": [{"value": user_scim_id}],
}
],
"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
},
)
4 changes: 4 additions & 0 deletions authentik/providers/scim/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_user_create(self, mock: Mocker):
self.assertJSONEqual(
mock.request_history[1].body,
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"active": True,
"emails": [
{
Expand Down Expand Up @@ -121,6 +122,7 @@ def test_user_create_update(self, mock: Mocker):
self.assertEqual(
body,
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"active": True,
"emails": [
{
Expand Down Expand Up @@ -173,6 +175,7 @@ def test_user_create_delete(self, mock: Mocker):
self.assertJSONEqual(
mock.request_history[1].body,
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"active": True,
"emails": [
{
Expand Down Expand Up @@ -240,6 +243,7 @@ def test_sync_task(self, mock: Mocker):
self.assertJSONEqual(
mock.request_history[1].body,
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"active": True,
"emails": [
{
Expand Down

0 comments on commit 51d3511

Please sign in to comment.