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

Removing legacy COA mapping + fixing access_denied mapping #1266

Merged
merged 4 commits into from
Feb 15, 2018
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
11 changes: 5 additions & 6 deletions src/__tests__/core/web_api/__snapshots__/helper.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`normalizeError maps COA not enabled error 1`] = `
exports[`normalizeError should map access_denied error to invalid_user_password when error.code === access_denied 1`] = `
Object {
"code": "cross_origin_login_not_enabled",
"description": "Cross Origin Authencation is not enabled. Please refer to this document to enable it: https://link-to-doc.com",
"error": "cross_origin_login_not_enabled",
"logToConsole": true,
"code": "invalid_user_password",
"description": "foobar",
"error": "invalid_user_password",
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason behind having code and error with the same values? Shouldn't you keep 1, code probably?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why it is like this. Can't change this now though.

}
`;

exports[`normalizeError should map access_denied error to invalid_user_password 1`] = `
exports[`normalizeError should map access_denied error to invalid_user_password when error.error === access_denied 1`] = `
Object {
"code": "invalid_user_password",
"description": "foobar",
Expand Down
24 changes: 14 additions & 10 deletions src/__tests__/core/web_api/helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@ describe('normalizeError', () => {
const normalized = normalizeError(undefined);
expect(normalized).toBe(undefined);
});
it('maps COA not enabled error', () => {
const normalized = normalizeError({
error: 'unauthorized_client',
error_description: 'Cross origin login not allowed.'
});
expect(normalized).toMatchSnapshot();
});
});
describe('normalizeError', () => {
it('should map access_denied error to invalid_user_password', () => {
it('should map access_denied error to invalid_user_password when error.error === access_denied', () => {
const error = {
error: 'access_denied',
description: 'foobar'
Expand All @@ -43,4 +34,17 @@ describe('normalizeError', () => {
const actualError = normalizeError(error);
expect(actualError).toMatchSnapshot();
});
it('should map access_denied error to invalid_user_password when error.code === access_denied', () => {
const error = {
code: 'access_denied',
description: 'foobar'
};
const expectedError = {
code: 'invalid_user_password',
error: 'invalid_user_password',
description: error.description
Copy link
Contributor

Choose a reason for hiding this comment

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

use description: 'foobar' instead of error.description

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

};
const actualError = normalizeError(error);
expect(actualError).toMatchSnapshot();
});
});
14 changes: 1 addition & 13 deletions src/core/web_api/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ export function normalizeError(error) {
return error;
}

if (
error.error === 'unauthorized_client' &&
error.error_description === 'Cross origin login not allowed.'
) {
return {
code: 'cross_origin_login_not_enabled',
error: 'cross_origin_login_not_enabled',
description: 'Cross Origin Authencation is not enabled. Please refer to this document to enable it: https://link-to-doc.com',
logToConsole: true
};
}

// TODO: clean this mess, the first checks are for social/popup,
// then we have some stuff for passwordless and the latter is for
// db.
Expand Down Expand Up @@ -106,7 +94,7 @@ export function normalizeError(error) {
description: error.description
};
}
if (error.error === 'access_denied') {
if (error.error === 'access_denied' || error.code === 'access_denied') {
return {
code: 'invalid_user_password',
error: 'invalid_user_password',
Expand Down