1
0
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:
Ivar Conradi Østhus 2021-10-12 21:27:06 +02:00
parent ce60d7f31b
commit 41574e3938
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09
2 changed files with 17 additions and 2 deletions

View File

@ -114,9 +114,9 @@ class UserService {
}
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
try {
const pwd = 'unleash4all';

View File

@ -58,6 +58,21 @@ test('should create initial admin user', async () => {
).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 () => {
await userStore.insert({ username: 'test', name: 'Hans Mola' });
await expect(async () =>