Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
improve: do not allow to bulk remove identity providers (#7772)
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-mitra authored Mar 21, 2023
1 parent 3185442 commit 33dce73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const checkIdentityProvider = (): any => {
const checkOnlyIdentityProvider = () => {
return async (context: HookContext): Promise<HookContext> => {
if (!context.id) {
// If trying to delete multiple providers, do not check if only 1 identity provider exists
return context
// do not allow to remove identity providers in bulk
throw new MethodNotAllowed('Cannot remove multiple providers together')
}

const thisIdentityProvider = await (context.app.service('identity-provider') as any).Model.findByPk(context.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,18 @@ describe('identity-provider service', () => {
assert.equal((item as any).total, 0)
})

it('should remove identity providers by user id', async () => {
await app.service('identity-provider').remove(null, {
query: {
userId
}
})

const item = await app.service('identity-provider').find({
query: {
userId
it('should not be able to remove identity providers by user id', async () => {
assert.rejects(
() =>
app.service('identity-provider').remove(null, {
query: {
userId
}
}),
{
name: 'MethodNotAllowed'
}
})

assert.equal((item as any).total, 0)
)
})

it('should not be able to remove the only identity provider', async () => {
Expand All @@ -144,7 +142,5 @@ describe('identity-provider service', () => {
assert.rejects(() => app.service('identity-provider').remove(item.id), {
name: 'MethodNotAllowed'
})

assert.ok(true)
})
})

0 comments on commit 33dce73

Please sign in to comment.