Skip to content

Commit

Permalink
PATCH: Add graceful error handling for auth0_organization data sour…
Browse files Browse the repository at this point in the history
…ce when using client grants (#1049)

* Added check on tenants which has insufficient scopes and return a empty slice

* Updated test case

* minor refactoring

* minor refactor

* linting

* linting
  • Loading branch information
duedares-rvj authored Oct 14, 2024
1 parent de35ea1 commit 483152e
Show file tree
Hide file tree
Showing 3 changed files with 449 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/auth0/organization/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package organization

import (
"context"
"strings"

"github.com/auth0/go-auth0/management"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -195,6 +196,9 @@ func fetchAllOrganizationClientGrants(
) ([]*management.ClientGrant, error) {
clientGrantList, err := api.Organization.ClientGrants(ctx, organizationID)
if err != nil {
if strings.Contains(err.Error(), "Insufficient scope") {
return []*management.ClientGrant{}, nil
}
return nil, err
}

Expand Down
22 changes: 22 additions & 0 deletions internal/auth0/organization/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,25 @@ func TestAccDataSourceOrganization(t *testing.T) {
},
})
}

func TestAccDataSourceOrganizationInsufficientScope(t *testing.T) {
acctest.Test(t, resource.TestCase{
PreventPostDestroyRefresh: true,
Steps: []resource.TestStep{
{
// Uncomment the below code to test functionality against a non enabled tenants and record it.
//PreConfig: func() {
// // Add your env variables here.
// _ = os.Setenv("AUTH0_DOMAIN", "some-domain-name")
// _ = os.Setenv("AUTH0_CLIENT_ID", "some-client-id")
// _ = os.Setenv("AUTH0_CLIENT_SECRET", "some-client-secret")
// },.
Config: `data "auth0_organization" "test" {
organization_id = "org_P0nITxTkwnKQvD22"
}`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.auth0_organization.test", "grant_ids.#", "0")),
},
},
})
}
Loading

0 comments on commit 483152e

Please sign in to comment.