mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
fix: create admin users if enabled and zero users already
This commit is contained in:
parent
ce60d7f31b
commit
41574e3938
@ -114,9 +114,9 @@ class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async initAdminUser(): Promise<void> {
|
async initAdminUser(): Promise<void> {
|
||||||
const hasAdminUser = await this.store.hasUser({ username: 'admin' });
|
const userCount = await this.store.count();
|
||||||
|
|
||||||
if (!hasAdminUser) {
|
if (userCount === 0) {
|
||||||
// create default admin user
|
// create default admin user
|
||||||
try {
|
try {
|
||||||
const pwd = 'unleash4all';
|
const pwd = 'unleash4all';
|
||||||
|
@ -58,6 +58,21 @@ test('should create initial admin user', async () => {
|
|||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not init default user if we already have users', async () => {
|
||||||
|
await userService.createUser({
|
||||||
|
username: 'test',
|
||||||
|
password: 'A very strange P4ssw0rd_',
|
||||||
|
rootRole: adminRole.id,
|
||||||
|
});
|
||||||
|
await userService.initAdminUser();
|
||||||
|
const users = await userService.getAll();
|
||||||
|
expect(users).toHaveLength(1);
|
||||||
|
expect(users[0].username).toBe('test');
|
||||||
|
await expect(async () =>
|
||||||
|
userService.loginUser('admin', 'unleash4all'),
|
||||||
|
).rejects.toThrow(Error);
|
||||||
|
});
|
||||||
|
|
||||||
test('should not be allowed to create existing user', async () => {
|
test('should not be allowed to create existing user', async () => {
|
||||||
await userStore.insert({ username: 'test', name: 'Hans Mola' });
|
await userStore.insert({ username: 'test', name: 'Hans Mola' });
|
||||||
await expect(async () =>
|
await expect(async () =>
|
||||||
|
Loading…
Reference in New Issue
Block a user