From 7f924fe04c66f12951c7d44bd94b153880489a48 Mon Sep 17 00:00:00 2001 From: fflorent Date: Tue, 14 Jan 2025 20:05:38 +0100 Subject: [PATCH] SCIM: Implement DELETE /Groups/{id} endpoint --- app/server/lib/scim/v2/ScimGroupController.ts | 17 ++++++++++ test/server/lib/Scim.ts | 34 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/app/server/lib/scim/v2/ScimGroupController.ts b/app/server/lib/scim/v2/ScimGroupController.ts index 4f31d8a00f..24f051ea7c 100644 --- a/app/server/lib/scim/v2/ScimGroupController.ts +++ b/app/server/lib/scim/v2/ScimGroupController.ts @@ -75,6 +75,20 @@ class ScimGroupController extends BaseController { return toSCIMMYGroup(group); }); } + + /** + * Deletes a group with the passed ID. + * + * @param resource The SCIMMY group resource performing the operation + * @param context The request context + * + */ + public async deleteGroup(resource: any, context: RequestContext) { + return this.runAndHandleErrors(context, async () => { + const id = this.getIdFromResource(resource); + await this.dbManager.deleteGroup(id); + }); + } } export const getScimGroupConfig = ( @@ -95,5 +109,8 @@ export const getScimGroupConfig = ( } return await controller.createGroup(data, context); }, + degress: async (resource: any, context: RequestContext) => { + return await controller.deleteGroup(resource, context); + } }; }; diff --git a/test/server/lib/Scim.ts b/test/server/lib/Scim.ts index b95d1b3a20..893db08910 100644 --- a/test/server/lib/Scim.ts +++ b/test/server/lib/Scim.ts @@ -1051,6 +1051,40 @@ describe('Scim', () => { }] }); }); + + describe('DELETE /Groups/{id}', function () { + it('should delete a group', async function () { + return withGroup(async (groupId) => { + const res = await axios.delete(scimUrl('/Groups/' + groupId), chimpy); + assert.equal(res.status, 204); + const refreshedGroup = await axios.get(scimUrl('/Groups/' + groupId), chimpy); + assert.equal(refreshedGroup.status, 404); + }); + }); + + it('should return 404 when the group is not found', async function () { + const res = await axios.delete(scimUrl('/Groups/1000'), chimpy); + assert.deepEqual(res.data, { + schemas: [ 'urn:ietf:params:scim:api:messages:2.0:Error' ], + status: '404', + detail: 'Group with id 1000 not found' + }); + assert.equal(res.status, 404); + }); + + it('should return 400 when the group id is malformed', async function () { + const res = await axios.delete(scimUrl('/Groups/not-an-id'), chimpy); + assert.deepEqual(res.data, { + schemas: [ 'urn:ietf:params:scim:api:messages:2.0:Error' ], + status: '400', + detail: 'Invalid passed group ID', + scimType: 'invalidValue' + }); + assert.equal(res.status, 400); + }); + + checkCommonErrors('delete', '/Groups/1'); + }); }); describe('POST /Bulk', function () {