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

fix(core): Handle null response_content before passing to findSensitiveValues #772

Merged
merged 2 commits into from
Apr 18, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/tools/create-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const toStdout = (event, msg, data) => {
const attemptFindSecretsInStr = (s, isGettingNewSecret) => {
let parsedRespContent;
try {
parsedRespContent = JSON.parse(s);
parsedRespContent = JSON.parse(s) || {};
} catch {
return [];
}
Expand Down
33 changes: 33 additions & 0 deletions packages/core/test/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,39 @@ describe('logger', () => {
]);
});

it('should leave response content of null uncensored', async () => {
const event = {
method: 'authentication.sessionConfig.perform',
};
const logger = createlogger(event, options);

const { message, data } = prepareTestRequest({
resBody: JSON.stringify(null),
});

await logger(message, data);
const response = await logger.end(1000);
response.status.should.eql(200);

response.content.logs.should.deepEqual([
{
message: '200 POST http://example.com',
data: {
log_type: 'http',
request_type: 'devplatform-outbound',
request_url: 'http://example.com',
request_method: 'POST',
request_headers: 'accept: application/json',
request_data: '{}',
request_via_client: true,
response_status_code: 200,
response_headers: 'content-type: application/json',
response_content: 'null',
},
},
]);
});

it('should handle missing bits of the request/response', async () => {
// this test should, as closely as possible, match what we actually log after an http request from z.request
const bundle = {
Expand Down
Loading