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

chore(api-graphql): Bump graphql to 14.5.0 #8984

Merged
merged 13 commits into from Oct 26, 2021
264 changes: 35 additions & 229 deletions packages/amazon-cognito-identity-js/CHANGELOG.md

Large diffs are not rendered by default.

Expand Up @@ -383,12 +383,21 @@ describe('authenticateUserInternal()', () => {
});

test('DEVICE_SRP_AUTH calls getDeviceResponse and sends session', () => {
const clientSpy = jest.spyOn(Client.prototype, 'request')
.mockImplementation((...args) => { });
const authDataGetDeviceResponse = { ...authData, ChallengeName: 'DEVICE_SRP_AUTH', Session: 'abcd' };
const clientSpy = jest
.spyOn(Client.prototype, 'request')
.mockImplementation((...args) => {});
const authDataGetDeviceResponse = {
...authData,
ChallengeName: 'DEVICE_SRP_AUTH',
Session: 'abcd',
};
const spyon = jest.spyOn(user, 'getDeviceResponse');

user.authenticateUserInternal(authDataGetDeviceResponse, authHelper, callback);
user.authenticateUserInternal(
authDataGetDeviceResponse,
authHelper,
callback
);
expect(clientSpy.mock.calls[0][1]).toMatchObject({ Session: 'abcd' });
expect(spyon).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -1169,7 +1178,7 @@ describe('confirmPassword() and forgotPassword()', () => {
test('happy path should callback onSuccess', () => {
netRequestMockSuccess(true);
cognitoUser.confirmPassword(...confirmPasswordDefaults);
expect(callback.onSuccess).toHaveBeenCalledWith('SUCCESS')
expect(callback.onSuccess).toHaveBeenCalledWith('SUCCESS');
});

test('client request throws an error', () => {
Expand Down Expand Up @@ -1572,8 +1581,9 @@ describe('refreshSession()', () => {
const callback = jest.fn();
const refreshSessionDefaults = [new CognitoRefreshToken(), callback, {}];

const keyPrefix = `CognitoIdentityServiceProvider.${cognitoUser.pool.getClientId()}.${cognitoUser.username
}`;
const keyPrefix = `CognitoIdentityServiceProvider.${cognitoUser.pool.getClientId()}.${
cognitoUser.username
}`;

const idTokenKey = `${keyPrefix}.idToken`;
const accessTokenKey = `${keyPrefix}.accessToken`;
Expand Down
40 changes: 23 additions & 17 deletions packages/amazon-cognito-identity-js/src/CognitoUser.js
Expand Up @@ -673,7 +673,7 @@ export default class CognitoUser {
ClientId: this.pool.getClientId(),
ChallengeResponses: authParameters,
ClientMetadata: clientMetadata,
Session: this.Session
Session: this.Session,
};
if (this.getUserContextData()) {
jsonReq.UserContextData = this.getUserContextData();
Expand Down Expand Up @@ -1397,8 +1397,9 @@ export default class CognitoUser {
return callback(null, this.signInUserSession);
}

const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${this.username
}`;
const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${
this.username
}`;
const idTokenKey = `${keyPrefix}.idToken`;
const accessTokenKey = `${keyPrefix}.accessToken`;
const refreshTokenKey = `${keyPrefix}.refreshToken`;
Expand Down Expand Up @@ -1561,8 +1562,9 @@ export default class CognitoUser {
* @returns {void}
*/
cacheDeviceKeyAndPassword() {
const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${this.username
}`;
const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${
this.username
}`;
const deviceKeyKey = `${keyPrefix}.deviceKey`;
const randomPasswordKey = `${keyPrefix}.randomPasswordKey`;
const deviceGroupKeyKey = `${keyPrefix}.deviceGroupKey`;
Expand All @@ -1577,8 +1579,9 @@ export default class CognitoUser {
* @returns {void}
*/
getCachedDeviceKeyAndPassword() {
const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${this.username
}`;
const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${
this.username
}`;
const deviceKeyKey = `${keyPrefix}.deviceKey`;
const randomPasswordKey = `${keyPrefix}.randomPasswordKey`;
const deviceGroupKeyKey = `${keyPrefix}.deviceGroupKey`;
Expand All @@ -1595,8 +1598,9 @@ export default class CognitoUser {
* @returns {void}
*/
clearCachedDeviceKeyAndPassword() {
const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${this.username
}`;
const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${
this.username
}`;
const deviceKeyKey = `${keyPrefix}.deviceKey`;
const randomPasswordKey = `${keyPrefix}.randomPasswordKey`;
const deviceGroupKeyKey = `${keyPrefix}.deviceGroupKey`;
Expand Down Expand Up @@ -1970,7 +1974,7 @@ export default class CognitoUser {
*/
signOut(revokeTokenCallback) {
// If tokens won't be revoked, we just clean the client data.
if (!revokeTokenCallback || typeof revokeTokenCallback !== "function") {
if (!revokeTokenCallback || typeof revokeTokenCallback !== 'function') {
this.cleanClientData();

return;
Expand All @@ -1981,17 +1985,17 @@ export default class CognitoUser {
return revokeTokenCallback(error);
}

this.revokeTokens((err) => {
this.revokeTokens(err => {
this.cleanClientData();

revokeTokenCallback(err);
});
});
}

revokeTokens(revokeTokenCallback = () => { }) {
revokeTokens(revokeTokenCallback = () => {}) {
if (typeof revokeTokenCallback !== 'function') {
throw new Error('Invalid revokeTokenCallback. It should be a function.')
throw new Error('Invalid revokeTokenCallback. It should be a function.');
}

const tokensToBeRevoked = [];
Expand All @@ -2013,7 +2017,10 @@ export default class CognitoUser {

if (this.isSessionRevocable(accessToken)) {
if (refreshToken) {
return this.revokeToken({ token: refreshToken, callback: revokeTokenCallback });
return this.revokeToken({
token: refreshToken,
callback: revokeTokenCallback,
});
}
}
revokeTokenCallback();
Expand Down Expand Up @@ -2042,17 +2049,16 @@ export default class CognitoUser {
'RevokeToken',
{
Token: token,
ClientId: this.pool.getClientId()
ClientId: this.pool.getClientId(),
},
err => {

if (err) {
return callback(err);
}

callback();
}
)
);
}

/**
Expand Down