Skip to content

Commit 9ac8060

Browse files
committed
major: do not redefine already set authorization header
1 parent faf83f4 commit 9ac8060

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/index.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ describe("hermione-oauth", () => {
4646
expect(config2).toEqual({ headers: { "<baz>": "<quux>", Authorization: "OAuth 123456789" } });
4747
});
4848

49+
test("should not set token if authorization header is already set", () => {
50+
const config = { headers: { Authorization: "<foo>" } };
51+
const hermione = hermioneMock({ "<bro-id>": browser(config) });
52+
53+
plugin(hermione, { enabled: true, token: "123456789" });
54+
hermione.emit(hermione.events.BEGIN);
55+
56+
expect(config).toEqual({ headers: { Authorization: "<foo>" } });
57+
});
58+
4959
test("should read token from file when it is given as absolute path", () => {
5060
const hermione = hermioneMock({ "<bro-id>": browser() });
5161

@@ -67,4 +77,17 @@ describe("hermione-oauth", () => {
6777
expect(config1).toEqual({ headers: { "<foo>": "<bar>", Authorization: "OAuth 987654321" } });
6878
expect(config2).toEqual({ headers: { "<baz>": "<quux>", Authorization: "OAuth 987654321" } });
6979
});
80+
81+
test("should not set token from file if authorization header is already set", () => {
82+
readTokenMock.default.mockReturnValue("987654321");
83+
84+
const config = { headers: { Authorization: "<foo>" } };
85+
const hermione = hermioneMock({ "<bro-id>": browser(config) });
86+
87+
plugin(hermione, { enabled: true, token: "/foo/bar" });
88+
89+
hermione.emit(hermione.events.BEGIN);
90+
91+
expect(config).toEqual({ headers: { Authorization: "<foo>" } });
92+
});
7093
});

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export = (hermione: Hermione, options: Record<string, unknown>): void => {
1818
hermione.config.getBrowserIds().forEach(browserId => {
1919
const browserConfig = hermione.config.forBrowser(browserId);
2020

21-
browserConfig.headers = { ...browserConfig.headers, Authorization: `OAuth ${token}` };
21+
browserConfig.headers = { Authorization: `OAuth ${token}`, ...browserConfig.headers };
2222
});
2323
});
2424
};

0 commit comments

Comments
 (0)