Skip to content

Commit

Permalink
fix: use the correct env vars for initial admin account (#8095)
Browse files Browse the repository at this point in the history
#7795 mistakenly changed the
initial admin account environment variables to be:

 - `INITIAL_ADMIN_USER_USERNAME`
 - `INITIAL_ADMIN_USER_PASSWORD`

Instead of the previous:

 - `UNLEASH_DEFAULT_ADMIN_USERNAME`
 - `UNLEASH_DEFAULT_ADMIN_PASSWORD`

See:
https://github.com/Unleash/unleash/pull/7795/files?diff=unified&w=0#diff-a38cc7ae9f963264333b6535498970a33e046dba50a6af554f438343a6edd2ddR319-R334

This PR reverts them back to the correct environment variable names and
adds a test to prevent something similar from happening in the future.
  • Loading branch information
nunogois authored Sep 5, 2024
1 parent 4b1de56 commit 3953801
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/create-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ const defaultVersionOption: IVersionOption = {
};

const parseEnvVarInitialAdminUser = (): UsernameAdminUser | undefined => {
const username = process.env.INITIAL_ADMIN_USER_USERNAME;
const password = process.env.INITIAL_ADMIN_USER_PASSWORD;
const username = process.env.UNLEASH_DEFAULT_ADMIN_USERNAME;
const password = process.env.UNLEASH_DEFAULT_ADMIN_PASSWORD;
return username && password ? { username, password } : undefined;
};

Expand Down
17 changes: 17 additions & 0 deletions src/lib/services/user-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ describe('Default admin initialization', () => {
'The combination of password and username you provided is invalid',
);
});

test('Should use the correct environment variables when initializing the default admin account', async () => {
jest.resetModules();

process.env.UNLEASH_DEFAULT_ADMIN_USERNAME = CUSTOM_ADMIN_USERNAME;
process.env.UNLEASH_DEFAULT_ADMIN_PASSWORD = CUSTOM_ADMIN_PASSWORD;

const createTestConfig =
require('../../test/config/test-config').createTestConfig;

const config = createTestConfig();

expect(config.authentication.initialAdminUser).toStrictEqual({
username: CUSTOM_ADMIN_USERNAME,
password: CUSTOM_ADMIN_PASSWORD,
});
});
});

test('Should be a valid password', async () => {
Expand Down

0 comments on commit 3953801

Please sign in to comment.