diff --git a/packages/amplify-e2e-core/src/utils/sdk-calls.ts b/packages/amplify-e2e-core/src/utils/sdk-calls.ts index 1c95c74d621..8f524cefedc 100644 --- a/packages/amplify-e2e-core/src/utils/sdk-calls.ts +++ b/packages/amplify-e2e-core/src/utils/sdk-calls.ts @@ -195,6 +195,20 @@ export const getSocialIdpProvider = async ( return res; }; +export const getUserPoolDomain = async (domain: string, region: string) => { + let res; + try { + res = await new CognitoIdentityServiceProvider({ region }) + .describeUserPoolDomain({ + Domain: domain, + }) + .promise(); + } catch (err) { + console.log(err); + } + return res; +}; + export const getIdentityPoolRoles = async (identityPoolId: string, region: string) => { let res; diff --git a/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration.test.ts b/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration.test.ts index 225901168cb..d37e26391cc 100644 --- a/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration.test.ts +++ b/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration.test.ts @@ -9,10 +9,12 @@ import { createUserPoolOnlyWithOAuthSettings, deleteProject, deleteProjectDir, + deleteUserPoolDomain, generateRandomShortId, getHostedUIDomain, getProjectMeta, getUserPool, + getUserPoolDomain, getUserPoolId, updateAuthAddUserGroups, updateHeadlessAuth, @@ -116,5 +118,54 @@ describe('amplify auth hosted ui', () => { expect(hostedUIDomain).toEqual(originalHostedUIDomain); expect(hostedUIDomain).toEqual(userPoolRes.UserPool.Domain); }); + + it('updates hosted ui domain headless with new version and pushes', async () => { + const updatedDomainPrefix = `new-prefix-${generateRandomShortId()}`; + const updateAuthRequest: UpdateAuthRequest = { + version: 2, + serviceModification: { + serviceName: 'Cognito', + userPoolModification: { + autoVerifiedAttributes: [ + { + type: 'EMAIL', + }, + ], + userPoolGroups: [ + { + groupName: 'group1', + }, + { + groupName: 'group2', + }, + ], + oAuth: { + domainPrefix: updatedDomainPrefix, + }, + }, + includeIdentityPool: false, + }, + }; + + await updateHeadlessAuth(projRoot, updateAuthRequest, { testingWithLatestCodebase: true }); + await amplifyPushNonInteractive(projRoot, true); + const userPoolId = getUserPoolId(projRoot); + const hostedUIDomain = getHostedUIDomain(projRoot); + + expect(userPoolId).toEqual(originalUserPoolId); + const userPoolRes = await getUserPool(userPoolId, region); + expect(hostedUIDomain).not.toEqual(originalHostedUIDomain); + expect(hostedUIDomain).toMatch(updatedDomainPrefix); + expect(hostedUIDomain).toEqual(userPoolRes.UserPool.Domain); + + const updatedDomainRes = await getUserPoolDomain(hostedUIDomain, region); + expect(updatedDomainRes).toBeDefined(); + const originalDomainRes = await getUserPoolDomain(originalHostedUIDomain, region); + expect(originalDomainRes).toEqual({ DomainDescription: {} }); + + const deleteOriginalDomainRes = await deleteUserPoolDomain(originalHostedUIDomain, userPoolId, region); + // undefined response as it throws InvalidParameterException: No such domain or user pool exists. + expect(deleteOriginalDomainRes).toBeUndefined(); + }); }); });