Return _id as string in saveLog.
MODIFY
src/storage/mongodb/LoggingStorage.ts
src/storage/mongodb/LoggingStorage.ts
@@ -6,7 +6,6 @@ import { DataResult } from '../../types/DataResult';
import DatabaseUtils from './DatabaseUtils';
import DbParams from '../../types/database/DbParams';
import { Log } from '../../types/Log';
-import { ObjectID } from 'mongodb';
import Utils from '../../utils/Utils';
import cfenv from 'cfenv';
import cluster from 'cluster';
@@ -59,7 +58,7 @@ export default class LoggingStorage {
return result.result;
}
- public static async saveLog(tenantID: string, logToSave: Log): Promise<ObjectID> {
+ public static async saveLog(tenantID: string, logToSave: Log): Promise<string> {
// Check Tenant
await DatabaseUtils.checkTenant(tenantID);
// Set
@@ -81,7 +80,7 @@ export default class LoggingStorage {
// Insert
if (global.database) {
await global.database.getCollection<Log>(tenantID, 'logs').insertOne(logMDB);
- return logMDB._id;
+ return logMDB._id.toHexString();
}
}

MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -14,7 +14,6 @@ import LoggingConfiguration from '../types/configuration/LoggingConfiguration';
import LoggingStorage from '../storage/mongodb/LoggingStorage';
import { OCPIResult } from '../types/ocpi/OCPIResult';
import { OCPPStatus } from '../types/ocpp/OCPPClient';
-import { ObjectID } from 'mongodb';
import { ServerAction } from '../types/Server';
import User from '../types/User';
import UserToken from '../types/UserToken';
@@ -72,53 +71,53 @@ export default class Logging {
}
// Log Debug
- public static async logDebug(log: Log): Promise<ObjectID> {
+ public static async logDebug(log: Log): Promise<string> {
log.level = LogLevel.DEBUG;
// eslint-disable-next-line @typescript-eslint/no-floating-promises
return Logging._log(log);
}
// Log Security Debug
- public static async logSecurityDebug(log: Log): Promise<ObjectID> {
+ public static async logSecurityDebug(log: Log): Promise<string> {
log.type = LogType.SECURITY;
return Logging.logDebug(log);
}
// Log Info
- public static async logInfo(log: Log): Promise<ObjectID> {
+ public static async logInfo(log: Log): Promise<string> {
log.level = LogLevel.INFO;
// eslint-disable-next-line @typescript-eslint/no-floating-promises
return Logging._log(log);
}
// Log Security Info
- public static async logSecurityInfo(log: Log): Promise<ObjectID> {
+ public static async logSecurityInfo(log: Log): Promise<string> {
log.type = LogType.SECURITY;
return Logging.logInfo(log);
}
// Log Warning
- public static async logWarning(log: Log): Promise<ObjectID> {
+ public static async logWarning(log: Log): Promise<string> {
log.level = LogLevel.WARNING;
// eslint-disable-next-line @typescript-eslint/no-floating-promises
return Logging._log(log);
}
// Log Security Warning
- public static async logSecurityWarning(log: Log): Promise<ObjectID> {
+ public static async logSecurityWarning(log: Log): Promise<string> {
log.type = LogType.SECURITY;
return Logging.logWarning(log);
}
// Log Error
- public static async logError(log: Log): Promise<ObjectID> {
+ public static async logError(log: Log): Promise<string> {
log.level = LogLevel.ERROR;
// eslint-disable-next-line @typescript-eslint/no-floating-promises
return Logging._log(log);
}
// Log Security Error
- public static async logSecurityError(log: Log): Promise<ObjectID> {
+ public static async logSecurityError(log: Log): Promise<string> {
log.type = LogType.SECURITY;
return Logging.logError(log);
}
@@ -584,7 +583,7 @@ export default class Logging {
}
// Log
- private static async _log(log: Log): Promise<ObjectID> {
+ private static async _log(log: Log): Promise<string> {
let moduleConfig = null;
const loggingConfig = Logging.getConfiguration();
// Default Log Level
@@ -703,15 +702,15 @@ export default class Logging {
if (!log.tenantID || log.tenantID === '') {
log.tenantID = Constants.DEFAULT_TENANT;
}
- // Log
- const logID = await LoggingStorage.saveLog(log.tenantID, log);
+
// Log in Cloud Foundry
if (Configuration.isCloudFoundry()) {
// Bind to express app
CFLog.logMessage(Logging.getCFLogLevel(log.level), log.message);
}
- return logID;
+ // Log
+ return LoggingStorage.saveLog(log.tenantID, log);
}
private static anonymizeSensitiveData(message: any): any {

MODIFY
test/api/SecurityTest.ts
test/api/SecurityTest.ts
@@ -7,7 +7,6 @@ import Constants from '../../src/utils/Constants';
import ContextDefinition from './context/ContextDefinition';
import Logging from '../../src/utils/Logging';
import MongoDBStorage from '../../src/storage/mongodb/MongoDBStorage';
-import { ObjectID } from 'mongodb';
import { ServerAction } from '../../src/types/Server';
import Tenant from '../types/Tenant';
import TestConstants from './client/utils/TestConstants';
@@ -84,7 +83,7 @@ describe('Security tests', function() {
describe('Success cases (tenant utall)', () => {
it('Check that sensitive data string (containing "=") is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -98,7 +97,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data string (containing ":") is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -112,7 +111,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data string (containing ",") is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -126,7 +125,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data string (containing ";") is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -140,7 +139,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data string (containing spaces and =) is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -154,7 +153,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data string (containing spaces and :) is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -168,7 +167,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data string (containing spaces and ,) is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -182,7 +181,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data string (containing spaces and ;) is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -196,7 +195,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that client_id field is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -210,7 +209,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that client_secret field is anonymized', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -224,7 +223,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that client_id and client_secret are anonymized in object', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -241,7 +240,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data is anonymized in object with string fields', async () => {
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -271,7 +270,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data is anonymized in object with query string fields', async () => { // Passes because query strings are treated correctly in object fields
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,
@@ -289,7 +288,7 @@ describe('Security tests', function() {
checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages));
});
it('Check that sensitive data is anonymized in array with strings', async () => { // Will fail
- const logId:ObjectID = await Logging.logDebug({
+ const logId:string = await Logging.logDebug({
source: 'test',
tenantID: testData.credentials.tenantId,
action: ServerAction.HTTP_REQUEST,

Return _id as string in saveLog.