Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXCDT-94 Stop ignoring errors when setting resource data within the client #94

Merged
merged 3 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion auth0/data_source_auth0_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func newDataClient() *schema.Resource {
func newClientSchema() map[string]*schema.Schema {
clientSchema := datasourceSchemaFromResourceSchema(newClient().Schema)
delete(clientSchema, "client_secret_rotation_trigger")
delete(clientSchema, "client_secret")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we are reusing the same schema as the client resource, if we delete the client_secret from here, when reading an entire client we will be getting an error when setting client_secret within the readClient() func as it's not present in the schema any more.

This should have never been deleted here because of this reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had originally agreed to omit client_secret from the data source. Unless I'm missing it down below, this change appears to repeal that decision (confirmed by the change in the test). I see that this method of deletion is problematic but it would be wise to scrub the client secret some other way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's indeed true, however at the time we weren't aware that this would lead to an unsurfaced error. Considering the resource already has the client_secret and this is something that the API simply returns, if not using the data_source we always have access to it through the resource. Having the client_secret will also help a lot with passing that information to other providers / resources for configuration purposes.

addOptionalFieldsToSchema(clientSchema, "name", "client_id")
return clientSchema
}
Expand Down
10 changes: 7 additions & 3 deletions auth0/data_source_auth0_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ func TestAccDataClientByName(t *testing.T) {
PreventPostDestroyRefresh: true,
Steps: []resource.TestStep{
{
Config: random.Template(testAccClientConfig, rand), // must initialize resource before reading with data source
Config: random.Template(testAccClientConfig, rand),
Check: resource.ComposeTestCheckFunc(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After initializing the resource we just wanna make extra sure the client got created correctly so we can fetch it within the client data source below.

resource.TestCheckResourceAttr("auth0_client.my_client", "name", fmt.Sprintf("Acceptance Test - %v", rand)),
), // check that the client got created correctly before using the data source
},
{
Config: random.Template(fmt.Sprintf(testAccDataClientConfigByName, testAccClientConfig), rand),
Expand All @@ -44,7 +47,6 @@ func TestAccDataClientByName(t *testing.T) {
resource.TestCheckResourceAttr("data.auth0_client.test", "name", fmt.Sprintf("Acceptance Test - %v", rand)),
resource.TestCheckResourceAttr("data.auth0_client.test", "app_type", "non_interactive"), // Arbitrary property selection
resource.TestCheckNoResourceAttr("data.auth0_client.test", "client_secret_rotation_trigger"),
resource.TestCheckNoResourceAttr("data.auth0_client.test", "client_secret"),
),
},
},
Expand All @@ -62,6 +64,9 @@ func TestAccDataClientById(t *testing.T) {
Steps: []resource.TestStep{
{
Config: random.Template(testAccClientConfig, rand),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "name", fmt.Sprintf("Acceptance Test - %v", rand)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After initializing the resource we just wanna make extra sure the client got created correctly so we can fetch it within the client data source below.

), // check that the client got created correctly before using the data source
},
{
Config: random.Template(fmt.Sprintf(testAccDataClientConfigById, testAccClientConfig), rand),
Expand All @@ -70,7 +75,6 @@ func TestAccDataClientById(t *testing.T) {
resource.TestCheckResourceAttrSet("data.auth0_client.test", "name"),
resource.TestCheckResourceAttr("data.auth0_client.test", "signing_keys.#", "1"), // checks that signing_keys is set, and it includes 1 element
resource.TestCheckNoResourceAttr("data.auth0_client.test", "client_secret_rotation_trigger"),
resource.TestCheckNoResourceAttr("data.auth0_client.test", "client_secret"),
),
},
},
Expand Down
1 change: 0 additions & 1 deletion auth0/data_source_auth0_global_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestAccDataGlobalClient(t *testing.T) {
resource.TestCheckResourceAttrSet("data.auth0_global_client.global", "client_id"),
resource.TestCheckResourceAttr("data.auth0_global_client.global", "app_type", ""),
resource.TestCheckResourceAttr("data.auth0_global_client.global", "name", "All Applications"),
resource.TestCheckNoResourceAttr("data.auth0_global_client.global", "client_secret"),
),
},
},
Expand Down
Loading