@contrail/flexplm 1.7.4-alpha.b869ea5 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -89,9 +89,9 @@ class FlexPLMConnect {
|
|
|
89
89
|
console.info('vibeEventsURL: ' + vibeEventsURL);
|
|
90
90
|
const logOptions = JSON.parse(JSON.stringify(xferOptions));
|
|
91
91
|
if (logOptions?.headers?.Authorization)
|
|
92
|
-
logOptions.headers.Authorization =
|
|
92
|
+
logOptions.headers.Authorization = logOptions?.headers?.Authorization.substring(0, 9);
|
|
93
93
|
if (csrf?.nonce_key)
|
|
94
|
-
logOptions.headers[csrf.nonce_key] = '***masked***';
|
|
94
|
+
logOptions.headers[csrf.nonce_key] = csrf.nonce ? `***masked(length:${csrf.nonce.length})***` : '***masked(empty)***';
|
|
95
95
|
console.info('csrfOptions: ' + JSON.stringify(logOptions));
|
|
96
96
|
console.info('Making call to xfer data to FlexPLM');
|
|
97
97
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const flexplm_connect_1 = require("./flexplm-connect");
|
|
4
|
+
const app_framework_1 = require("@contrail/app-framework");
|
|
4
5
|
const mockJsonData = { items: [{ id: '123', name: 'test' }] };
|
|
5
6
|
const mockResponse = (status, json = mockJsonData) => ({
|
|
6
7
|
status,
|
|
@@ -87,3 +88,36 @@ describe('FlexPLMConnect.getRequest', () => {
|
|
|
87
88
|
await expect(connect.getRequest()).rejects.toThrow('Error getting json data from FlexPLM: Invalid JSON');
|
|
88
89
|
});
|
|
89
90
|
});
|
|
91
|
+
describe('FlexPLMConnect.sendRequest', () => {
|
|
92
|
+
it('should mask csrf nonce value in logged request options', async () => {
|
|
93
|
+
const loggerIsInfoOnSpy = jest.spyOn(app_framework_1.Logger, 'isInfoOn').mockReturnValue(true);
|
|
94
|
+
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
|
|
95
|
+
const csrf = { nonce_key: 'CSRF_NONCE', nonce: 'raw-secret-nonce' };
|
|
96
|
+
const payload = { id: '123' };
|
|
97
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
98
|
+
await connect.sendRequest(csrf, payload);
|
|
99
|
+
const csrfOptionsLogMessages = consoleInfoSpy.mock.calls
|
|
100
|
+
.map(([message]) => String(message ?? ''))
|
|
101
|
+
.filter(message => message.startsWith('csrfOptions: '));
|
|
102
|
+
const sendRequestOptionsLogMessage = csrfOptionsLogMessages.find(message => message.includes('"CSRF_NONCE":'));
|
|
103
|
+
expect(sendRequestOptionsLogMessage).toBeDefined();
|
|
104
|
+
expect(sendRequestOptionsLogMessage ?? '').not.toContain('raw-secret-nonce');
|
|
105
|
+
expect(sendRequestOptionsLogMessage ?? '').toContain(`"CSRF_NONCE":"***masked(length:${'raw-secret-nonce'.length})***"`);
|
|
106
|
+
loggerIsInfoOnSpy.mockRestore();
|
|
107
|
+
consoleInfoSpy.mockRestore();
|
|
108
|
+
});
|
|
109
|
+
it('should log masked(empty) when csrf nonce is empty', async () => {
|
|
110
|
+
const loggerIsInfoOnSpy = jest.spyOn(app_framework_1.Logger, 'isInfoOn').mockReturnValue(true);
|
|
111
|
+
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
|
|
112
|
+
const csrf = { nonce_key: 'CSRF_NONCE', nonce: '' };
|
|
113
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
114
|
+
await connect.sendRequest(csrf, { id: '123' });
|
|
115
|
+
const csrfOptionsLog = consoleInfoSpy.mock.calls
|
|
116
|
+
.map(([message]) => String(message ?? ''))
|
|
117
|
+
.find(message => message.includes('"CSRF_NONCE":'));
|
|
118
|
+
expect(csrfOptionsLog).toBeDefined();
|
|
119
|
+
expect(csrfOptionsLog ?? '').toContain('"CSRF_NONCE":"***masked(empty)***"');
|
|
120
|
+
loggerIsInfoOnSpy.mockRestore();
|
|
121
|
+
consoleInfoSpy.mockRestore();
|
|
122
|
+
});
|
|
123
|
+
});
|