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

Return policy attr in errors + responseType validation #273

Merged
merged 4 commits into from
Dec 16, 2016
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
4 changes: 4 additions & 0 deletions src/helper/response-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function wrapCallback(cb) {
errObj.name = err.name;
}

if (err.policy) {
errObj.policy = err.policy;
}

return cb(errObj);
}

Expand Down
4 changes: 4 additions & 0 deletions src/web-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ WebAuth.prototype.login = function (options) {
'audience'
]).with(options);

assert.check(params, { type: 'object', message: 'options parameter is not valid' }, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test this?

responseType: { type: 'string', message: 'responseType option is required' }
});

params = this.transactionManager.process(params);

windowHelper.redirect(this.client.buildAuthorizeUrl(params));
Expand Down
5 changes: 5 additions & 0 deletions src/web-auth/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var UsernamePassword = require('./username-password');
var TransactionManager = require('./transaction-manager');
var objectHelper = require('../helper/object');
var Warn = require('../helper/warn');
var assert = require('../helper/assert');

function Redirect(client, options) {
this.baseOptions = options;
Expand Down Expand Up @@ -36,6 +37,10 @@ Redirect.prototype.login = function (options, cb) {

this.warn.warning('`webauth.redirect.login` will be soon deprecated, use `webauth.login` instead.');

assert.check(params, { type: 'object', message: 'options parameter is not valid' }, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test this?

responseType: { type: 'string', message: 'responseType option is required' }
});

params = this.transactionManager.process(params);

usernamePassword = new UsernamePassword(this.baseOptions);
Expand Down
2 changes: 2 additions & 0 deletions test/helper/response-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('helpers responseHandler', function () {
assert_err.response.statusText = 'Bad request';
assert_err.response.body = {
error: 'the_error_code',
policy: 'the policy',
error_description: 'The error description.',
name: 'SomeName'
};
Expand All @@ -34,6 +35,7 @@ describe('helpers responseHandler', function () {
statusCode: 400,
statusText: 'Bad request',
code: 'the_error_code',
policy: 'the policy',
description: 'The error description.',
name: 'SomeName'
});
Expand Down
12 changes: 10 additions & 2 deletions test/web-auth/redirect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,21 @@ describe('auth0.WebAuth.redirect', function () {
domain: 'me.auth0.com',
clientID: '...',
redirectUri: 'http://page.com/callback',
responseType: 'code',
_sendTelemetry: false
});
});

it('should check that responseType is present', function() {
var _this = this;
expect(function() {
_this.auth0.login({ connection: 'facebook' })
}).to.throwException(function (e) {
expect(e.message).to.be('responseType option is required');
});
})

it('should redirect to authorize', function () {
this.auth0.login({connection: 'facebook', state: '1234'})
this.auth0.login({responseType: 'code', connection: 'facebook', state: '1234'})
expect(global.window.location).to.be('https://me.auth0.com/authorize?connection=facebook&client_id=...&response_type=code&redirect_uri=http%3A%2F%2Fpage.com%2Fcallback&state=1234');
});

Expand Down
22 changes: 22 additions & 0 deletions test/web-auth/web-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,28 @@ describe('auth0.WebAuth', function () {
});
});

context('login', function () {
it('should check that responseType is present', function () {
global.window = { location: '' };
var webAuth = new WebAuth({
domain: 'me.auth0.com',
redirectUri: 'http://page.com/callback',
clientID: '...',
scope: 'openid name read:blog',
audience: 'urn:site:demo:blog',
_sendTelemetry: false
});

expect(function() {
webAuth.login({ connection: 'facebook' })
}).to.throwException(function (e) {
expect(e.message).to.be('responseType option is required');
});

delete global.window;
});
});

context('renewAuth', function () {
beforeEach(function(){
global.window = {};
Expand Down