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

[ESD-5519] Fix issue where authz header was overridden in code exchange #86

Merged
merged 3 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
4 changes: 1 addition & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ async function get(config) {
config.enableTelemetry && {'Auth0-Client': Buffer.from(JSON.stringify(telemetryHeader)).toString('base64')}
);

client[custom.http_options] = function(options) {
return Object.assign({}, options, httpOptions);
};
custom.setHttpOptionsDefaults(httpOptions);

client[custom.clock_tolerance] = config.clockTolerance;

Expand Down
30 changes: 24 additions & 6 deletions test/client.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const { get: getClient } = require('../lib/client');
const wellKnown = require('./fixture/well-known.json');
const nock = require('nock');
const pkg = require('../package.json');
const sinon = require('sinon');
const openidClient = require('openid-client');

describe('client initialization', function() {

Expand Down Expand Up @@ -49,6 +51,18 @@ describe('client initialization', function() {
assert.include( headerProps, 'user-agent');
assert.equal( `express-openid-connect/${pkg.version}`, headers['user-agent']);
});

it('should not strip new headers', async function() {
const response = await client.requestResource('https://test.auth0.com/introspection', 'token', {
method: 'POST',
headers: {
Authorization: 'Bearer foo',
}
});
const headerProps = Object.getOwnPropertyNames(JSON.parse(response.body));

assert.include( headerProps, 'authorization');
});
});

describe('custom headers', function() {
Expand Down Expand Up @@ -100,16 +114,20 @@ describe('client initialization', function() {
enableTelemetry: false
});

let client;
before(async function() {
client = await getClient(config);
sinon.spy(openidClient.custom, 'setHttpOptionsDefaults');
await getClient(config);
});

it('should send the correct default headers', async function() {
const headers = await client.introspect('__test_token__', '__test_hint__');
const headerProps = Object.getOwnPropertyNames(headers);
after(async function() {
adamjmcgrath marked this conversation as resolved.
Show resolved Hide resolved
openidClient.custom.setHttpOptionsDefaults.restore();
});

assert.notInclude(headerProps, 'auth0-client');
it('should set the correct default headers', async function() {
adamjmcgrath marked this conversation as resolved.
Show resolved Hide resolved
assert.doesNotHaveAnyKeys(
openidClient.custom.setHttpOptionsDefaults.firstCall.args[0].headers,
['auth0-client']
);
});
});

Expand Down