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: Merge next/release into preview-testing #12066

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions .github/workflows/callable-release-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ jobs:
uses: ./.github/workflows/callable-prebuild-amplify-js.yml
with:
runs_on: ubuntu-latest
prebuild-macos:
uses: ./.github/workflows/callable-prebuild-amplify-js.yml
with:
runs_on: macos-latest
# prebuild-macos:
# uses: ./.github/workflows/callable-prebuild-amplify-js.yml
# with:
# runs_on: macos-latest
prebuild-samples-staging:
secrets: inherit
uses: ./.github/workflows/callable-prebuild-samples-staging.yml
e2e:
needs:
- prebuild-macos
# - prebuild-macos
- prebuild-ubuntu
- prebuild-samples-staging
secrets: inherit
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/push-next-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ concurrency:
on:
push:
branches:
- invalid-branch
- next/release

jobs:
e2e:
secrets: inherit
uses: ./.github/workflows/callable-release-verification.yml
next-release:
needs:
- e2e
secrets: inherit
uses: ./.github/workflows/callable-npm-publish-preid.yml
with:
preid: next
allow-protected-preid: true
# next-release:
# needs:
# - e2e
# secrets: inherit
# uses: ./.github/workflows/callable-npm-publish-preid.yml
# with:
# preid: next
# allow-protected-preid: true
6 changes: 6 additions & 0 deletions packages/analytics/src/providers/pinpoint/types/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
import { UserProfile } from '@aws-amplify/core';
import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';

/**
* Input type for Pinpoint record API.
*/
export type RecordInput = {
/**
* An event to send to the default Analytics provider.
*/
event: PinpointAnalyticsEvent;
};

