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

fix(auth): custom userPoolEndpoint cannot be applied on the server-side #13739

Merged
merged 15 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AmplifyUrl } from '@aws-amplify/core/internals/utils';

import { cognitoUserPoolEndpointResolver } from '../../../src/foundation/core/cognitoUserPoolEndpointResolver';
import { COGNITO_IDP_SERVICE_NAME } from '../../../src/foundation/core/constants';
import { cognitoUserPoolEndpointResolver } from '../../../src/foundation/cognitoUserPoolEndpointResolver';
import { COGNITO_IDP_SERVICE_NAME } from '../../../src/foundation/constants';

describe('cognitoUserPoolEndpointResolver', () => {
it('should return the Cognito User Pool endpoint', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AuthError } from '../../../../src/errors/AuthError';
import {
getRegionFromIdentityPoolId,
getRegionFromUserPoolId,
} from '../../../../src/foundation/core/parsers/getRegion';
} from '../../../../src/foundation/parsers/regionParsers';

describe('getRegionFromIdentityPoolId()', () => {
it('returns the region from the identity pool id', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('cognitoUserPoolTransferHandler', () => {
});

it('adds the disableCacheMiddlewareFactory at module loading', () => {
console.log(mockComposeTransferHandler);
expect(mockComposeTransferHandler).toHaveBeenCalledTimes(1);

const [core, middleware] = mockComposeTransferHandler.mock.calls[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {
parseJsonError,
} from '@aws-amplify/core/internals/aws-client-utils';

import { buildEmptyResponseDeserializer } from '../../../../../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/shared/serialization/buildEmptyResponseDeserializer';
import { createEmptyResponseDeserializer } from '../../../../../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/shared/serde/createEmptyResponseDeserializer';
import { AuthError } from '../../../../../../../src/errors/AuthError';

jest.mock('@aws-amplify/core/internals/aws-client-utils');

const mockParseJsonError = jest.mocked(parseJsonError);

describe('buildEmptyResponseDeserializer created response deserializer', () => {
const deserializer = buildEmptyResponseDeserializer();
const deserializer = createEmptyResponseDeserializer();

it('returns undefined for 2xx status code', async () => {
const response: HttpResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
parseJsonError,
} from '@aws-amplify/core/internals/aws-client-utils';

import { buildUserPoolDeserializer } from '../../../../../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/shared/serialization/buildUserPoolDeserializer';
import { createUserPoolDeserializer } from '../../../../../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/shared/serde/createUserPoolDeserializer';
import { AuthError } from '../../../../../../../src/errors/AuthError';

jest.mock('@aws-amplify/core/internals/aws-client-utils');
Expand All @@ -13,7 +13,7 @@ const mockParseJsonBody = jest.mocked(parseJsonBody);
const mockParseJsonError = jest.mocked(parseJsonError);

describe('buildUserPoolDeserializer created response deserializer', () => {
const deserializer = buildUserPoolDeserializer();
const deserializer = createUserPoolDeserializer();

it('returns body for 2xx status code', async () => {
const expectedBody = { test: 'test' };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AmplifyUrl } from '@aws-amplify/core/internals/utils';

import { buildUserPoolSerializer } from '../../../../../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/shared/serialization/buildUserPoolSerializer';
import { createUserPoolSerializer } from '../../../../../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/shared/serde/createUserPoolSerializer';

describe('buildUserPoolSerializer created request serializer', () => {
test.each(['SignUp', 'InitiateAuth', 'RevokeToken'] as const)(
Expand All @@ -10,7 +10,7 @@ describe('buildUserPoolSerializer created request serializer', () => {
const testEndpoint = {
url: new AmplifyUrl('http://test.com'),
};
const serializer = buildUserPoolSerializer(operation);
const serializer = createUserPoolSerializer(operation);
const result = serializer(testInput, testEndpoint);

expect(result).toEqual({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ServiceClientAPIConfig } from '../../../../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/types/ServiceClient';
import { ServiceClientFactoryInput } from '../../../../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/types';

export const mockServiceClientAPIConfig: ServiceClientAPIConfig = {
export const mockServiceClientAPIConfig: ServiceClientFactoryInput = {
endpointResolver: jest.fn() as jest.MockedFunction<
ServiceClientAPIConfig['endpointResolver']
ServiceClientFactoryInput['endpointResolver']
>,
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AmplifyUrl } from '@aws-amplify/core/internals/utils';

import { cognitoUserPoolEndpointResolver } from '../../../../src/foundation/core/cognitoUserPoolEndpointResolver';
import { cognitoUserPoolEndpointResolver } from '../../../../src/foundation/cognitoUserPoolEndpointResolver';
import { createCognitoUserPoolEndpointResolver } from '../../../../src/providers/cognito/factories/createCognitoUserPoolEndpointResolver';

jest.mock('../../../../src/foundation/core/cognitoUserPoolEndpointResolver');
jest.mock('../../../../src/foundation/cognitoUserPoolEndpointResolver');

const mockCognitoUserPoolEndpointResolver = jest.mocked(
cognitoUserPoolEndpointResolver,
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/__tests__/providers/cognito/signOut.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
createGlobalSignOutClient,
createRevokeTokenClient,
} from '../../../src/foundation/factories/serviceClients/cognitoIdentityProvider';
import { getRegionFromUserPoolId } from '../../../src/foundation/core/parsers';
import { getRegionFromUserPoolId } from '../../../src/foundation/parsers';
import { createCognitoUserPoolEndpointResolver } from '../../../src/providers/cognito/factories';

jest.mock('@aws-amplify/core');
Expand All @@ -29,7 +29,7 @@ jest.mock('../../../src/utils');
jest.mock(
'../../../src/foundation/factories/serviceClients/cognitoIdentityProvider',
);
jest.mock('../../../src/foundation/core/parsers');
jest.mock('../../../src/foundation/parsers');
jest.mock('../../../src/providers/cognito/factories');

describe('signOut', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@aws-amplify/core/internals/aws-client-utils';
import { getAmplifyUserAgent } from '@aws-amplify/core/internals/utils';

import { COGNITO_IDP_SERVICE_NAME } from '../../../core/constants';
import { COGNITO_IDP_SERVICE_NAME } from '../../../constants';

export const DEFAULT_SERVICE_CLIENT_API_CONFIG = {
service: COGNITO_IDP_SERVICE_NAME,
Expand Down
HuiSF marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
// SPDX-License-Identifier: Apache-2.0
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';

import { ServiceClientAPIConfig } from './types/ServiceClient';
import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
buildUserPoolDeserializer,
buildUserPoolSerializer,
} from './shared/serialization';
import {
AssociateSoftwareTokenCommandInput,
AssociateSoftwareTokenCommandOutput,
} from './types/Sdk';
ServiceClientFactoryInput,
} from './types';
import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
createUserPoolDeserializer,
createUserPoolSerializer,
} from './shared/serde';
import { DEFAULT_SERVICE_CLIENT_API_CONFIG } from './constants';

export const createAssociateSoftwareTokenClient = (
config: ServiceClientAPIConfig,
config: ServiceClientFactoryInput,
) =>
composeServiceApi(
cognitoUserPoolTransferHandler,
buildUserPoolSerializer<AssociateSoftwareTokenCommandInput>(
createUserPoolSerializer<AssociateSoftwareTokenCommandInput>(
'AssociateSoftwareToken',
),
buildUserPoolDeserializer<AssociateSoftwareTokenCommandOutput>(),
createUserPoolDeserializer<AssociateSoftwareTokenCommandOutput>(),
{
...DEFAULT_SERVICE_CLIENT_API_CONFIG,
...config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/

import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
buildUserPoolDeserializer,
buildUserPoolSerializer,
} from './shared/serialization';
createUserPoolDeserializer,
createUserPoolSerializer,
} from './shared/serde';
import {
ChangePasswordCommandInput,
ChangePasswordCommandOutput,
} from './types/Sdk';
import { ServiceClientAPIConfig } from './types/ServiceClient';
ServiceClientFactoryInput,
} from './types';
import { DEFAULT_SERVICE_CLIENT_API_CONFIG } from './constants';

export const createChangePasswordClient = (config: ServiceClientAPIConfig) =>
export const createChangePasswordClient = (config: ServiceClientFactoryInput) =>
composeServiceApi(
cognitoUserPoolTransferHandler,
buildUserPoolSerializer<ChangePasswordCommandInput>('ChangePassword'),
buildUserPoolDeserializer<ChangePasswordCommandOutput>(),
createUserPoolSerializer<ChangePasswordCommandInput>('ChangePassword'),
createUserPoolDeserializer<ChangePasswordCommandOutput>(),
{
...DEFAULT_SERVICE_CLIENT_API_CONFIG,
...config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/

import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
buildUserPoolDeserializer,
buildUserPoolSerializer,
} from './shared/serialization';
createUserPoolDeserializer,
createUserPoolSerializer,
} from './shared/serde';
import {
ConfirmDeviceCommandInput,
ConfirmDeviceCommandOutput,
} from './types/Sdk';
import { ServiceClientAPIConfig } from './types/ServiceClient';
ServiceClientFactoryInput,
} from './types';
import { DEFAULT_SERVICE_CLIENT_API_CONFIG } from './constants';

export const createConfirmDeviceClient = (config: ServiceClientAPIConfig) =>
export const createConfirmDeviceClient = (config: ServiceClientFactoryInput) =>
composeServiceApi(
cognitoUserPoolTransferHandler,
buildUserPoolSerializer<ConfirmDeviceCommandInput>('ConfirmDevice'),
buildUserPoolDeserializer<ConfirmDeviceCommandOutput>(),
createUserPoolSerializer<ConfirmDeviceCommandInput>('ConfirmDevice'),
createUserPoolDeserializer<ConfirmDeviceCommandOutput>(),
{
...DEFAULT_SERVICE_CLIENT_API_CONFIG,
...config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
// SPDX-License-Identifier: Apache-2.0
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';

import { ServiceClientAPIConfig } from './types/ServiceClient';
import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
buildUserPoolDeserializer,
buildUserPoolSerializer,
} from './shared/serialization';
import {
ConfirmForgotPasswordCommandInput,
ConfirmForgotPasswordCommandOutput,
} from './types/Sdk';
ServiceClientFactoryInput,
} from './types';
import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
createUserPoolDeserializer,
createUserPoolSerializer,
} from './shared/serde';
import { DEFAULT_SERVICE_CLIENT_API_CONFIG } from './constants';

export const createConfirmForgotPasswordClient = (
config: ServiceClientAPIConfig,
config: ServiceClientFactoryInput,
) =>
composeServiceApi(
cognitoUserPoolTransferHandler,
buildUserPoolSerializer<ConfirmForgotPasswordCommandInput>(
createUserPoolSerializer<ConfirmForgotPasswordCommandInput>(
'ConfirmForgotPassword',
),
buildUserPoolDeserializer<ConfirmForgotPasswordCommandOutput>(),
createUserPoolDeserializer<ConfirmForgotPasswordCommandOutput>(),
{
...DEFAULT_SERVICE_CLIENT_API_CONFIG,
...config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/
import { DEFAULT_SERVICE_CLIENT_API_CONFIG } from './constants';
import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
buildUserPoolDeserializer,
buildUserPoolSerializer,
} from './shared/serialization';
createUserPoolDeserializer,
createUserPoolSerializer,
} from './shared/serde';
import {
ConfirmSignUpCommandInput,
ConfirmSignUpCommandOutput,
} from './types/Sdk';
import { ServiceClientAPIConfig } from './types/ServiceClient';
ServiceClientFactoryInput,
} from './types';

export const createConfirmSignUpClient = (config: ServiceClientAPIConfig) =>
export const createConfirmSignUpClient = (config: ServiceClientFactoryInput) =>
composeServiceApi(
cognitoUserPoolTransferHandler,
buildUserPoolSerializer<ConfirmSignUpCommandInput>('ConfirmSignUp'),
buildUserPoolDeserializer<ConfirmSignUpCommandOutput>(),
createUserPoolSerializer<ConfirmSignUpCommandInput>('ConfirmSignUp'),
createUserPoolDeserializer<ConfirmSignUpCommandOutput>(),
{
...DEFAULT_SERVICE_CLIENT_API_CONFIG,
...config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
// SPDX-License-Identifier: Apache-2.0
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';

import { ServiceClientAPIConfig } from './types/ServiceClient';
import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
buildUserPoolDeserializer,
buildUserPoolSerializer,
} from './shared/serialization';
import {
DeleteUserAttributesCommandInput,
DeleteUserAttributesCommandOutput,
} from './types/Sdk';
ServiceClientFactoryInput,
} from './types';
import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
createUserPoolDeserializer,
createUserPoolSerializer,
} from './shared/serde';
import { DEFAULT_SERVICE_CLIENT_API_CONFIG } from './constants';

export const createDeleteUserAttributesClient = (
config: ServiceClientAPIConfig,
config: ServiceClientFactoryInput,
) =>
composeServiceApi(
cognitoUserPoolTransferHandler,
buildUserPoolSerializer<DeleteUserAttributesCommandInput>(
createUserPoolSerializer<DeleteUserAttributesCommandInput>(
'DeleteUserAttributes',
),
buildUserPoolDeserializer<DeleteUserAttributesCommandOutput>(),
createUserPoolDeserializer<DeleteUserAttributesCommandOutput>(),
{
...DEFAULT_SERVICE_CLIENT_API_CONFIG,
...config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
// SPDX-License-Identifier: Apache-2.0
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';

import { ServiceClientAPIConfig } from './types/ServiceClient';
import {
DeleteUserCommandInput,
DeleteUserCommandOutput,
ServiceClientFactoryInput,
} from './types';
import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
buildEmptyResponseDeserializer,
buildUserPoolSerializer,
} from './shared/serialization';
import { DeleteUserCommandInput, DeleteUserCommandOutput } from './types/Sdk';
createEmptyResponseDeserializer,
createUserPoolSerializer,
} from './shared/serde';
import { DEFAULT_SERVICE_CLIENT_API_CONFIG } from './constants';

export const createDeleteUserClient = (config: ServiceClientAPIConfig) =>
export const createDeleteUserClient = (config: ServiceClientFactoryInput) =>
composeServiceApi(
cognitoUserPoolTransferHandler,
buildUserPoolSerializer<DeleteUserCommandInput>('DeleteUser'),
buildEmptyResponseDeserializer<DeleteUserCommandOutput>(),
createUserPoolSerializer<DeleteUserCommandInput>('DeleteUser'),
createEmptyResponseDeserializer<DeleteUserCommandOutput>(),
{
...DEFAULT_SERVICE_CLIENT_API_CONFIG,
...config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/

import { cognitoUserPoolTransferHandler } from './shared/handler';
import {
buildEmptyResponseDeserializer,
buildUserPoolSerializer,
} from './shared/serialization';
import { ServiceClientAPIConfig } from './types/ServiceClient';
createEmptyResponseDeserializer,
createUserPoolSerializer,
} from './shared/serde';
import {
ForgetDeviceCommandInput,
ForgetDeviceCommandOutput,
} from './types/Sdk';
ServiceClientFactoryInput,
} from './types';
import { DEFAULT_SERVICE_CLIENT_API_CONFIG } from './constants';

export const createForgetDeviceClient = (config: ServiceClientAPIConfig) =>
export const createForgetDeviceClient = (config: ServiceClientFactoryInput) =>
composeServiceApi(
cognitoUserPoolTransferHandler,
buildUserPoolSerializer<ForgetDeviceCommandInput>('ForgetDevice'),
buildEmptyResponseDeserializer<ForgetDeviceCommandOutput>(),
createUserPoolSerializer<ForgetDeviceCommandInput>('ForgetDevice'),
createEmptyResponseDeserializer<ForgetDeviceCommandOutput>(),
{
...DEFAULT_SERVICE_CLIENT_API_CONFIG,
...config,
Expand Down
Loading
Loading