Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case 'success':
case 'email-verification-required':
callback();
break;
default:
assert(false, 'unrecognised username in credentials refresh');
}
});
const mockSession = {
getIdToken: () => ({
getJwtToken: () => 'jwt_token',
}),
};
sinon.stub(CognitoUser.prototype, 'getAttributeVerificationCode').callsFake((attribute, callbacks) =>
callbacks.inputVerificationCode(),
);
sinon.stub(CognitoUser.prototype, 'getUserAttributes').callsFake(function f(callback) {
const verified = this.username === 'email-verification-required' ? 'false' : 'true';
callback(undefined, [{
getName: () => 'email_verified',
getValue: () => verified,
}]);
});
sinon.stub(CognitoUser.prototype, 'getSession').callsFake(function f(callback) {
switch (this.username) {
case 'session-error':
callback(true, null);
break;
sinon.stub(CognitoUser.prototype, 'getSession').callsFake(function f(callback) {
switch (this.username) {
case 'session-error':
callback(true, null);
break;
case 'success':
case 'email-verification-required':
callback(false, mockSession);
break;
default:
assert(false, 'unrecognised username in getSession stub');
}
});
sinon.stub(CognitoUser.prototype, 'authenticateUser').callsFake((creds, f) => {
switch (creds.username) {
case 'success':
case 'session-error':
case 'email-verification-required':
f.onSuccess();
break;
case 'failure-bad-creds':
f.onFailure({ code: 'NotAuthorizedException' });
break;
case 'failure-not-confirmed':
f.onFailure({ code: 'UserNotConfirmedException' });
break;
case 'mfa':
f.mfaRequired();
break;
case 'newpass':