Skip to content

Commit

Permalink
TF Generate - Handling unsupported custom domains error (#854)
Browse files Browse the repository at this point in the history
Adding handler for 403 error

Co-authored-by: Will Vedder <will.vedder@okta.com>
  • Loading branch information
willvedd and willvedd authored Sep 21, 2023
1 parent 6fe8277 commit 0a82eee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"strings"

"github.com/auth0/go-auth0/management"
"github.com/google/uuid"
Expand Down Expand Up @@ -202,6 +203,10 @@ func (f *customDomainResourceFetcher) FetchData(ctx context.Context) (importData

customDomains, err := f.api.CustomDomain.List(ctx)
if err != nil {
if strings.Contains(err.Error(), "The account is not allowed to perform this operation, please contact our support team") {
return data, nil
}

return nil, err
}

Expand Down
20 changes: 20 additions & 0 deletions internal/cli/terraform_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,26 @@ func TestCustomDomainResourceFetcher_FetchData(t *testing.T) {
_, err := fetcher.FetchData(context.Background())
assert.EqualError(t, err, "failed to list custom domains")
})

t.Run("it returns empty set error if unsupported feature error occurs", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

customDomainAPI := mock.NewMockCustomDomainAPI(ctrl)
customDomainAPI.EXPECT().
List(gomock.Any()).
Return(nil, fmt.Errorf("403 Forbidden: The account is not allowed to perform this operation, please contact our support team"))

fetcher := customDomainResourceFetcher{
api: &auth0.API{
CustomDomain: customDomainAPI,
},
}

data, err := fetcher.FetchData(context.Background())
assert.NoError(t, err)
assert.Len(t, data, 0)
})
}

func TestGuardianResourceFetcher_FetchData(t *testing.T) {
Expand Down

0 comments on commit 0a82eee

Please sign in to comment.