@@ -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} ) ;
0 commit comments