From 0a4b89a3f8d0f97a4c01af6ce5bea2b841feb0e0 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Thu, 26 Dec 2024 10:43:27 -0700 Subject: [PATCH 1/3] fix(cognito-userpool): include user attribute update settings --- resources/cognito-userpool.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/resources/cognito-userpool.go b/resources/cognito-userpool.go index 33fd6e82..897576e1 100644 --- a/resources/cognito-userpool.go +++ b/resources/cognito-userpool.go @@ -99,13 +99,21 @@ type CognitoUserPool struct { func (r *CognitoUserPool) Remove(_ context.Context) error { if r.settings.GetBool("DisableDeletionProtection") { - _, err := r.svc.UpdateUserPool(&cognitoidentityprovider.UpdateUserPoolInput{ - UserPoolId: r.ID, - DeletionProtection: ptr.String("INACTIVE"), + userPool, err := r.svc.DescribeUserPool(&cognitoidentityprovider.DescribeUserPoolInput{ + UserPoolId: r.ID, }) if err != nil { return err } + + _, updateErr := r.svc.UpdateUserPool(&cognitoidentityprovider.UpdateUserPoolInput{ + UserPoolId: r.ID, + DeletionProtection: ptr.String("INACTIVE"), + UserAttributeUpdateSettings: userPool.UserPool.UserAttributeUpdateSettings, + }) + if updateErr != nil { + return updateErr + } } _, err := r.svc.DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{ From 593b1c617e24d971faaad0111a0f32274ad91557 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Thu, 26 Dec 2024 11:05:08 -0700 Subject: [PATCH 2/3] fix(cognito-userpool): include auto verified attributes --- resources/cognito-userpool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/cognito-userpool.go b/resources/cognito-userpool.go index 897576e1..fd528d73 100644 --- a/resources/cognito-userpool.go +++ b/resources/cognito-userpool.go @@ -110,6 +110,7 @@ func (r *CognitoUserPool) Remove(_ context.Context) error { UserPoolId: r.ID, DeletionProtection: ptr.String("INACTIVE"), UserAttributeUpdateSettings: userPool.UserPool.UserAttributeUpdateSettings, + AutoVerifiedAttributes: userPool.UserPool.AutoVerifiedAttributes, }) if updateErr != nil { return updateErr From 1e64bc0a4d627d0b55e6a72c0e38780a06df6349 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Thu, 26 Dec 2024 11:05:42 -0700 Subject: [PATCH 3/3] test(cognito-userpool): fix tests to account for new changes --- resources/cognito-userpool_mock_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/resources/cognito-userpool_mock_test.go b/resources/cognito-userpool_mock_test.go index fc0bfa57..32244630 100644 --- a/resources/cognito-userpool_mock_test.go +++ b/resources/cognito-userpool_mock_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/golang/mock/gomock" + "github.com/gotidy/ptr" "github.com/stretchr/testify/assert" "github.com/aws/aws-sdk-go/aws" @@ -85,9 +86,24 @@ func Test_Mock_CognitoUserPool_Remove_DeletionProtection(t *testing.T) { mockSvc := mock_cognitoidentityprovideriface.NewMockCognitoIdentityProviderAPI(ctrl) + mockSvc.EXPECT().DescribeUserPool(&cognitoidentityprovider.DescribeUserPoolInput{ + UserPoolId: aws.String("test-pool-id"), + }).Return(&cognitoidentityprovider.DescribeUserPoolOutput{ + UserPool: &cognitoidentityprovider.UserPoolType{ + UserAttributeUpdateSettings: &cognitoidentityprovider.UserAttributeUpdateSettingsType{ + AttributesRequireVerificationBeforeUpdate: []*string{ptr.String("email")}, + }, + AutoVerifiedAttributes: []*string{ptr.String("email")}, + }, + }, nil) + mockSvc.EXPECT().UpdateUserPool(&cognitoidentityprovider.UpdateUserPoolInput{ UserPoolId: aws.String("test-pool-id"), DeletionProtection: aws.String("INACTIVE"), + UserAttributeUpdateSettings: &cognitoidentityprovider.UserAttributeUpdateSettingsType{ + AttributesRequireVerificationBeforeUpdate: []*string{ptr.String("email")}, + }, + AutoVerifiedAttributes: []*string{ptr.String("email")}, }).Return(&cognitoidentityprovider.UpdateUserPoolOutput{}, nil) mockSvc.EXPECT().DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{