diff --git a/.changeset/eighty-feet-go.md b/.changeset/eighty-feet-go.md new file mode 100644 index 00000000000..aad4be62f3d --- /dev/null +++ b/.changeset/eighty-feet-go.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/backend-auth': patch +--- + +Add unit tests for custom domain and cognito-managed domain OAuth scenarios diff --git a/packages/backend-auth/src/lambda/reference_auth_initializer.test.ts b/packages/backend-auth/src/lambda/reference_auth_initializer.test.ts index a2b9dba597f..c429ed83caf 100644 --- a/packages/backend-auth/src/lambda/reference_auth_initializer.test.ts +++ b/packages/backend-auth/src/lambda/reference_auth_initializer.test.ts @@ -311,6 +311,38 @@ void describe('ReferenceAuthInitializer', () => { ); }); + void it('handles custom domain with external login providers', async () => { + describeUserPoolResponse = { + ...httpSuccess, + UserPool: { + ...UserPool, + CustomDomain: 'auth.dev.example.com', + }, + }; + const result = await handler.handleEvent(createCfnEvent); + assert.strictEqual(result.Status, 'SUCCESS'); + assert.ok(result.Data); + assert.strictEqual(result.Data.oauthCognitoDomain, 'auth.dev.example.com'); + }); + + void it('handles cognito-managed domain with external login providers', async () => { + describeUserPoolResponse = { + ...httpSuccess, + UserPool: { + ...UserPool, + CustomDomain: undefined, + Domain: 'ref-auth-userpool-1', + }, + }; + const result = await handler.handleEvent(createCfnEvent); + assert.strictEqual(result.Status, 'SUCCESS'); + assert.ok(result.Data); + assert.strictEqual( + result.Data.oauthCognitoDomain, + 'ref-auth-userpool-1.auth.us-east-1.amazoncognito.com', + ); + }); + void it('throws if user pool group is not found', async () => { listGroupsResponse = { ...httpSuccess, diff --git a/packages/backend-auth/src/lambda/reference_auth_initializer.ts b/packages/backend-auth/src/lambda/reference_auth_initializer.ts index 29e9aa18c3a..f25e0c4ec0a 100644 --- a/packages/backend-auth/src/lambda/reference_auth_initializer.ts +++ b/packages/backend-auth/src/lambda/reference_auth_initializer.ts @@ -459,7 +459,9 @@ export class ReferenceAuthInitializer { // domain const oauthDomain = userPool.CustomDomain ?? userPool.Domain ?? ''; - const fullDomainPath = `${oauthDomain}.auth.${region}.amazoncognito.com`; + const fullDomainPath = userPool.CustomDomain + ? userPool.CustomDomain + : `${oauthDomain}.auth.${region}.amazoncognito.com`; const data = { signupAttributes: JSON.stringify( userPool.SchemaAttributes?.filter(