Skip to content

Commit

Permalink
Merge pull request #5 from gemini-testing/INFRADUTY-23826
Browse files Browse the repository at this point in the history
major: do not redefine already set authorization header
  • Loading branch information
eGavr authored Dec 15, 2022
2 parents faf83f4 + 9ac8060 commit 7d9b366
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ describe("hermione-oauth", () => {
expect(config2).toEqual({ headers: { "<baz>": "<quux>", Authorization: "OAuth 123456789" } });
});

test("should not set token if authorization header is already set", () => {
const config = { headers: { Authorization: "<foo>" } };
const hermione = hermioneMock({ "<bro-id>": browser(config) });

plugin(hermione, { enabled: true, token: "123456789" });
hermione.emit(hermione.events.BEGIN);

expect(config).toEqual({ headers: { Authorization: "<foo>" } });
});

test("should read token from file when it is given as absolute path", () => {
const hermione = hermioneMock({ "<bro-id>": browser() });

Expand All @@ -67,4 +77,17 @@ describe("hermione-oauth", () => {
expect(config1).toEqual({ headers: { "<foo>": "<bar>", Authorization: "OAuth 987654321" } });
expect(config2).toEqual({ headers: { "<baz>": "<quux>", Authorization: "OAuth 987654321" } });
});

test("should not set token from file if authorization header is already set", () => {
readTokenMock.default.mockReturnValue("987654321");

const config = { headers: { Authorization: "<foo>" } };
const hermione = hermioneMock({ "<bro-id>": browser(config) });

plugin(hermione, { enabled: true, token: "/foo/bar" });

hermione.emit(hermione.events.BEGIN);

expect(config).toEqual({ headers: { Authorization: "<foo>" } });
});
});
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export = (hermione: Hermione, options: Record<string, unknown>): void => {
hermione.config.getBrowserIds().forEach(browserId => {
const browserConfig = hermione.config.forBrowser(browserId);

browserConfig.headers = { ...browserConfig.headers, Authorization: `OAuth ${token}` };
browserConfig.headers = { Authorization: `OAuth ${token}`, ...browserConfig.headers };
});
});
};

0 comments on commit 7d9b366

Please sign in to comment.