-
-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://linear.app/unleash/issue/2-2093/api-should-not-allow-manual-management-of-scim-managed-users-in Introduces a SCIM guard for SCIM users. SCIM users should be managed exclusively by the SCIM client, not Unleash. We decided to be restrictive for now, completely covering all of the write methods, but may fine-tune some of this at a later stage. Will eventually be followed up by a UI-centric PR.
- Loading branch information
Showing
7 changed files
with
179 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { | ||
type IUnleashTest, | ||
setupAppWithCustomConfig, | ||
} from '../../helpers/test-helper'; | ||
import dbInit, { type ITestDb } from '../../helpers/database-init'; | ||
import getLogger from '../../../fixtures/no-logger'; | ||
import type { IUnleashStores } from '../../../../lib/types'; | ||
|
||
let stores: IUnleashStores; | ||
let db: ITestDb; | ||
let app: IUnleashTest; | ||
|
||
let scimUserId: number; | ||
let regularUserId: number; | ||
|
||
const scimUser = { | ||
email: '[email protected]', | ||
name: 'SCIM User', | ||
scim_id: 'some-random-scim-id', | ||
}; | ||
|
||
const regularUser = { | ||
email: '[email protected]', | ||
name: 'Regular User', | ||
}; | ||
|
||
const scimGuardErrorMessage = | ||
'This user is managed by your SCIM provider and cannot be changed manually'; | ||
|
||
beforeAll(async () => { | ||
db = await dbInit('user_admin_scim', getLogger); | ||
stores = db.stores; | ||
app = await setupAppWithCustomConfig(stores, { | ||
enterpriseVersion: 'enterprise', | ||
experimental: { | ||
flags: { | ||
strictSchemaValidation: true, | ||
scimApi: true, | ||
}, | ||
}, | ||
}); | ||
|
||
await stores.settingStore.insert('scim', { | ||
enabled: true, | ||
}); | ||
|
||
scimUserId = ( | ||
await db.rawDatabase('users').insert(scimUser).returning('id') | ||
)[0].id; | ||
|
||
regularUserId = ( | ||
await db.rawDatabase('users').insert(regularUser).returning('id') | ||
)[0].id; | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.destroy(); | ||
await db.destroy(); | ||
}); | ||
|
||
test('fetching a SCIM user should include scimId', async () => { | ||
const { body } = await app.request | ||
.get(`/api/admin/user-admin/${scimUserId}`) | ||
.expect(200); | ||
|
||
expect(body.email).toBe(scimUser.email); | ||
expect(body.scimId).toBe('some-random-scim-id'); | ||
}); | ||
|
||
test('fetching a regular user should not include scimId', async () => { | ||
const { body } = await app.request | ||
.get(`/api/admin/user-admin/${regularUserId}`) | ||
.expect(200); | ||
|
||
expect(body.email).toBe(regularUser.email); | ||
expect(body.scimId).toBeFalsy(); | ||
}); | ||
|
||
test('should prevent editing a SCIM user', async () => { | ||
const { body } = await app.request | ||
.put(`/api/admin/user-admin/${scimUserId}`) | ||
.send({ | ||
name: 'New name', | ||
}) | ||
.expect(403); | ||
|
||
expect(body.details[0].message).toBe(scimGuardErrorMessage); | ||
}); | ||
|
||
test('should prevent deleting a SCIM user', async () => { | ||
const { body } = await app.request | ||
.delete(`/api/admin/user-admin/${scimUserId}`) | ||
.expect(403); | ||
|
||
expect(body.details[0].message).toBe(scimGuardErrorMessage); | ||
}); | ||
|
||
test('should prevent changing password for a SCIM user', async () => { | ||
const { body } = await app.request | ||
.post(`/api/admin/user-admin/${scimUserId}/change-password`) | ||
.send({ | ||
password: 'new-password', | ||
}) | ||
.expect(403); | ||
|
||
expect(body.details[0].message).toBe(scimGuardErrorMessage); | ||
}); | ||
|
||
test('should prevent resetting password for a SCIM user', async () => { | ||
const { body } = await app.request | ||
.post(`/api/admin/user-admin/reset-password`) | ||
.send({ id: scimUser.email }) | ||
.expect(403); | ||
|
||
expect(body.details[0].message).toBe(scimGuardErrorMessage); | ||
}); |