Skip to content

Commit

Permalink
Merge pull request #478 from ekristen/fix-cognito-userpool
Browse files Browse the repository at this point in the history
fix(cognito-userpool): include user attribute update settings
  • Loading branch information
ekristen authored Dec 26, 2024
2 parents d7a7494 + 1e64bc0 commit 74900bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 12 additions & 3 deletions resources/cognito-userpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,22 @@ 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,
AutoVerifiedAttributes: userPool.UserPool.AutoVerifiedAttributes,
})
if updateErr != nil {
return updateErr
}
}

_, err := r.svc.DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{
Expand Down
16 changes: 16 additions & 0 deletions resources/cognito-userpool_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 74900bb

Please sign in to comment.