Skip to content

Commit

Permalink
fix: Error Redactor Case-Insensitive Matching (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbankhead committed Apr 3, 2024
1 parent 086c824 commit 05e65ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/common.ts
Expand Up @@ -369,17 +369,17 @@ export function defaultErrorRedactor<T = any>(data: {

for (const key of Object.keys(headers)) {
// any casing of `Authentication`
if (/^authentication$/.test(key)) {
if (/^authentication$/i.test(key)) {
headers[key] = REDACT;
}

// any casing of `Authorization`
if (/^authorization$/.test(key)) {
if (/^authorization$/i.test(key)) {
headers[key] = REDACT;
}

// anything containing secret, such as 'client secret'
if (/secret/.test(key)) {
if (/secret/i.test(key)) {
headers[key] = REDACT;
}
}
Expand All @@ -394,9 +394,9 @@ export function defaultErrorRedactor<T = any>(data: {
const text = obj[key];

if (
/grant_type=/.test(text) ||
/assertion=/.test(text) ||
/secret/.test(text)
/grant_type=/i.test(text) ||
/assertion=/i.test(text) ||
/secret/i.test(text)
) {
obj[key] = REDACT;
}
Expand Down
23 changes: 16 additions & 7 deletions test/test.getch.ts
Expand Up @@ -26,7 +26,7 @@ import {
GaxiosResponse,
GaxiosPromise,
} from '../src';
import {GAXIOS_ERROR_SYMBOL} from '../src/common';
import {GAXIOS_ERROR_SYMBOL, Headers} from '../src/common';
import {pkg} from '../src/util';
import qs from 'querystring';
import fs from 'fs';
Expand Down Expand Up @@ -772,8 +772,11 @@ describe('🎏 data handling', () => {

const config: GaxiosOptions = {
headers: {
authentication: 'My Auth',
authorization: 'My Auth',
Authentication: 'My Auth',
/**
* Ensure casing is properly handled
*/
AUTHORIZATION: 'My Auth',
'content-type': 'application/x-www-form-urlencoded',
random: 'data',
},
Expand Down Expand Up @@ -821,8 +824,8 @@ describe('🎏 data handling', () => {
assert(e.config.headers);
assert.deepStrictEqual(e.config.headers, {
...config.headers, // non-redactables should be present
authentication: REDACT,
authorization: REDACT,
Authentication: REDACT,
AUTHORIZATION: REDACT,
});

// config redactions - data
Expand All @@ -847,11 +850,17 @@ describe('🎏 data handling', () => {
// response redactions
assert(e.response);
assert.deepStrictEqual(e.response.config, e.config);
assert.deepStrictEqual(e.response.headers, {

const expectedHeaders: Headers = {
...responseHeaders, // non-redactables should be present
authentication: REDACT,
authorization: REDACT,
});
};

delete expectedHeaders['AUTHORIZATION'];
delete expectedHeaders['Authentication'];

assert.deepStrictEqual(e.response.headers, expectedHeaders);
assert.deepStrictEqual(e.response.data, {
...response, // non-redactables should be present
assertion: REDACT,
Expand Down

0 comments on commit 05e65ef

Please sign in to comment.