-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow admin login when using demo auth type
- Loading branch information
Showing
8 changed files
with
106 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { IAuthType } from '../server-impl'; | ||
import dbInit, { ITestDb } from '../../test/e2e/helpers/database-init'; | ||
import { IUnleashStores } from '../types'; | ||
import { setupAppWithCustomAuth } from '../../test/e2e/helpers/test-helper'; | ||
|
||
let db: ITestDb; | ||
let stores: IUnleashStores; | ||
|
||
beforeAll(async () => { | ||
db = await dbInit('demo_auth_serial'); | ||
stores = db.stores; | ||
}); | ||
|
||
afterAll(async () => { | ||
await db?.destroy(); | ||
}); | ||
|
||
const getApp = (adminLoginEnabled: boolean) => | ||
setupAppWithCustomAuth(stores, () => {}, { | ||
authentication: { | ||
authDemoAllowAdminLogin: adminLoginEnabled, | ||
type: IAuthType.DEMO, | ||
createAdminUser: true, | ||
}, | ||
}); | ||
|
||
test('should create regular user with flag enabled', async () => { | ||
const app = await getApp(true); | ||
return app.request | ||
.post(`/auth/demo/login`) | ||
.send({ email: '[email protected]' }) | ||
.expect(200) | ||
.expect((res) => { | ||
expect(res.body.email).toBe('[email protected]'); | ||
expect(res.body.id).not.toBe(1); | ||
}); | ||
}); | ||
|
||
test('should return 403 for admin user if flag disabled', async () => { | ||
const app = await getApp(false); | ||
return app.request | ||
.post(`/auth/demo/login`) | ||
.send({ email: 'admin' }) | ||
.expect(403); | ||
}); | ||
|
||
test('should allow login with admin user if flag enabled', async () => { | ||
const app = await getApp(true); | ||
return app.request | ||
.post(`/auth/demo/login`) | ||
.send({ email: 'admin' }) | ||
.expect(200) | ||
.expect((res) => { | ||
expect(res.body.id).toBe(1); | ||
expect(res.body.username).toBe('admin'); | ||
}); | ||
}); |
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