Skip to content

Commit

Permalink
Removing legacy COA mapping + fixing access_denied mapping (#1266)
Browse files Browse the repository at this point in the history
* Removing legacy COA mapping + fixing access_denied mapping

* using foobar
  • Loading branch information
luisrudge authored Feb 15, 2018
1 parent 7259cd8 commit 16e6c04
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
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",
}
`;

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
26 changes: 15 additions & 11 deletions src/__tests__/core/web_api/helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,28 @@ 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'
};
const expectedError = {
code: 'invalid_user_password',
error: 'invalid_user_password',
description: error.description
description: 'foobar'
};
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: 'foobar'
};
const actualError = normalizeError(error);
expect(actualError).toMatchSnapshot();
Expand Down
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

0 comments on commit 16e6c04

Please sign in to comment.