Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fix(interceptor): set authorization header instead of appending
Browse files Browse the repository at this point in the history
  • Loading branch information
doktordirk committed Mar 31, 2016
1 parent 4a44425 commit 4e53457
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app.fetch-httpClient.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class FetchConfig {
token = `${config.authToken} ${token}`;
}

request.headers.append(config.authHeader, token);
request.headers.set(config.authHeader, token);

return request;
}
Expand Down
7 changes: 4 additions & 3 deletions test/app.fetch-httpClient.config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function getInterceptorStubs(isAuthenticated, httpInterceptor) {

let requestStub = {
headers: {
append: (header, value) => {}
append: (header, value) => {},
set: (header, value) => {}
}
};

Expand All @@ -47,13 +48,13 @@ describe('FetchConfig', function() {
it('Should intercept requests when authenticated.', function() {
let { authenticationStub, configStub, requestStub } = getInterceptorStubs(true, true);

spyOn(requestStub.headers, 'append');
spyOn(requestStub.headers, 'set');

let fetchConfig = new FetchConfig(null, null, authenticationStub, configStub);
let chain = fetchConfig.interceptor.request(requestStub);

expect(chain).toBe(requestStub);
expect(requestStub.headers.append).toHaveBeenCalledWith('AuthoriseHeader', 'AuthoriseToken someToken');
expect(requestStub.headers.set).toHaveBeenCalledWith('AuthoriseHeader', 'AuthoriseToken someToken');
});

it('Should not intercept requests when unauthenticated.', function() {
Expand Down

0 comments on commit 4e53457

Please sign in to comment.