-
-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/allow admin login using demo auth #6808
Merged
thomasheartman
merged 5 commits into
Unleash:main
from
00Chaotic:feat/allow_admin_login_using_demo_auth
Apr 23, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f9016fe
feat: allow admin login when using demo auth type
00Chaotic 4702019
patch: improve naming for demo auth admin login flag
00Chaotic 175d2f5
patch: further renaming as auto-replace did not catch all occurrences
00Chaotic 5e2b432
patch: update ordering of config test snapshot
00Chaotic f9a44f3
Update src/lib/create-config.test.ts
thomasheartman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,73 @@ | ||
import dbInit from '../../test/e2e/helpers/database-init'; | ||
import { IAuthType } from '../server-impl'; | ||
import { setupAppWithCustomAuth } from '../../test/e2e/helpers/test-helper'; | ||
import type { ITestDb } from '../../test/e2e/helpers/database-init'; | ||
import type { IUnleashStores } from '../types'; | ||
|
||
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: { | ||
demoAllowAdminLogin: adminLoginEnabled, | ||
type: IAuthType.DEMO, | ||
createAdminUser: true, | ||
}, | ||
}); | ||
|
||
test('the demoAllowAdminLogin flag should not affect regular user login/creation', 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('if the demoAllowAdminLogin flag is disabled, using `admin` should have the same result as any other invalid email', async () => { | ||
const app = await getApp(false); | ||
|
||
const nonAdminUsername = 'not-an-email'; | ||
const adminUsername = 'admin'; | ||
|
||
const nonAdminUser = await app.request | ||
.post(`/auth/demo/login`) | ||
.send({ email: nonAdminUsername }); | ||
|
||
const adminUser = await app.request | ||
.post(`/auth/demo/login`) | ||
.send({ email: adminUsername }); | ||
|
||
expect(nonAdminUser.status).toBe(adminUser.status); | ||
|
||
for (const user of [nonAdminUser, adminUser]) { | ||
expect(user.body).toMatchObject({ | ||
error: expect.stringMatching(/^Could not sign in with /), | ||
}); | ||
} | ||
}); | ||
|
||
test('should allow you to login as admin if the demoAllowAdminLogin 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ New issue: Complex Method
demoAuthentication has a cyclomatic complexity of 12, threshold = 9
Suppress