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

Add support for hapi 18 #397

Merged
merged 3 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ internals.refreshRedirect = function (request, name, protocol, settings, credent
return h.unauthenticated(Boom.internal('Missing ' + name + ' request token cookie'), { credentials });
}

const refreshQuery = Object.assign({}, request.url.query, { refresh: 1 });
const refreshQuery = Object.assign({}, request.query, { refresh: 1 });
const refreshUrl = internals.location(request, protocol, settings.location) + '?' + internals.queryString(refreshQuery);
return h.response(`<html><head><meta http-equiv="refresh" content="0;URL='${refreshUrl}'"></head><body></body></html>`).takeover();
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"code": "5.x.x",
"hapi": "17.x.x",
"hapi": "18.x.x",
"hawk": "7.x.x",
"lab": "17.x.x",
"teamwork": "3.x.x"
Expand Down
38 changes: 19 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Bell', () => {
it('authenticates an endpoint via oauth', async (flags) => {

const mock = await Mock.v1(flags);
const server = Hapi.server({ host: 'localhost', port: 80 });
const server = Hapi.server({ host: 'localhost', port: 8080 });
await server.register(Bell);

server.auth.strategy('custom', 'bell', {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('Bell', () => {
expect(res1.headers.location).to.equal(mock.uri + '/auth?oauth_token=1');

const res2 = await mock.server.inject(res1.headers.location);
expect(res2.headers.location).to.equal('http://localhost:80/login?oauth_token=1&oauth_verifier=123');
expect(res2.headers.location).to.equal('http://localhost:8080/login?oauth_token=1&oauth_verifier=123');

const res3 = await server.inject({ url: res2.headers.location, headers: { cookie } });
expect(res3.result.provider).to.equal('custom');
Expand All @@ -63,7 +63,7 @@ describe('Bell', () => {
it('authenticates an endpoint via oauth using RSA-SHA1 signing', async (flags) => {

const mock = await Mock.v1(flags, { signatureMethod: 'RSA-SHA1' });
const server = Hapi.server({ host: 'localhost', port: 80 });
const server = Hapi.server({ host: 'localhost', port: 8080 });
await server.register(Bell);

server.auth.strategy('custom', 'bell', {
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('Bell', () => {
expect(res1.headers.location).to.equal(mock.uri + '/auth?oauth_token=1');

const res2 = await mock.server.inject(res1.headers.location);
expect(res2.headers.location).to.equal('http://localhost:80/login?oauth_token=1&oauth_verifier=123');
expect(res2.headers.location).to.equal('http://localhost:8080/login?oauth_token=1&oauth_verifier=123');

const res3 = await server.inject({ url: res2.headers.location, headers: { cookie } });
expect(res3.result.provider).to.equal('custom');
Expand All @@ -101,7 +101,7 @@ describe('Bell', () => {
it('authenticates an endpoint via oauth2', async (flags) => {

const mock = await Mock.v2(flags);
const server = Hapi.server({ host: 'localhost', port: 80 });
const server = Hapi.server({ host: 'localhost', port: 8080 });
await server.register(Bell);

server.auth.strategy('custom', 'bell', {
Expand All @@ -125,11 +125,11 @@ describe('Bell', () => {
});

const res1 = await server.inject('/login');
expect(res1.headers.location).to.contain(mock.uri + '/auth?client_id=test&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A80%2Flogin&state=');
expect(res1.headers.location).to.contain(mock.uri + '/auth?client_id=test&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin&state=');
const cookie = res1.headers['set-cookie'][0].split(';')[0] + ';';

const res2 = await mock.server.inject(res1.headers.location);
expect(res2.headers.location).to.contain('http://localhost:80/login?code=1&state=');
expect(res2.headers.location).to.contain('http://localhost:8080/login?code=1&state=');

const res3 = await server.inject({ url: res2.headers.location, headers: { cookie } });
expect(res3.result.provider).to.equal('custom');
Expand All @@ -138,7 +138,7 @@ describe('Bell', () => {
it('authenticates an endpoint via oauth2 and basic authentication', async (flags) => {

const mock = await Mock.v2(flags, { useParamsAuth: false });
const server = Hapi.server({ host: 'localhost', port: 80 });
const server = Hapi.server({ host: 'localhost', port: 8080 });
await server.register(Bell);

server.auth.strategy('custom', 'bell', {
Expand All @@ -163,10 +163,10 @@ describe('Bell', () => {

const res1 = await server.inject('/login');
const cookie = res1.headers['set-cookie'][0].split(';')[0] + ';';
expect(res1.headers.location).to.contain(mock.uri + '/auth?client_id=test&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A80%2Flogin&state=');
expect(res1.headers.location).to.contain(mock.uri + '/auth?client_id=test&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin&state=');

const res2 = await mock.server.inject(res1.headers.location);
expect(res2.headers.location).to.contain('http://localhost:80/login?code=1&state=');
expect(res2.headers.location).to.contain('http://localhost:8080/login?code=1&state=');

const res3 = await server.inject({ url: res2.headers.location, headers: { cookie } });
expect(res3.result.provider).to.equal('custom');
Expand All @@ -175,7 +175,7 @@ describe('Bell', () => {
it('authenticates an endpoint via oauth2 with custom client secret options', async (flags) => {

const mock = await Mock.v2(flags, false);
const server = Hapi.server({ host: 'localhost', port: 80 });
const server = Hapi.server({ host: 'localhost', port: 8080 });
await server.register(Bell);

server.auth.strategy('custom', 'bell', {
Expand All @@ -200,10 +200,10 @@ describe('Bell', () => {

const res1 = await server.inject('/login');
const cookie = res1.headers['set-cookie'][0].split(';')[0] + ';';
expect(res1.headers.location).to.contain(mock.uri + '/auth?client_id=customSecret&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A80%2Flogin&state=');
expect(res1.headers.location).to.contain(mock.uri + '/auth?client_id=customSecret&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin&state=');

const res2 = await mock.server.inject(res1.headers.location);
expect(res2.headers.location).to.contain('http://localhost:80/login?code=1&state=');
expect(res2.headers.location).to.contain('http://localhost:8080/login?code=1&state=');

const res3 = await server.inject({ url: res2.headers.location, headers: { cookie } });
expect(res3.result.provider).to.equal('custom');
Expand All @@ -213,7 +213,7 @@ describe('Bell', () => {
it('authenticates an endpoint via oauth2 with custom client secret options and params auth', async (flags) => {

const mock = await Mock.v2(flags, true); // Sets useParamsAuth = true
const server = Hapi.server({ host: 'localhost', port: 80 });
const server = Hapi.server({ host: 'localhost', port: 8080 });
await server.register(Bell);

server.auth.strategy('custom', 'bell', {
Expand All @@ -238,10 +238,10 @@ describe('Bell', () => {

const res1 = await server.inject('/login');
const cookie = res1.headers['set-cookie'][0].split(';')[0] + ';';
expect(res1.headers.location).to.contain(mock.uri + '/auth?client_id=customSecret&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A80%2Flogin&state=');
expect(res1.headers.location).to.contain(mock.uri + '/auth?client_id=customSecret&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin&state=');

const res2 = await mock.server.inject(res1.headers.location);
expect(res2.headers.location).to.contain('http://localhost:80/login?code=1&state=');
expect(res2.headers.location).to.contain('http://localhost:8080/login?code=1&state=');

const res3 = await server.inject({ url: res2.headers.location, headers: { cookie } });
expect(res3.result.provider).to.equal('custom');
Expand All @@ -251,7 +251,7 @@ describe('Bell', () => {
it('overrides cookie name', async (flags) => {

const mock = await Mock.v1(flags);
const server = Hapi.server({ host: 'localhost', port: 80 });
const server = Hapi.server({ host: 'localhost', port: 8080 });
await server.register(Bell);

server.auth.strategy('custom', 'bell', {
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('Bell', () => {
it('allows multiple custom provider names', async (flags) => {

const mock = await Mock.v1(flags);
const server = Hapi.server({ host: 'localhost', port: 80 });
const server = Hapi.server({ host: 'localhost', port: 8080 });
await server.register(Bell);

server.auth.strategy('custom_1', 'bell', {
Expand Down Expand Up @@ -341,7 +341,7 @@ describe('Bell', () => {

it('exposes OAuth via plugin', async () => {

const server = Hapi.server({ host: 'localhost', port: 80 });
const server = Hapi.server({ host: 'localhost', port: 8080 });
await server.register(Bell);

expect(server.plugins.bell.oauth.Client).to.be.function();
Expand Down
Loading