Skip to content
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

[backend] Allow passwords with digits only for initial admin (#6382) #6489

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions opencti-platform/opencti-graphql/src/domain/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@
const patch = {
account_status: ACCOUNT_STATUS_ACTIVE,
user_email: email,
password: bcrypt.hashSync(password),
password: bcrypt.hashSync(password.toString()),
api_token: tokenValue,
external: true,
};
Expand All @@ -1445,7 +1445,7 @@
lastname: 'OpenCTI',
description: 'Principal admin account',
api_token: tokenValue,
password,
password: password.toString(),

Check warning on line 1448 in opencti-platform/opencti-graphql/src/domain/user.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/domain/user.js#L1448

Added line #L1448 was not covered by tests
user_confidence_level: {
max_confidence: 100,
overrides: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { initializeAdminUser } from '../../../src/config/providers';
import conf from '../../../src/config/conf';
import { SYSTEM_USER } from '../../../src/utils/access';
import { OPENCTI_ADMIN_UUID } from '../../../src/schema/general';
import { findById } from '../../../src/domain/user';

describe('initializeAdminUser configurations verifications', () => {
let initialEmail: string;
let initialPassword: string;
let initialToken: string;

beforeAll(() => {
initialEmail = conf.get('app:admin:email');
initialPassword = conf.get('app:admin:password');
initialToken = conf.get('app:admin:token');
});

afterAll(() => {
// reset to value that were set before running this test.
conf.set('app:admin:email', initialEmail);
conf.set('app:admin:password', initialPassword);
conf.set('app:admin:token', initialToken);
initializeAdminUser({});
});

it('should well configured admin be initialized', async () => {
// GIVEN configuration
conf.set('app:admin:email', 'cecilia.payne@filigran.io');
conf.set('app:admin:password', 'IDiscoveredUniverseMatter');
conf.set('app:admin:token', 'aaaaaaaa-1111-2222-3333-999999999999');

await initializeAdminUser({});

const existingAdmin = await findById({}, SYSTEM_USER, OPENCTI_ADMIN_UUID);
expect(existingAdmin.user_email).toBe('cecilia.payne@filigran.io');
});

it('should password env with digit only works', async () => {
// GIVEN configuration
conf.set('app:admin:email', initialEmail);
conf.set('app:admin:password', 1111); // ENV var with digit only is interpreted as number by node.
conf.set('app:admin:token', initialToken);

await initializeAdminUser({});
// expect no exception, exception are failing tests so nothing to check more.
});
});