/**
* Input type for Pinpoint identifyUser API.
*/
export type IdentifyUserInput = {
/**
* A User ID associated to the current device.
Expand Down
55 changes: 22 additions & 33 deletions packages/auth/__tests__/providers/cognito/getCurrentUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from 'aws-amplify';
import { decodeJWT, fetchAuthSession } from '@aws-amplify/core/internals/utils';
import { decodeJWT } from '@aws-amplify/core/internals/utils';
import { AuthError } from '../../../src/errors/AuthError';
import { getCurrentUser } from '../../../src/providers/cognito';
import { InitiateAuthException } from '../../../src/providers/cognito/types/errors';
import { fetchTransferHandler } from '@aws-amplify/core/internals/aws-client-utils';
import { buildMockErrorResponse, mockJsonResponse } from './testUtils/data';

import { Amplify as AmplifyV6 } from '@aws-amplify/core';
import { USER_UNAUTHENTICATED_EXCEPTION } from '../../../src/errors/constants';
jest.mock('@aws-amplify/core/lib/clients/handlers/fetch');
jest.mock('@aws-amplify/core/internals/utils', () => ({
...jest.requireActual('@aws-amplify/core/internals/utils'),
fetchAuthSession: jest.fn(),
}));

Amplify.configure({
Auth: {
Expand All @@ -26,27 +23,25 @@ Amplify.configure({
});
const mockedAccessToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
const mockFetchAuthSession = fetchAuthSession as jest.Mock;
const mockGetTokensFunction = jest.spyOn(AmplifyV6.Auth, 'getTokens');
const mockedSub = 'mockedSub';
const mockedUsername = 'XXXXXXXXXXXXXX';

describe('getUser API happy path cases', () => {
beforeEach(() => {
mockFetchAuthSession.mockResolvedValue({
tokens: {
accessToken: decodeJWT(mockedAccessToken),
idToken: {
payload: {
sub: mockedSub,
'cognito:username': mockedUsername,
},
mockGetTokensFunction.mockResolvedValue({
accessToken: decodeJWT(mockedAccessToken),
idToken: {
payload: {
sub: mockedSub,
'cognito:username': mockedUsername,
},
},
});
});

afterEach(() => {
mockFetchAuthSession.mockClear();
mockGetTokensFunction.mockClear();
});

test('get current user', async () => {
Expand All @@ -56,26 +51,20 @@ describe('getUser API happy path cases', () => {
});

describe('getUser API error path cases:', () => {
test('getUser API should raise service error', async () => {
expect.assertions(2);
mockFetchAuthSession.mockImplementationOnce(async () => {
throw new AuthError({
name: InitiateAuthException.InternalErrorException,
message: 'error at fetchAuthSession',
});
});
(fetchTransferHandler as jest.Mock).mockResolvedValue(
mockJsonResponse(
buildMockErrorResponse(InitiateAuthException.InternalErrorException)
)
);
beforeEach(() => {
mockGetTokensFunction.mockResolvedValue(null);
});

afterEach(() => {
mockGetTokensFunction.mockClear();
});
test('getUser API should raise a validation error when tokens are not found', async () => {
try {
await getCurrentUser({
recache: true,
});
const result = await getCurrentUser();
} catch (error) {
console.log(error);
expect(error).toBeInstanceOf(AuthError);
expect(error.name).toBe(InitiateAuthException.InternalErrorException);
expect(error.name).toBe(USER_UNAUTHENTICATED_EXCEPTION);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { Amplify } from 'aws-amplify';
import { AuthError } from '../../../src/errors/AuthError';
import { AuthValidationErrorCode } from '../../../src/errors/types/validation';
import { authAPITestParams } from './testUtils/authApiTestParams';
import { signIn } from '../../../src/providers/cognito/apis/signIn';
import { signIn, getCurrentUser } from '../../../src/providers/cognito';
import { signInWithCustomAuth } from '../../../src/providers/cognito/apis/signInWithCustomAuth';
import { InitiateAuthException } from '../../../src/providers/cognito/types/errors';
import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers';
import { InitiateAuthCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types';
import { fetchTransferHandler } from '@aws-amplify/core/internals/aws-client-utils';
import { buildMockErrorResponse, mockJsonResponse } from './testUtils/data';
import { USER_ALREADY_AUTHENTICATED_EXCEPTION } from '../../../src/errors/constants';
jest.mock('../../../src/providers/cognito/apis/getCurrentUser');
jest.mock('@aws-amplify/core/lib/clients/handlers/fetch');


const authConfig = {
Cognito: {
userPoolClientId: '111111-aaaaa-42d8-891d-ee81a1549398',
Expand Down Expand Up @@ -83,6 +86,24 @@ describe('signIn API happy path cases', () => {
});

describe('signIn API error path cases:', () => {
test('signIn API should throw a validation AuthError when a user is already signed-in', async () => {
const mockedGetCurrentUser = getCurrentUser as jest.Mock;

mockedGetCurrentUser.mockImplementationOnce(async () => {
return {
username: 'username',
userId: 'userId',
};
});

try {
await signIn({ username: 'username', password: 'password' });
} catch (error) {
expect(error).toBeInstanceOf(AuthError);
expect(error.name).toBe(USER_ALREADY_AUTHENTICATED_EXCEPTION);
}
mockedGetCurrentUser.mockClear();
});
test('signIn API should throw a validation AuthError when username is empty', async () => {
expect.assertions(2);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
import { AuthError } from '../../../src/errors/AuthError';
import { AuthValidationErrorCode } from '../../../src/errors/types/validation';
import { authAPITestParams } from './testUtils/authApiTestParams';
import { signIn } from '../../../src/providers/cognito/apis/signIn';
import { signIn, getCurrentUser } from '../../../src/providers/cognito';
import { InitiateAuthException } from '../../../src/providers/cognito/types/errors';
import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers';
import { signInWithCustomSRPAuth } from '../../../src/providers/cognito/apis/signInWithCustomSRPAuth';
import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types';
import { Amplify } from 'aws-amplify';
import { fetchTransferHandler } from '@aws-amplify/core/internals/aws-client-utils';
import { buildMockErrorResponse, mockJsonResponse } from './testUtils/data';
import { USER_ALREADY_AUTHENTICATED_EXCEPTION } from '../../../src/errors/constants';
jest.mock('../../../src/providers/cognito/apis/getCurrentUser');
jest.mock('@aws-amplify/core/lib/clients/handlers/fetch');

const authConfig = {
Expand Down Expand Up @@ -89,6 +91,24 @@ describe('signIn API happy path cases', () => {
});

describe('signIn API error path cases:', () => {
test('signIn API should throw a validation AuthError when a user is already signed-in', async () => {
const mockedGetCurrentUser = getCurrentUser as jest.Mock;

mockedGetCurrentUser.mockImplementationOnce(async () => {
return {
username: 'username',
userId: 'userId',
};
});

try {
await signIn({ username: 'username', password: 'password' });
} catch (error) {
expect(error).toBeInstanceOf(AuthError);
expect(error.name).toBe(USER_ALREADY_AUTHENTICATED_EXCEPTION);
}
mockedGetCurrentUser.mockClear();
});
test('signIn API should throw a validation AuthError when username is empty', async () => {
expect.assertions(2);
try {
Expand Down
23 changes: 22 additions & 1 deletion packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { AuthError } from '../../../src/errors/AuthError';
import { AuthValidationErrorCode } from '../../../src/errors/types/validation';
import { authAPITestParams } from './testUtils/authApiTestParams';
import { signIn } from '../../../src/providers/cognito/apis/signIn';
import { signIn, getCurrentUser } from '../../../src/providers/cognito';
import { signInWithSRP } from '../../../src/providers/cognito/apis/signInWithSRP';
import { InitiateAuthException } from '../../../src/providers/cognito/types/errors';
import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers';
Expand All @@ -12,6 +13,8 @@ import { Amplify } from 'aws-amplify';
import { fetchTransferHandler } from '@aws-amplify/core/internals/aws-client-utils';
import { buildMockErrorResponse, mockJsonResponse } from './testUtils/data';
import { CognitoUserPoolsTokenProvider } from '../../../src/providers/cognito/tokenProvider';
import { USER_ALREADY_AUTHENTICATED_EXCEPTION } from '../../../src/errors/constants';
jest.mock('../../../src/providers/cognito/apis/getCurrentUser');
jest.mock('@aws-amplify/core/lib/clients/handlers/fetch');

const authConfig = {
Expand Down Expand Up @@ -99,6 +102,24 @@ describe('signIn API happy path cases', () => {
});

describe('signIn API error path cases:', () => {
test('signIn API should throw a validation AuthError when a user is already signed-in', async () => {
const mockedGetCurrentUser = getCurrentUser as jest.Mock;

mockedGetCurrentUser.mockImplementationOnce(async () => {
return {
username: 'username',
userId: 'userId',
};
});

try {
await signIn({ username: 'username', password: 'password' });
} catch (error) {
expect(error).toBeInstanceOf(AuthError);
expect(error.name).toBe(USER_ALREADY_AUTHENTICATED_EXCEPTION);
}
mockedGetCurrentUser.mockClear();
});
test('signIn API should throw a validation AuthError when username is empty', async () => {
expect.assertions(2);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import { AuthError } from '../../../src/errors/AuthError';
import { AuthValidationErrorCode } from '../../../src/errors/types/validation';
import { authAPITestParams } from './testUtils/authApiTestParams';
import { signIn } from '../../../src/providers/cognito/apis/signIn';
import { signIn, getCurrentUser } from '../../../src/providers/cognito';
import { InitiateAuthException } from '../../../src/providers/cognito/types/errors';
import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers';
import { signInWithUserPassword } from '../../../src/providers/cognito/apis/signInWithUserPassword';
import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types';
import { Amplify } from 'aws-amplify';
import { fetchTransferHandler } from '@aws-amplify/core/internals/aws-client-utils';
import { buildMockErrorResponse, mockJsonResponse } from './testUtils/data';
import { cognitoCredentialsProvider } from '../../../src/providers/cognito/credentialsProvider';
import { CognitoUserPoolsTokenProvider } from '../../../src/providers/cognito/tokenProvider';
import { USER_ALREADY_AUTHENTICATED_EXCEPTION } from '../../../src/errors/constants';
jest.mock('../../../src/providers/cognito/apis/getCurrentUser');
jest.mock('@aws-amplify/core/lib/clients/handlers/fetch');

const authConfig = {
Expand All @@ -22,12 +23,7 @@ const authConfig = {
userPoolId: 'us-west-2_zzzzz',
},
};
const authConfigWithClientmetadata = {
Cognito: {
userPoolClientId: '111111-aaaaa-42d8-891d-ee81a1549398',
userPoolId: 'us-west-2_zzzzz',
},
};

CognitoUserPoolsTokenProvider.setAuthConfig(authConfig);
Amplify.configure({
Auth: authConfig,
Expand Down Expand Up @@ -82,6 +78,24 @@ describe('signIn API happy path cases', () => {
});

describe('signIn API error path cases:', () => {
test('signIn API should throw a validation AuthError when a user is already signed-in', async () => {
const mockedGetCurrentUser = getCurrentUser as jest.Mock;

mockedGetCurrentUser.mockImplementationOnce(async () => {
return {
username: 'username',
userId: 'userId',
};
});

try {
await signIn({ username: 'username', password: 'password' });
} catch (error) {
expect(error).toBeInstanceOf(AuthError);
expect(error.name).toBe(USER_ALREADY_AUTHENTICATED_EXCEPTION);
}
mockedGetCurrentUser.mockClear();
});
test('signIn API should throw a validation AuthError when username is empty', async () => {
expect.assertions(2);
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"clean:size": "rimraf dual-publish-tmp tmp*",
"format": "echo \"Not implemented\"",
"lint": "tslint '{src}/**/*.ts' && npm run ts-coverage",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 91.19"
"ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 91.18"
},
"typesVersions": {
">=3.8": {
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// TODO: delete this module when the Auth class is removed.

import { AuthErrorMessages, AuthErrorTypes } from './types';
import { AuthErrorMessages, AuthErrorTypes } from './types/Auth';
import { ConsoleLogger as Logger } from '@aws-amplify/core/internals/utils';
import { AuthErrorStrings } from './common/AuthErrorStrings';

Expand Down
6 changes: 6 additions & 0 deletions packages/auth/src/errors/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

export const USER_UNAUTHENTICATED_EXCEPTION = 'UserUnAuthenticatedException';
export const USER_ALREADY_AUTHENTICATED_EXCEPTION =
'UserAlreadyAuthenticatedException';
Loading
Loading