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

exui-2709-fortify-scan-issue #4233

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import { AcceptTermsService } from './services/acceptTerms/acceptTerms.service';
import { CaseShareService } from './services/case/share-case.service';
import { DefaultErrorHandler } from './services/errorHandler/defaultErrorHandler';
import { JurisdictionService } from './services/jurisdiction/jurisdiction.service';
import { CryptoWrapper } from './services/logger/cryptoWrapper';
import { LoggerService } from './services/logger/logger.service';
import { MonitoringService } from './services/logger/monitoring.service';
import { SharedModule } from './shared/shared.module';
Expand Down Expand Up @@ -122,7 +121,6 @@ export function launchDarklyClientIdFactory(
deps: [Store, ENVIRONMENT_CONFIG],
multi: true
},
CryptoWrapper,
MonitoringService,
LoggerService,
{
Expand Down
14 changes: 0 additions & 14 deletions src/app/services/logger/CryptoWrapper.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/app/services/logger/cryptoWrapper.ts

This file was deleted.

35 changes: 16 additions & 19 deletions src/app/services/logger/logger.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,92 +7,89 @@ describe('Logger service', () => {
const mockedNgxLogger = jasmine.createSpyObj('mockedNgxLogger', ['trace', 'debug', 'info',
'log', 'warn', 'error', 'fatal']);
const mockedSessionStorageService = jasmine.createSpyObj('mockedSessionStorageService', ['getItem']);
const mockedCryptoWrapper = jasmine.createSpyObj('mockedCryptoWrapper', ['encrypt', 'decrypt']);
const mockedConsoleObject = jasmine.createSpyObj('mockedConsoleObject', ['log', 'trace', 'debug', 'info', 'warn', 'error']);
const mockEnvironmentService = jasmine.createSpyObj('mockEnvironmentService', ['config$', 'getDeploymentEnv']);
const mockConfig = jasmine.createSpyObj('mockConfig', ['subscribe']);
mockEnvironmentService.config$ = mockConfig;

it('should be Truthy', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
expect(service).toBeTruthy();
});

it('should be able to call info', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
service.info('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
expect(mockedNgxLogger.info).toHaveBeenCalled();
});

it('should be able to call log', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
service.log('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
expect(mockedNgxLogger.log).toHaveBeenCalled();
});

it('should be able to call warn', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
service.warn('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
expect(mockedNgxLogger.warn).toHaveBeenCalled();
});

it('should be able to call error', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
service.error('message');
expect(mockedMonitoringService.logException).toHaveBeenCalled();
expect(mockedNgxLogger.error).toHaveBeenCalled();
});

it('should be able to call fatal', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
service.fatal('message');
expect(mockedMonitoringService.logException).toHaveBeenCalled();
expect(mockedNgxLogger.fatal).toHaveBeenCalled();
});

it('should be able to call debug', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
service.debug('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
});

it('should be able to call trace', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
service.trace('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
expect(mockedNgxLogger.trace).toHaveBeenCalled();
});

it('should be able to get a message', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
// slice off the last two characters of string to ensure no accidental discrepancies
const expectedMessage = `Message - message, Timestamp - ${Date.now()}`.slice(0, -2);
const returnedMessage = service.getMessage('message');
expect(returnedMessage).not.toBeNull();
expect(returnedMessage.slice(0, -2)).toBe(expectedMessage);
});

it('should be able to get a message with the user email encrypted', () => {
const userInfo = { id: '1', forename: 'Test', surname: 'User', email: 'testemail', active: true, roles: ['pui-case-manager'] };
it('should be able to get a message with the user id', () => {
const userInfo = { id: '1', forename: 'Test', surname: 'User', email: 'testemail', active: true, roles: ['pui-case-manager'], uid: '123' };
mockedSessionStorageService.getItem.and.returnValue(JSON.stringify(userInfo));
// Return dummy encrypted email address
mockedCryptoWrapper.encrypt.and.returnValue('[email protected]');
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
// slice off the last two characters of string to ensure no accidental discrepancies
const expectedMessage = `User - [email protected], Message - message, Timestamp - ${Date.now()}`.slice(0, -2);
const expectedMessage = `User - 123, Message - message, Timestamp - ${Date.now()}`.slice(0, -2);
const returnedMessage = service.getMessage('message');
expect(returnedMessage).not.toBeNull();
expect(returnedMessage.slice(0, -2)).toBe(expectedMessage);
Expand All @@ -103,18 +100,18 @@ describe('Logger service', () => {
mockEnvironmentService.getDeploymentEnv.and.returnValue(DeploymentEnvironmentEnum.PROD);
spyOn(console, 'info');
new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
expect(console.info).toHaveBeenCalledWith('Environment is prod.');
mockEnvironmentService.getDeploymentEnv.and.returnValue(DeploymentEnvironmentEnum.AAT);
new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
expect(console.info).toHaveBeenCalledWith('Environment is aat.');
});

describe('enableCookies()', () => {
it('should make a call to monitoringService', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
mockEnvironmentService);
service.enableCookies();
expect(mockedMonitoringService.enableCookies).toHaveBeenCalled();
});
Expand Down
8 changes: 3 additions & 5 deletions src/app/services/logger/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { NGXLogger } from 'ngx-logger';
import { environment as config } from '../../../environments/environment';
import { UserInfo } from '../../models/user-details.model';
import { SessionStorageService } from '../session-storage/session-storage.service';
import { CryptoWrapper } from './cryptoWrapper';
import { MonitoringService } from './monitoring.service';
import { EnvironmentService } from '../../shared/services/environment.service';

Expand All @@ -29,7 +28,6 @@ export class LoggerService implements ILoggerService {
constructor(private readonly monitoringService: MonitoringService,
private readonly ngxLogger: NGXLogger,
private readonly sessionStorageService: SessionStorageService,
private readonly cryptoWrapper: CryptoWrapper,
private readonly environmentService: EnvironmentService) {
this.COOKIE_KEYS = {
TOKEN: config.cookies.token,
Expand Down Expand Up @@ -100,9 +98,9 @@ export class LoggerService implements ILoggerService {
const userInfoStr = this.sessionStorageService.getItem('userDetails');
if (userInfoStr) {
const userInfo: UserInfo = JSON.parse(userInfoStr);
if (userInfo && userInfo.email) {
const userIdEncrypted = this.cryptoWrapper.encrypt(userInfo.email);
return `User - ${userIdEncrypted.toString()}, Message - ${message}, Timestamp - ${Date.now()}`;
if (userInfo?.uid) {
RiteshHMCTS marked this conversation as resolved.
Show resolved Hide resolved
const userId = userInfo.uid;
return `User - ${userId.toString()}, Message - ${message}, Timestamp - ${Date.now()}`;
}
}
return `Message - ${message}, Timestamp - ${Date.now()}`;
Expand Down