Skip to content

Commit

Permalink
SCIM: Implement DELETE /Groups/{id} endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
fflorent committed Jan 17, 2025
1 parent 02ce475 commit 7f924fe
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/server/lib/scim/v2/ScimGroupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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);
}
};
};
34 changes: 34 additions & 0 deletions test/server/lib/Scim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 7f924fe

Please sign in to comment.