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(logs/azure): redact sensitive header when DEBUG is set #1218

Merged
merged 19 commits into from
Jan 13, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update2
minhanh-phan committed Dec 10, 2024
commit 182f201b5cbae6d98da7713e1d78b35b95f4d7fb
49 changes: 48 additions & 1 deletion tests/qs/utils.test.ts
minhanh-phan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { debug } from 'openai/core';
import { combine, merge, is_buffer, assign_single_source } from 'openai/internal/qs/utils';

describe('merge()', function () {
@@ -166,4 +167,50 @@ test('is_buffer()', function () {
var buffer = Buffer.from('abc');
// t.equal(is_buffer(buffer), true, 'real Buffer instance is a buffer');
expect(is_buffer(buffer)).toEqual(true);
});
});

test("debug()", function(){
const originalEnv = process.env;
const spy = jest.spyOn(console, "log");

// Debug enabled
process.env["DEBUG"]= "true";

// Test request body includes headers object with Authorization
const headersTest = {
headers: {
Authorization: "fakeAuthorization"
}
}
debug("request", headersTest);
expect(spy).toHaveBeenCalledWith("OpenAI:DEBUG:request", {
headers: {
Authorization: "REDACTED"
}
});

// Test request body includes headers object with api-ley
const apiKeyTest = {
headers: {
"api-key": "fakeKey"
}
}
debug("request", apiKeyTest);
expect(spy).toHaveBeenCalledWith("OpenAI:DEBUG:request", {
headers: {
"api-key": "REDACTED"
}
});

// Test headers object with authorization header
const authorizationTest = {
authorization: "fakeValue"
}
debug("request", authorizationTest);
expect(spy).toHaveBeenCalledWith("OpenAI:DEBUG:request", {
authorization: "REDACTED"
});

process.env = originalEnv;

})