Skip to content

Commit

Permalink
fix(@aws-amplify/auth): Adjust Cognito error message checking for dis… (
Browse files Browse the repository at this point in the history
aws-amplify#4546)

* fix(@aws-amplify/auth): Adjust Cognito error message checking for disabled user.

Fixes aws-amplify#4544

* Fix unit test
  • Loading branch information
manueliglesias authored Dec 10, 2019
1 parent 73bf46e commit 1baab78
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
66 changes: 30 additions & 36 deletions packages/auth/__tests__/auth-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,11 @@ describe('auth unit test', () => {

await auth.confirmSignUp('username', code);

expect(await CognitoUser.prototype.confirmRegistration).toBeCalledWith(
code,
jasmine.any(Boolean),
jasmine.any(Function),
{ foo: 'bar' }
);
expect(
await CognitoUser.prototype.confirmRegistration
).toBeCalledWith(code, jasmine.any(Boolean), jasmine.any(Function), {
foo: 'bar',
});
spyon.mockClear();
});

Expand All @@ -518,12 +517,11 @@ describe('auth unit test', () => {
clientMetadata: { custom: 'value' },
});

expect(await CognitoUser.prototype.confirmRegistration).toBeCalledWith(
code,
jasmine.any(Boolean),
jasmine.any(Function),
{ custom: 'value' }
);
expect(
await CognitoUser.prototype.confirmRegistration
).toBeCalledWith(code, jasmine.any(Boolean), jasmine.any(Function), {
custom: 'value',
});
spyon.mockClear();
});

Expand Down Expand Up @@ -607,10 +605,9 @@ describe('auth unit test', () => {

await auth.resendSignUp('username');

expect(await CognitoUser.prototype.resendConfirmationCode).toBeCalledWith(
jasmine.any(Function),
{ foo: 'bar' }
);
expect(
await CognitoUser.prototype.resendConfirmationCode
).toBeCalledWith(jasmine.any(Function), { foo: 'bar' });
spyon.mockClear();
});

Expand All @@ -620,10 +617,9 @@ describe('auth unit test', () => {

await auth.resendSignUp('username', { custom: 'value' });

expect(await CognitoUser.prototype.resendConfirmationCode).toBeCalledWith(
jasmine.any(Function),
{ custom: 'value' }
);
expect(
await CognitoUser.prototype.resendConfirmationCode
).toBeCalledWith(jasmine.any(Function), { custom: 'value' });
spyon.mockClear();
});

Expand Down Expand Up @@ -753,13 +749,13 @@ describe('auth unit test', () => {
const spyon2 = jest
.spyOn(auth, 'currentUserPoolUser')
.mockImplementationOnce(() => {
return Promise.reject('User is disabled');
return Promise.reject('User is disabled.');
});
expect.assertions(2);
try {
await auth.signIn('username', 'password');
} catch (e) {
expect(e).toBe('User is disabled');
expect(e).toBe('User is disabled.');
expect(spyon2).toBeCalled();
}

Expand Down Expand Up @@ -2000,12 +1996,11 @@ describe('auth unit test', () => {

await auth.changePassword(user, oldPassword, newPassword);

expect(await CognitoUser.prototype.changePassword).toBeCalledWith(
oldPassword,
newPassword,
jasmine.any(Function),
{ foo: 'bar' }
);
expect(
await CognitoUser.prototype.changePassword
).toBeCalledWith(oldPassword, newPassword, jasmine.any(Function), {
foo: 'bar',
});
spyon.mockClear();
});

Expand All @@ -2023,12 +2018,11 @@ describe('auth unit test', () => {
custom: 'value',
});

expect(await CognitoUser.prototype.changePassword).toBeCalledWith(
oldPassword,
newPassword,
jasmine.any(Function),
{ custom: 'value' }
);
expect(
await CognitoUser.prototype.changePassword
).toBeCalledWith(oldPassword, newPassword, jasmine.any(Function), {
custom: 'value',
});
spyon.mockClear();
});
});
Expand Down Expand Up @@ -3092,7 +3086,7 @@ describe('auth unit test', () => {
.mockImplementationOnce(callback => {
callback(
{
message: 'User is disabled',
message: 'User is disabled.',
},
null
);
Expand All @@ -3115,7 +3109,7 @@ describe('auth unit test', () => {
await auth.currentUserPoolUser();
} catch (e) {
expect(e).toEqual({
message: 'User is disabled',
message: 'User is disabled.',
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ export default class AuthClass {
logger.debug('getting user data failed', err);
// Make sure the user is still valid
if (
err.message === 'User is disabled' ||
err.message === 'User is disabled.' ||
err.message === 'User does not exist.' ||
err.message === 'Access Token has been revoked' // Session revoked by another app
) {
Expand Down

0 comments on commit 1baab78

Please sign in to comment.