From 4a29da9963e9f2b02009adb345f4117afc8a0c15 Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Tue, 7 Feb 2023 16:59:30 +0100 Subject: [PATCH] DXCDT-360: Move client resources to dedicated pkg (#468) Co-authored-by: Rita Zerrizuela --- Makefile | 2 +- docs/data-sources/client.md | 4 +- docs/data-sources/global_client.md | 4 +- .../client/data_source.go} | 34 ++-- .../client/data_source_test.go} | 7 +- .../client/expand.go} | 167 +---------------- internal/auth0/client/flatten.go | 172 ++++++++++++++++++ internal/auth0/client/global_data_source.go | 32 ++++ .../client/global_data_source_test.go} | 5 +- .../client/global_resource.go} | 9 +- .../client/global_resource_test.go} | 47 ++--- .../client/resource.go} | 9 +- .../client/resource_test.go} | 43 +++-- .../data_source_auth0_global_client.go | 23 --- .../provider/data_source_auth0_tenant_test.go | 2 +- internal/provider/provider.go | 9 +- internal/provider/provider_test.go | 74 -------- .../provider/resource_auth0_action_test.go | 4 +- .../resource_auth0_attack_protection_test.go | 6 +- .../provider/resource_auth0_branding_test.go | 4 +- .../resource_auth0_branding_theme_test.go | 2 +- .../resource_auth0_client_grant_test.go | 2 +- .../resource_auth0_connection_client_test.go | 2 +- .../resource_auth0_connection_test.go | 42 ++--- .../resource_auth0_custom_domain_test.go | 2 +- ...e_auth0_custom_domain_verification_test.go | 4 +- .../resource_auth0_email_template_test.go | 2 +- .../provider/resource_auth0_email_test.go | 2 +- .../provider/resource_auth0_guardian_test.go | 12 +- internal/provider/resource_auth0_hook_test.go | 4 +- .../resource_auth0_log_stream_test.go | 18 +- ...urce_auth0_organization_connection_test.go | 2 +- ...resource_auth0_organization_member_test.go | 2 +- .../resource_auth0_organization_test.go | 2 +- .../resource_auth0_prompt_custom_text_test.go | 2 +- .../provider/resource_auth0_prompt_test.go | 2 +- .../resource_auth0_resource_server_test.go | 4 +- internal/provider/resource_auth0_role_test.go | 4 +- .../resource_auth0_rule_config_test.go | 2 +- internal/provider/resource_auth0_rule_test.go | 2 +- .../provider/resource_auth0_tenant_test.go | 4 +- .../resource_auth0_trigger_binding_test.go | 2 +- internal/provider/resource_auth0_user_test.go | 6 +- internal/provider/test_helpers.go | 81 +++++++++ internal/recorder/http_recorder.go | 12 +- 45 files changed, 461 insertions(+), 415 deletions(-) rename internal/{provider/data_source_auth0_client.go => auth0/client/data_source.go} (51%) rename internal/{provider/data_source_auth0_client_test.go => auth0/client/data_source_test.go} (90%) rename internal/{provider/structure_auth0_client.go => auth0/client/expand.go} (73%) create mode 100644 internal/auth0/client/flatten.go create mode 100644 internal/auth0/client/global_data_source.go rename internal/{provider/data_source_auth0_global_client_test.go => auth0/client/global_data_source_test.go} (88%) rename internal/{provider/resource_auth0_global_client.go => auth0/client/global_resource.go} (86%) rename internal/{provider/resource_auth0_global_client_test.go => auth0/client/global_resource_test.go} (94%) rename internal/{provider/resource_auth0_client.go => auth0/client/resource.go} (99%) rename internal/{provider/resource_auth0_client_test.go => auth0/client/resource_test.go} (97%) delete mode 100644 internal/provider/data_source_auth0_global_client.go create mode 100644 internal/provider/test_helpers.go diff --git a/Makefile b/Makefile index 3b8647156..9c8200388 100644 --- a/Makefile +++ b/Makefile @@ -157,7 +157,7 @@ test-sweep: ## Clean up test tenant ${call print_warning, "WARNING: This will destroy infrastructure. Use only in development accounts."} @read -p "Continue? [y/N] " ans && ans=$${ans:-N} ; \ if [ $${ans} = y ] || [ $${ans} = Y ]; then \ - go test ./internal/provider -v -sweep="phony" $(SWEEPARGS) ; \ + go test ./internal/provider ./internal/auth0/... -v -sweep="phony" $(SWEEPARGS) ; \ fi #----------------------------------------------------------------------------------------------------------------------- diff --git a/docs/data-sources/client.md b/docs/data-sources/client.md index e92b98c0f..4895bb901 100644 --- a/docs/data-sources/client.md +++ b/docs/data-sources/client.md @@ -1,12 +1,12 @@ --- page_title: "Data Source: auth0_client" description: |- - Data source to retrieve a specific Auth0 Application client by 'client_id' or 'name'. + Data source to retrieve a specific Auth0 application client by client_id or name. --- # Data Source: auth0_client -Data source to retrieve a specific Auth0 Application client by 'client_id' or 'name'. +Data source to retrieve a specific Auth0 application client by `client_id` or `name`. ## Example Usage diff --git a/docs/data-sources/global_client.md b/docs/data-sources/global_client.md index 4ce5cd856..3e654d78c 100644 --- a/docs/data-sources/global_client.md +++ b/docs/data-sources/global_client.md @@ -1,12 +1,12 @@ --- page_title: "Data Source: auth0_global_client" description: |- - Retrieves a tenant's global Auth0 Application client. + Retrieve a tenant's global Auth0 application client. --- # Data Source: auth0_global_client -Retrieves a tenant's global Auth0 Application client. +Retrieve a tenant's global Auth0 application client. ## Example Usage diff --git a/internal/provider/data_source_auth0_client.go b/internal/auth0/client/data_source.go similarity index 51% rename from internal/provider/data_source_auth0_client.go rename to internal/auth0/client/data_source.go index 4ddae603a..46545a600 100644 --- a/internal/provider/data_source_auth0_client.go +++ b/internal/auth0/client/data_source.go @@ -1,4 +1,4 @@ -package provider +package client import ( "context" @@ -10,27 +10,29 @@ import ( internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema" ) -func newDataClient() *schema.Resource { - clientDataSource := &schema.Resource{ - ReadContext: readDataClient, - Schema: newClientSchema(), - Description: "Data source to retrieve a specific Auth0 Application client by 'client_id' or 'name'.", +// NewDataSource will return a new auth0_client data source. +func NewDataSource() *schema.Resource { + return &schema.Resource{ + ReadContext: readClientForDataSource, + Description: "Data source to retrieve a specific Auth0 application client by `client_id` or `name`.", + Schema: dataSourceSchema(), } +} - internalSchema.SetExistingAttributesAsOptional(clientDataSource.Schema, "name", "client_id") - clientDataSource.Schema["name"].Description = "The name of the client. If not provided, `client_id` must be set." - clientDataSource.Schema["client_id"].Description = "The ID of the client. If not provided, `name` must be set." +func dataSourceSchema() map[string]*schema.Schema { + dataSourceSchema := internalSchema.TransformResourceToDataSource(NewResource().Schema) - return clientDataSource -} + delete(dataSourceSchema, "client_secret_rotation_trigger") + + internalSchema.SetExistingAttributesAsOptional(dataSourceSchema, "name", "client_id") + + dataSourceSchema["name"].Description = "The name of the client. If not provided, `client_id` must be set." + dataSourceSchema["client_id"].Description = "The ID of the client. If not provided, `name` must be set." -func newClientSchema() map[string]*schema.Schema { - clientSchema := internalSchema.TransformResourceToDataSource(newClient().Schema) - delete(clientSchema, "client_secret_rotation_trigger") - return clientSchema + return dataSourceSchema } -func readDataClient(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func readClientForDataSource(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { clientID := d.Get("client_id").(string) if clientID != "" { d.SetId(clientID) diff --git a/internal/provider/data_source_auth0_client_test.go b/internal/auth0/client/data_source_test.go similarity index 90% rename from internal/provider/data_source_auth0_client_test.go rename to internal/auth0/client/data_source_test.go index 400cd0f3f..67bb9611b 100644 --- a/internal/provider/data_source_auth0_client_test.go +++ b/internal/auth0/client/data_source_test.go @@ -1,4 +1,4 @@ -package provider +package client_test import ( "fmt" @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/auth0/terraform-provider-auth0/internal/provider" "github.com/auth0/terraform-provider-auth0/internal/recorder" "github.com/auth0/terraform-provider-auth0/internal/template" ) @@ -35,7 +36,7 @@ func TestAccDataClientByName(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), PreventPostDestroyRefresh: true, Steps: []resource.TestStep{ { @@ -56,7 +57,7 @@ func TestAccDataClientById(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), PreventPostDestroyRefresh: true, Steps: []resource.TestStep{ { diff --git a/internal/provider/structure_auth0_client.go b/internal/auth0/client/expand.go similarity index 73% rename from internal/provider/structure_auth0_client.go rename to internal/auth0/client/expand.go index 3d8e0f8d0..f370cb912 100644 --- a/internal/provider/structure_auth0_client.go +++ b/internal/auth0/client/expand.go @@ -1,4 +1,4 @@ -package provider +package client import ( "strconv" @@ -393,167 +393,6 @@ func mapFromState(input map[string]interface{}) map[string]interface{} { return output } -func flattenCustomSocialConfiguration(customSocial *management.ClientNativeSocialLogin) []interface{} { - if customSocial == nil { - return nil - } - - m := map[string]interface{}{ - "apple": []interface{}{ - map[string]interface{}{ - "enabled": customSocial.GetApple().GetEnabled(), - }, - }, - "facebook": []interface{}{ - map[string]interface{}{ - "enabled": customSocial.GetFacebook().GetEnabled(), - }, - }, - } - - return []interface{}{m} -} - -func flattenClientJwtConfiguration(jwt *management.ClientJWTConfiguration) []interface{} { - if jwt == nil { - return nil - } - - return []interface{}{ - map[string]interface{}{ - "lifetime_in_seconds": jwt.GetLifetimeInSeconds(), - "secret_encoded": jwt.GetSecretEncoded(), - "scopes": jwt.GetScopes(), - "alg": jwt.GetAlgorithm(), - }, - } -} - -func flattenClientRefreshTokenConfiguration(refreshToken *management.ClientRefreshToken) []interface{} { - if refreshToken == nil { - return nil - } - - return []interface{}{ - map[string]interface{}{ - "rotation_type": refreshToken.GetRotationType(), - "expiration_type": refreshToken.GetExpirationType(), - "leeway": refreshToken.GetLeeway(), - "token_lifetime": refreshToken.GetTokenLifetime(), - "infinite_token_lifetime": refreshToken.GetInfiniteTokenLifetime(), - "infinite_idle_token_lifetime": refreshToken.GetInfiniteIdleTokenLifetime(), - "idle_token_lifetime": refreshToken.GetIdleTokenLifetime(), - }, - } -} - -func flattenClientAddons(addons map[string]interface{}) []interface{} { - if addons == nil { - return nil - } - - m := make(map[string]interface{}) - - if v, ok := addons["samlp"]; ok { - samlp := v.(map[string]interface{}) - - samlpMap := map[string]interface{}{ - "issuer": samlp["issuer"], - "audience": samlp["audience"], - "recipient": samlp["recipient"], - "mappings": samlp["mappings"], - "create_upn_claim": samlp["createUpnClaim"], - "passthrough_claims_with_no_mapping": samlp["passthroughClaimsWithNoMapping"], - "map_unknown_claims_as_is": samlp["mapUnknownClaimsAsIs"], - "map_identities": samlp["mapIdentities"], - "signature_algorithm": samlp["signatureAlgorithm"], - "digest_algorithm": samlp["digestAlgorithm"], - "destination": samlp["destination"], - "lifetime_in_seconds": samlp["lifetimeInSeconds"], - "sign_response": samlp["signResponse"], - "name_identifier_format": samlp["nameIdentifierFormat"], - "name_identifier_probes": samlp["nameIdentifierProbes"], - "authn_context_class_ref": samlp["authnContextClassRef"], - "typed_attributes": samlp["typedAttributes"], - "include_attribute_name_format": samlp["includeAttributeNameFormat"], - "binding": samlp["binding"], - "signing_cert": samlp["signingCert"], - } - - if logout, ok := samlp["logout"].(map[string]interface{}); ok { - samlpMap["logout"] = mapToState(logout) - } - - m["samlp"] = []interface{}{samlpMap} - } - - for _, name := range []string{ - "aws", "azure_blob", "azure_sb", "rms", "mscrm", "slack", "sentry", - "box", "cloudbees", "concur", "dropbox", "echosign", "egnyte", - "firebase", "newrelic", "office365", "salesforce", "salesforce_api", - "salesforce_sandbox_api", "layer", "sap_api", "sharepoint", - "springcm", "wams", "wsfed", "zendesk", "zoom", - } { - if v, ok := addons[name]; ok { - if addonType, ok := v.(map[string]interface{}); ok { - m[name] = mapToState(addonType) - } - } - } - - return []interface{}{m} -} - -func flattenClientMobile(mobile *management.ClientMobile) []interface{} { - if mobile == nil { - return nil - } - - m := map[string]interface{}{ - "android": nil, - "ios": nil, - } - - if mobile.GetAndroid() != nil { - m["android"] = []interface{}{ - map[string]interface{}{ - "app_package_name": mobile.GetAndroid().GetAppPackageName(), - "sha256_cert_fingerprints": mobile.GetAndroid().GetKeyHashes(), - }, - } - } - - if mobile.GetIOS() != nil { - m["ios"] = []interface{}{ - map[string]interface{}{ - "team_id": mobile.GetIOS().GetTeamID(), - "app_bundle_identifier": mobile.GetIOS().GetAppID(), - }, - } - } - - return []interface{}{m} -} - -func mapToState(input map[string]interface{}) map[string]interface{} { - output := make(map[string]interface{}) - - for key, v := range input { - switch val := v.(type) { - case bool: - if val { - output[key] = "true" - } else { - output[key] = "false" - } - case float64: - output[key] = strconv.Itoa(int(val)) - case int: - output[key] = strconv.Itoa(val) - default: - output[key] = val - } - } - - return output +func clientHasChange(c *management.Client) bool { + return c.String() != "{}" } diff --git a/internal/auth0/client/flatten.go b/internal/auth0/client/flatten.go new file mode 100644 index 000000000..0a97e99ee --- /dev/null +++ b/internal/auth0/client/flatten.go @@ -0,0 +1,172 @@ +package client + +import ( + "strconv" + + "github.com/auth0/go-auth0/management" +) + +func flattenCustomSocialConfiguration(customSocial *management.ClientNativeSocialLogin) []interface{} { + if customSocial == nil { + return nil + } + + m := map[string]interface{}{ + "apple": []interface{}{ + map[string]interface{}{ + "enabled": customSocial.GetApple().GetEnabled(), + }, + }, + "facebook": []interface{}{ + map[string]interface{}{ + "enabled": customSocial.GetFacebook().GetEnabled(), + }, + }, + } + + return []interface{}{m} +} + +func flattenClientJwtConfiguration(jwt *management.ClientJWTConfiguration) []interface{} { + if jwt == nil { + return nil + } + + return []interface{}{ + map[string]interface{}{ + "lifetime_in_seconds": jwt.GetLifetimeInSeconds(), + "secret_encoded": jwt.GetSecretEncoded(), + "scopes": jwt.GetScopes(), + "alg": jwt.GetAlgorithm(), + }, + } +} + +func flattenClientRefreshTokenConfiguration(refreshToken *management.ClientRefreshToken) []interface{} { + if refreshToken == nil { + return nil + } + + return []interface{}{ + map[string]interface{}{ + "rotation_type": refreshToken.GetRotationType(), + "expiration_type": refreshToken.GetExpirationType(), + "leeway": refreshToken.GetLeeway(), + "token_lifetime": refreshToken.GetTokenLifetime(), + "infinite_token_lifetime": refreshToken.GetInfiniteTokenLifetime(), + "infinite_idle_token_lifetime": refreshToken.GetInfiniteIdleTokenLifetime(), + "idle_token_lifetime": refreshToken.GetIdleTokenLifetime(), + }, + } +} + +func flattenClientAddons(addons map[string]interface{}) []interface{} { + if addons == nil { + return nil + } + + m := make(map[string]interface{}) + + if v, ok := addons["samlp"]; ok { + samlp := v.(map[string]interface{}) + + samlpMap := map[string]interface{}{ + "issuer": samlp["issuer"], + "audience": samlp["audience"], + "recipient": samlp["recipient"], + "mappings": samlp["mappings"], + "create_upn_claim": samlp["createUpnClaim"], + "passthrough_claims_with_no_mapping": samlp["passthroughClaimsWithNoMapping"], + "map_unknown_claims_as_is": samlp["mapUnknownClaimsAsIs"], + "map_identities": samlp["mapIdentities"], + "signature_algorithm": samlp["signatureAlgorithm"], + "digest_algorithm": samlp["digestAlgorithm"], + "destination": samlp["destination"], + "lifetime_in_seconds": samlp["lifetimeInSeconds"], + "sign_response": samlp["signResponse"], + "name_identifier_format": samlp["nameIdentifierFormat"], + "name_identifier_probes": samlp["nameIdentifierProbes"], + "authn_context_class_ref": samlp["authnContextClassRef"], + "typed_attributes": samlp["typedAttributes"], + "include_attribute_name_format": samlp["includeAttributeNameFormat"], + "binding": samlp["binding"], + "signing_cert": samlp["signingCert"], + } + + if logout, ok := samlp["logout"].(map[string]interface{}); ok { + samlpMap["logout"] = mapToState(logout) + } + + m["samlp"] = []interface{}{samlpMap} + } + + for _, name := range []string{ + "aws", "azure_blob", "azure_sb", "rms", "mscrm", "slack", "sentry", + "box", "cloudbees", "concur", "dropbox", "echosign", "egnyte", + "firebase", "newrelic", "office365", "salesforce", "salesforce_api", + "salesforce_sandbox_api", "layer", "sap_api", "sharepoint", + "springcm", "wams", "wsfed", "zendesk", "zoom", + } { + if v, ok := addons[name]; ok { + if addonType, ok := v.(map[string]interface{}); ok { + m[name] = mapToState(addonType) + } + } + } + + return []interface{}{m} +} + +func flattenClientMobile(mobile *management.ClientMobile) []interface{} { + if mobile == nil { + return nil + } + + m := map[string]interface{}{ + "android": nil, + "ios": nil, + } + + if mobile.GetAndroid() != nil { + m["android"] = []interface{}{ + map[string]interface{}{ + "app_package_name": mobile.GetAndroid().GetAppPackageName(), + "sha256_cert_fingerprints": mobile.GetAndroid().GetKeyHashes(), + }, + } + } + + if mobile.GetIOS() != nil { + m["ios"] = []interface{}{ + map[string]interface{}{ + "team_id": mobile.GetIOS().GetTeamID(), + "app_bundle_identifier": mobile.GetIOS().GetAppID(), + }, + } + } + + return []interface{}{m} +} + +func mapToState(input map[string]interface{}) map[string]interface{} { + output := make(map[string]interface{}) + + for key, v := range input { + switch val := v.(type) { + case bool: + if val { + output[key] = "true" + } else { + output[key] = "false" + } + case float64: + output[key] = strconv.Itoa(int(val)) + case int: + output[key] = strconv.Itoa(val) + default: + output[key] = val + } + } + + return output +} diff --git a/internal/auth0/client/global_data_source.go b/internal/auth0/client/global_data_source.go new file mode 100644 index 000000000..13aedf904 --- /dev/null +++ b/internal/auth0/client/global_data_source.go @@ -0,0 +1,32 @@ +package client + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema" +) + +// NewGlobalDataSource will return a new auth0_global_client data source. +func NewGlobalDataSource() *schema.Resource { + return &schema.Resource{ + ReadContext: readDataGlobalClient, + Schema: globalDataSourceSchema(), + Description: "Retrieve a tenant's global Auth0 application client.", + } +} + +func globalDataSourceSchema() map[string]*schema.Schema { + dataSourceSchema := internalSchema.TransformResourceToDataSource(NewResource().Schema) + delete(dataSourceSchema, "client_secret_rotation_trigger") + return dataSourceSchema +} + +func readDataGlobalClient(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + if err := readGlobalClientID(ctx, d, m); err != nil { + return err + } + return readClient(ctx, d, m) +} diff --git a/internal/provider/data_source_auth0_global_client_test.go b/internal/auth0/client/global_data_source_test.go similarity index 88% rename from internal/provider/data_source_auth0_global_client_test.go rename to internal/auth0/client/global_data_source_test.go index 31a8286ae..75b8c210b 100644 --- a/internal/provider/data_source_auth0_global_client_test.go +++ b/internal/auth0/client/global_data_source_test.go @@ -1,4 +1,4 @@ -package provider +package client_test import ( "fmt" @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/auth0/terraform-provider-auth0/internal/provider" "github.com/auth0/terraform-provider-auth0/internal/recorder" ) @@ -19,7 +20,7 @@ func TestAccDataGlobalClient(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccGlobalClientConfigWithCustomLogin, diff --git a/internal/provider/resource_auth0_global_client.go b/internal/auth0/client/global_resource.go similarity index 86% rename from internal/provider/resource_auth0_global_client.go rename to internal/auth0/client/global_resource.go index 7b3ee6015..3972b45f8 100644 --- a/internal/provider/resource_auth0_global_client.go +++ b/internal/auth0/client/global_resource.go @@ -1,4 +1,4 @@ -package provider +package client import ( "context" @@ -8,8 +8,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func newGlobalClient() *schema.Resource { - client := newClient() +// NewGlobalResource will return a new auth0_global_client resource. +func NewGlobalResource() *schema.Resource { + client := NewResource() client.Description = "Use a tenant's global Auth0 Application client." client.CreateContext = createGlobalClient client.DeleteContext = deleteGlobalClient @@ -69,7 +70,7 @@ func readGlobalClientID(ctx context.Context, d *schema.ResourceData, m interface return nil } -func deleteGlobalClient(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func deleteGlobalClient(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics { d.SetId("") return nil } diff --git a/internal/provider/resource_auth0_global_client_test.go b/internal/auth0/client/global_resource_test.go similarity index 94% rename from internal/provider/resource_auth0_global_client_test.go rename to internal/auth0/client/global_resource_test.go index d44ac3b3c..c9d686181 100644 --- a/internal/provider/resource_auth0_global_client_test.go +++ b/internal/auth0/client/global_resource_test.go @@ -1,4 +1,4 @@ -package provider +package client_test import ( "errors" @@ -7,14 +7,36 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/auth0/terraform-provider-auth0/internal/provider" "github.com/auth0/terraform-provider-auth0/internal/recorder" ) +const testAccGlobalClientConfigEmpty = ` +` + +const testAccGlobalClientConfigDefault = ` +resource "auth0_global_client" "global" { +} +` + +const testAccGlobalClientConfigWithCustomLogin = ` +resource "auth0_global_client" "global" { + custom_login_page = "TEST123" + custom_login_page_on = true +} +` + +const testAccGlobalClientConfigNoCustomLogin = ` +resource "auth0_global_client" "global" { + custom_login_page_on = false +} +` + func TestAccGlobalClient(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccGlobalClientConfigWithCustomLogin, @@ -57,24 +79,3 @@ func TestAccGlobalClient(t *testing.T) { }, }) } - -const testAccGlobalClientConfigEmpty = ` -` - -const testAccGlobalClientConfigDefault = ` -resource "auth0_global_client" "global" { -} -` - -const testAccGlobalClientConfigWithCustomLogin = ` -resource "auth0_global_client" "global" { - custom_login_page = "TEST123" - custom_login_page_on = true -} -` - -const testAccGlobalClientConfigNoCustomLogin = ` -resource "auth0_global_client" "global" { - custom_login_page_on = false -} -` diff --git a/internal/provider/resource_auth0_client.go b/internal/auth0/client/resource.go similarity index 99% rename from internal/provider/resource_auth0_client.go rename to internal/auth0/client/resource.go index 0a3033cbb..7acd5c527 100644 --- a/internal/provider/resource_auth0_client.go +++ b/internal/auth0/client/resource.go @@ -1,4 +1,4 @@ -package provider +package client import ( "context" @@ -13,7 +13,8 @@ import ( internalValidation "github.com/auth0/terraform-provider-auth0/internal/validation" ) -func newClient() *schema.Resource { +// NewResource will return a new auth0_client resource. +func NewResource() *schema.Resource { return &schema.Resource{ CreateContext: createClient, ReadContext: readClient, @@ -845,7 +846,3 @@ func rotateClientSecret(d *schema.ResourceData, m interface{}) error { return d.Set("client_secret", client.GetClientSecret()) } - -func clientHasChange(c *management.Client) bool { - return c.String() != "{}" -} diff --git a/internal/provider/resource_auth0_client_test.go b/internal/auth0/client/resource_test.go similarity index 97% rename from internal/provider/resource_auth0_client_test.go rename to internal/auth0/client/resource_test.go index 4a676f392..f84daa87c 100644 --- a/internal/provider/resource_auth0_client_test.go +++ b/internal/auth0/client/resource_test.go @@ -1,4 +1,4 @@ -package provider +package client_test import ( "fmt" @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/auth0/terraform-provider-auth0/internal/provider" "github.com/auth0/terraform-provider-auth0/internal/recorder" "github.com/auth0/terraform-provider-auth0/internal/sweep" "github.com/auth0/terraform-provider-auth0/internal/template" @@ -16,6 +17,12 @@ func init() { sweep.Clients() } +// This is needed so that the test +// sweepers get registered. +func TestMain(m *testing.M) { + resource.TestMain(m) +} + const testAccClientValidationOnInitiateLoginURIWithHTTP = ` resource "auth0_client" "my_client" { name = "Acceptance Test - Initiate Login URI - {{.testName}}" @@ -25,7 +32,7 @@ resource "auth0_client" "my_client" { func TestAccClientInitiateLoginUriValidation(t *testing.T) { resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(nil), + ProviderFactories: provider.TestFactories(nil), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccClientValidationOnInitiateLoginURIWithHTTP, t.Name()), @@ -56,7 +63,7 @@ func TestAccClientRotateSecret(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccClientConfigRotateSecret, t.Name()), @@ -90,7 +97,7 @@ resource "auth0_client" "my_client" { func TestAccClientMobileValidationError(t *testing.T) { resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(nil), + ProviderFactories: provider.TestFactories(nil), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccClientValidationOnMobile, t.Name()), @@ -199,7 +206,7 @@ func TestAccClientMobile(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccCreateMobileClient, t.Name()), @@ -338,7 +345,7 @@ func TestAccClientRefreshToken(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccCreateClientWithRefreshToken, t.Name()), @@ -439,7 +446,7 @@ func TestAccClientJWTConfiguration(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccCreateClientWithJWTConfiguration, t.Name()), @@ -570,7 +577,7 @@ func TestAccClient(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccClientConfigCreateWithOnlyRequiredFields, t.Name()), @@ -620,14 +627,14 @@ func TestAccClient(t *testing.T) { resource.TestCheckResourceAttr("auth0_client.my_client", "refresh_token.0.rotation_type", "non-rotating"), resource.TestCheckResourceAttr("auth0_client.my_client", "refresh_token.0.token_lifetime", "2592000"), resource.TestCheckNoResourceAttr("auth0_client.my_client", "client_secret_rotation_trigger"), - resource.TestCheckNoResourceAttr("auth0_client.my_client", "client_aliases"), - resource.TestCheckNoResourceAttr("auth0_client.my_client", "callbacks"), - resource.TestCheckNoResourceAttr("auth0_client.my_client", "allowed_logout_urls"), - resource.TestCheckNoResourceAttr("auth0_client.my_client", "allowed_origins"), - resource.TestCheckNoResourceAttr("auth0_client.my_client", "allowed_clients"), - resource.TestCheckNoResourceAttr("auth0_client.my_client", "web_origins"), - resource.TestCheckNoResourceAttr("auth0_client.my_client", "encryption_key"), - resource.TestCheckNoResourceAttr("auth0_client.my_client", "client_metadata"), + resource.TestCheckResourceAttr("auth0_client.my_client", "client_aliases.#", "0"), + resource.TestCheckResourceAttr("auth0_client.my_client", "callbacks.#", "0"), + resource.TestCheckResourceAttr("auth0_client.my_client", "allowed_logout_urls.#", "0"), + resource.TestCheckResourceAttr("auth0_client.my_client", "allowed_origins.#", "0"), + resource.TestCheckResourceAttr("auth0_client.my_client", "allowed_clients.#", "0"), + resource.TestCheckResourceAttr("auth0_client.my_client", "web_origins.#", "0"), + resource.TestCheckResourceAttr("auth0_client.my_client", "encryption_key.%", "0"), + resource.TestCheckResourceAttr("auth0_client.my_client", "client_metadata.%", "0"), ), }, { @@ -847,7 +854,7 @@ func TestAccClientSSOIntegrationWithSAML(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccCreateClientWithAddons, t.Name()), @@ -930,7 +937,7 @@ func TestAccClientMetadataBehavior(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: provider.TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(` diff --git a/internal/provider/data_source_auth0_global_client.go b/internal/provider/data_source_auth0_global_client.go deleted file mode 100644 index 71eb6bcc4..000000000 --- a/internal/provider/data_source_auth0_global_client.go +++ /dev/null @@ -1,23 +0,0 @@ -package provider - -import ( - "context" - - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -func newDataGlobalClient() *schema.Resource { - return &schema.Resource{ - ReadContext: readDataGlobalClient, - Schema: newClientSchema(), - Description: "Retrieves a tenant's global Auth0 Application client.", - } -} - -func readDataGlobalClient(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - if err := readGlobalClientID(ctx, d, m); err != nil { - return err - } - return readClient(ctx, d, m) -} diff --git a/internal/provider/data_source_auth0_tenant_test.go b/internal/provider/data_source_auth0_tenant_test.go index 2b5157e41..32c7ba6af 100644 --- a/internal/provider/data_source_auth0_tenant_test.go +++ b/internal/provider/data_source_auth0_tenant_test.go @@ -31,7 +31,7 @@ func TestAccDataTenant(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccDataTenantConfig, t.Name()), diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 64afcc7a8..9256d4031 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/meta" + "github.com/auth0/terraform-provider-auth0/internal/auth0/client" "github.com/auth0/terraform-provider-auth0/internal/mutex" ) @@ -79,8 +80,8 @@ func New() *schema.Provider { }, }, ResourcesMap: map[string]*schema.Resource{ - "auth0_client": newClient(), - "auth0_global_client": newGlobalClient(), + "auth0_client": client.NewResource(), + "auth0_global_client": client.NewGlobalResource(), "auth0_client_grant": newClientGrant(), "auth0_connection": newConnection(), "auth0_custom_domain": newCustomDomain(), @@ -109,8 +110,8 @@ func New() *schema.Provider { "auth0_connection_client": newConnectionClient(), }, DataSourcesMap: map[string]*schema.Resource{ - "auth0_client": newDataClient(), - "auth0_global_client": newDataGlobalClient(), + "auth0_client": client.NewDataSource(), + "auth0_global_client": client.NewGlobalDataSource(), "auth0_tenant": newDataTenant(), }, } diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 9fb8ed496..49f692cc5 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -1,90 +1,16 @@ package provider import ( - "context" - "net/http" "os" "sort" "strings" "testing" - "github.com/auth0/go-auth0/management" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - "github.com/auth0/terraform-provider-auth0/internal/recorder" ) -func ProviderTestFactories(httpRecorder *recorder.Recorder) map[string]func() (*schema.Provider, error) { - return map[string]func() (*schema.Provider, error){ - "auth0": func() (*schema.Provider, error) { - provider := New() - - provider.ConfigureContextFunc = configureTestProvider(httpRecorder) - - return provider, nil - }, - } -} - -func configureTestProvider( - httpRecorder *recorder.Recorder, -) func(ctx context.Context, data *schema.ResourceData) (interface{}, diag.Diagnostics) { - return func(ctx context.Context, data *schema.ResourceData) (interface{}, diag.Diagnostics) { - domain := data.Get("domain").(string) - debug := data.Get("debug").(bool) - - testClient := http.DefaultClient - if httpRecorder != nil { - testClient = httpRecorder.GetDefaultClient() - } - - apiClient, err := management.New( - domain, - management.WithStaticToken("insecure"), - management.WithClient(testClient), - management.WithDebug(debug), - ) - if err != nil { - return nil, diag.FromErr(err) - } - - if domain != recorder.RecordingsDomain { - clientID := data.Get("client_id").(string) - clientSecret := data.Get("client_secret").(string) - apiToken := data.Get("api_token").(string) - audience := data.Get("audience").(string) - - authenticationOption := management.WithStaticToken(apiToken) - if apiToken == "" { - authenticationOption = management.WithClientCredentials(clientID, clientSecret) - - if audience != "" { - authenticationOption = management.WithClientCredentialsAndAudience( - clientID, - clientSecret, - audience, - ) - } - } - - apiClient, err = management.New( - domain, - authenticationOption, - management.WithClient(testClient), - management.WithDebug(debug), - ) - if err != nil { - return nil, diag.FromErr(err) - } - } - - return apiClient, nil - } -} - func TestMain(m *testing.M) { resource.TestMain(m) } diff --git a/internal/provider/resource_auth0_action_test.go b/internal/provider/resource_auth0_action_test.go index 96f22119e..3fcc916d4 100644 --- a/internal/provider/resource_auth0_action_test.go +++ b/internal/provider/resource_auth0_action_test.go @@ -109,7 +109,7 @@ func TestAccAction(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccActionConfigCreateWithOnlyRequiredFields, t.Name()), @@ -219,7 +219,7 @@ func TestAccAction_FailedBuild(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccActionConfigCreateWithFailedBuild, t.Name()), diff --git a/internal/provider/resource_auth0_attack_protection_test.go b/internal/provider/resource_auth0_attack_protection_test.go index 748d44d40..1d3a00b00 100644 --- a/internal/provider/resource_auth0_attack_protection_test.go +++ b/internal/provider/resource_auth0_attack_protection_test.go @@ -58,7 +58,7 @@ func TestAccAttackProtectionBreachedPasswordDetection(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccBreachedPasswordDetectionEnable, @@ -162,7 +162,7 @@ func TestAccAttackProtectionBruteForceProtection(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccBruteForceProtectionEnable, @@ -266,7 +266,7 @@ func TestAccAttackProtectionSuspiciousIPThrottling(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccSuspiciousIPThrottlingEnable, diff --git a/internal/provider/resource_auth0_branding_test.go b/internal/provider/resource_auth0_branding_test.go index a77b7f0b7..1047fce90 100644 --- a/internal/provider/resource_auth0_branding_test.go +++ b/internal/provider/resource_auth0_branding_test.go @@ -96,7 +96,7 @@ func TestAccBranding_WithNoCustomDomainsSet(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccTenantDisallowsUniversalLoginCustomization, @@ -113,7 +113,7 @@ func TestAccBranding(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccTenantAllowsUniversalLoginCustomization + testAccBrandingConfigCreate, diff --git a/internal/provider/resource_auth0_branding_theme_test.go b/internal/provider/resource_auth0_branding_theme_test.go index 5acf707cd..028464f53 100644 --- a/internal/provider/resource_auth0_branding_theme_test.go +++ b/internal/provider/resource_auth0_branding_theme_test.go @@ -187,7 +187,7 @@ func TestAccBrandingTheme(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccBrandingThemeCreate, diff --git a/internal/provider/resource_auth0_client_grant_test.go b/internal/provider/resource_auth0_client_grant_test.go index 1683a8845..ad8680471 100644 --- a/internal/provider/resource_auth0_client_grant_test.go +++ b/internal/provider/resource_auth0_client_grant_test.go @@ -73,7 +73,7 @@ func TestAccClientGrant(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccClientGrantConfigCreate, t.Name()), diff --git a/internal/provider/resource_auth0_connection_client_test.go b/internal/provider/resource_auth0_connection_client_test.go index 756bd04ff..1883c7d3d 100644 --- a/internal/provider/resource_auth0_connection_client_test.go +++ b/internal/provider/resource_auth0_connection_client_test.go @@ -68,7 +68,7 @@ func TestAccConnectionClient(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccCreateConnectionClient, t.Name()), diff --git a/internal/provider/resource_auth0_connection_test.go b/internal/provider/resource_auth0_connection_test.go index aad430287..7a61108ec 100644 --- a/internal/provider/resource_auth0_connection_test.go +++ b/internal/provider/resource_auth0_connection_test.go @@ -21,7 +21,7 @@ func TestAccConnection(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionConfig, t.Name()), @@ -169,7 +169,7 @@ func TestAccConnectionAD(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionADConfig, t.Name()), @@ -222,7 +222,7 @@ func TestAccConnectionAzureAD(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionAzureADConfig, t.Name()), @@ -290,7 +290,7 @@ func TestAccConnectionADFS(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionADFSConfig, t.Name()), @@ -426,7 +426,7 @@ func TestAccConnectionOIDC(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionOIDCConfig, t.Name()), @@ -543,7 +543,7 @@ func TestAccConnectionOkta(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionOktaConfig, t.Name()), @@ -657,7 +657,7 @@ func TestAccConnectionOAuth2(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionOAuth2Config, t.Name()), @@ -750,7 +750,7 @@ func TestAccConnectionSMS(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionSMSConfig, t.Name()), @@ -801,7 +801,7 @@ func TestAccConnectionCustomSMS(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionCustomSMSConfig, t.Name()), @@ -863,7 +863,7 @@ func TestAccConnectionEmail(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionEmailConfig, t.Name()), @@ -981,7 +981,7 @@ func TestAccConnectionSalesforce(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionSalesforceConfig, t.Name()), @@ -1018,7 +1018,7 @@ func TestAccConnectionGoogleOAuth2(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionGoogleOAuth2Config, t.Name()), @@ -1065,7 +1065,7 @@ func TestAccConnectionGoogleApps(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionGoogleApps, t.Name()), @@ -1118,7 +1118,7 @@ func TestAccConnectionFacebook(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionFacebookConfig, t.Name()), @@ -1185,7 +1185,7 @@ func TestAccConnectionApple(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionAppleConfig, t.Name()), @@ -1259,7 +1259,7 @@ func TestAccConnectionLinkedin(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionLinkedinConfig, t.Name()), @@ -1326,7 +1326,7 @@ func TestAccConnectionGitHub(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionGitHubConfig, t.Name()), @@ -1387,7 +1387,7 @@ func TestAccConnectionWindowslive(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionWindowsliveConfig, t.Name()), @@ -1457,7 +1457,7 @@ func TestAccConnectionConfiguration(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionConfigurationCreate, t.Name()), @@ -1631,7 +1631,7 @@ func TestAccConnectionSAML(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testConnectionSAMLConfigCreate, t.Name()), @@ -1809,7 +1809,7 @@ func TestAccConnectionTwitter(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccConnectionTwitterConfig, t.Name()), diff --git a/internal/provider/resource_auth0_custom_domain_test.go b/internal/provider/resource_auth0_custom_domain_test.go index f6e0ab998..4816c9e2c 100644 --- a/internal/provider/resource_auth0_custom_domain_test.go +++ b/internal/provider/resource_auth0_custom_domain_test.go @@ -58,7 +58,7 @@ func TestAccCustomDomain(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccCreateSelfManagedCustomDomain, strings.ToLower(t.Name())), diff --git a/internal/provider/resource_auth0_custom_domain_verification_test.go b/internal/provider/resource_auth0_custom_domain_verification_test.go index 609c2c3aa..216e3477a 100644 --- a/internal/provider/resource_auth0_custom_domain_verification_test.go +++ b/internal/provider/resource_auth0_custom_domain_verification_test.go @@ -17,7 +17,7 @@ func TestAccCustomDomainVerificationWithAuth0ManagedCerts(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccCustomDomainVerificationWithAuth0ManagedCerts, @@ -72,7 +72,7 @@ func TestAccCustomDomainVerificationWithSelfManagedCerts(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccCustomDomainVerificationWithSelfManagedCerts, diff --git a/internal/provider/resource_auth0_email_template_test.go b/internal/provider/resource_auth0_email_template_test.go index 5a30a8505..ec5fa608c 100644 --- a/internal/provider/resource_auth0_email_template_test.go +++ b/internal/provider/resource_auth0_email_template_test.go @@ -17,7 +17,7 @@ func TestAccEmailTemplate(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccEmailTemplateConfig, diff --git a/internal/provider/resource_auth0_email_test.go b/internal/provider/resource_auth0_email_test.go index b6017af18..184433b85 100644 --- a/internal/provider/resource_auth0_email_test.go +++ b/internal/provider/resource_auth0_email_test.go @@ -165,7 +165,7 @@ func TestAccEmail(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccCreateSESEmailProvider, diff --git a/internal/provider/resource_auth0_guardian_test.go b/internal/provider/resource_auth0_guardian_test.go index 5644e8f5b..e0536f2f1 100644 --- a/internal/provider/resource_auth0_guardian_test.go +++ b/internal/provider/resource_auth0_guardian_test.go @@ -54,7 +54,7 @@ func TestAccGuardian(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccGuardianEmailCreate, @@ -175,7 +175,7 @@ func TestAccGuardianPhone(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccGuardianPhoneWithCustomProviderAndNoOptions, @@ -278,7 +278,7 @@ func TestAccGuardianWebAuthnRoaming(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccConfigureWebAuthnRoamingCreate, @@ -331,7 +331,7 @@ func TestAccGuardianWebAuthnPlatform(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccConfigureWebAuthnPlatformCreate, @@ -378,7 +378,7 @@ func TestAccGuardianDUO(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccConfigureDUOCreate, @@ -471,7 +471,7 @@ func TestAccGuardianPush(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccConfigurePushCreate, diff --git a/internal/provider/resource_auth0_hook_test.go b/internal/provider/resource_auth0_hook_test.go index bf987946e..b29317ccc 100644 --- a/internal/provider/resource_auth0_hook_test.go +++ b/internal/provider/resource_auth0_hook_test.go @@ -15,7 +15,7 @@ func TestAccHook(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccHookEmpty, @@ -63,7 +63,7 @@ func TestAccHookSecrets(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: fmt.Sprintf(testAccHookCreate, testAccHookSecrets), diff --git a/internal/provider/resource_auth0_log_stream_test.go b/internal/provider/resource_auth0_log_stream_test.go index bc46c76fe..a49a252c6 100644 --- a/internal/provider/resource_auth0_log_stream_test.go +++ b/internal/provider/resource_auth0_log_stream_test.go @@ -21,7 +21,7 @@ func TestAccLogStreamHTTP(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccLogStreamHTTPConfig, t.Name()), @@ -194,7 +194,7 @@ func TestAccLogStreamEventBridge(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(logStreamAwsEventBridgeConfig, t.Name()), @@ -269,7 +269,7 @@ func TestAccLogStreamEventGrid(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(logStreamAzureEventGridConfig, t.Name()), @@ -320,7 +320,7 @@ resource "auth0_log_stream" "my_log_stream" { func TestAccLogStreamDataDogRegionValidation(t *testing.T) { resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(nil), + ProviderFactories: TestFactories(nil), Steps: []resource.TestStep{ { Config: fmt.Sprintf(logStreamDatadogInvalidConfig, "uS"), @@ -349,7 +349,7 @@ func TestAccLogStreamDatadog(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(logStreamDatadogConfig, t.Name()), @@ -417,7 +417,7 @@ func TestAccLogStreamSplunk(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(logStreamSplunkConfig, t.Name()), @@ -474,7 +474,7 @@ func TestAccLogStreamSegment(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(logStreamSegmentConfig, t.Name()), @@ -577,7 +577,7 @@ func TestAccLogStreamSumo(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(logStreamSumoConfig, t.Name()), @@ -680,7 +680,7 @@ func TestAccLogStreamMixpanel(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(logStreamMixpanelConfig, t.Name()), diff --git a/internal/provider/resource_auth0_organization_connection_test.go b/internal/provider/resource_auth0_organization_connection_test.go index c52f75fc2..2823978f3 100644 --- a/internal/provider/resource_auth0_organization_connection_test.go +++ b/internal/provider/resource_auth0_organization_connection_test.go @@ -46,7 +46,7 @@ func TestAccOrganizationConnection(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(TestAccOrganizationConnectionCreate, strings.ToLower(t.Name())), diff --git a/internal/provider/resource_auth0_organization_member_test.go b/internal/provider/resource_auth0_organization_member_test.go index d9af5efc9..3b05c7b0a 100644 --- a/internal/provider/resource_auth0_organization_member_test.go +++ b/internal/provider/resource_auth0_organization_member_test.go @@ -20,7 +20,7 @@ func TestAccOrganizationMember(t *testing.T) { testName := strings.ToLower(t.Name()) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{{ Config: template.ParseTestName(testAccOrganizationMembersAux+` resource auth0_organization_member test_member { diff --git a/internal/provider/resource_auth0_organization_test.go b/internal/provider/resource_auth0_organization_test.go index 6bad8e485..bfe91ddc1 100644 --- a/internal/provider/resource_auth0_organization_test.go +++ b/internal/provider/resource_auth0_organization_test.go @@ -113,7 +113,7 @@ func TestAccOrganization(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccOrganizationEmpty, strings.ToLower(t.Name())), diff --git a/internal/provider/resource_auth0_prompt_custom_text_test.go b/internal/provider/resource_auth0_prompt_custom_text_test.go index 73a0f5607..8a0a3d939 100644 --- a/internal/provider/resource_auth0_prompt_custom_text_test.go +++ b/internal/provider/resource_auth0_prompt_custom_text_test.go @@ -12,7 +12,7 @@ func TestAccPromptCustomText(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccPromptCustomTextCreate, diff --git a/internal/provider/resource_auth0_prompt_test.go b/internal/provider/resource_auth0_prompt_test.go index 701eba02b..aa46f71bd 100644 --- a/internal/provider/resource_auth0_prompt_test.go +++ b/internal/provider/resource_auth0_prompt_test.go @@ -42,7 +42,7 @@ func TestAccPrompt(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccPromptEmpty, diff --git a/internal/provider/resource_auth0_resource_server_test.go b/internal/provider/resource_auth0_resource_server_test.go index c2d237202..509b4a038 100644 --- a/internal/provider/resource_auth0_resource_server_test.go +++ b/internal/provider/resource_auth0_resource_server_test.go @@ -20,7 +20,7 @@ func TestAccResourceServer(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccResourceServerConfigEmpty, t.Name()), @@ -157,7 +157,7 @@ func TestAccResourceServerAuth0APIManagement(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: ` diff --git a/internal/provider/resource_auth0_role_test.go b/internal/provider/resource_auth0_role_test.go index 74553bdbf..6c5cae32c 100644 --- a/internal/provider/resource_auth0_role_test.go +++ b/internal/provider/resource_auth0_role_test.go @@ -19,7 +19,7 @@ func TestAccRole(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccRoleEmpty, t.Name()), @@ -113,7 +113,7 @@ func TestAccRolePermissions(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccRolePermissions, t.Name()), diff --git a/internal/provider/resource_auth0_rule_config_test.go b/internal/provider/resource_auth0_rule_config_test.go index c8ed94ae0..6ca913df9 100644 --- a/internal/provider/resource_auth0_rule_config_test.go +++ b/internal/provider/resource_auth0_rule_config_test.go @@ -19,7 +19,7 @@ func TestAccRuleConfig(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccRuleConfigCreate, t.Name()), diff --git a/internal/provider/resource_auth0_rule_test.go b/internal/provider/resource_auth0_rule_test.go index d4a800fe9..916b7bc11 100644 --- a/internal/provider/resource_auth0_rule_test.go +++ b/internal/provider/resource_auth0_rule_test.go @@ -15,7 +15,7 @@ func TestAccRule(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccRuleCreate, t.Name()), diff --git a/internal/provider/resource_auth0_tenant_test.go b/internal/provider/resource_auth0_tenant_test.go index 21da882e6..5c593eb3e 100644 --- a/internal/provider/resource_auth0_tenant_test.go +++ b/internal/provider/resource_auth0_tenant_test.go @@ -13,7 +13,7 @@ func TestAccTenant(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccEmptyTenant, @@ -185,7 +185,7 @@ func TestAccTenantDefaults(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: testAccEmptyTenant, diff --git a/internal/provider/resource_auth0_trigger_binding_test.go b/internal/provider/resource_auth0_trigger_binding_test.go index 84e93ff4c..3d241f5df 100644 --- a/internal/provider/resource_auth0_trigger_binding_test.go +++ b/internal/provider/resource_auth0_trigger_binding_test.go @@ -14,7 +14,7 @@ func TestAccTriggerBinding(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccTriggerBindingConfigCreate, t.Name()), diff --git a/internal/provider/resource_auth0_user_test.go b/internal/provider/resource_auth0_user_test.go index cc50e26f6..7fd908861 100644 --- a/internal/provider/resource_auth0_user_test.go +++ b/internal/provider/resource_auth0_user_test.go @@ -19,7 +19,7 @@ func init() { func TestAccUserMissingRequiredParams(t *testing.T) { resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(nil), + ProviderFactories: TestFactories(nil), Steps: []resource.TestStep{ { Config: "resource auth0_user user {}", @@ -156,7 +156,7 @@ func TestAccUser(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccUserEmpty, strings.ToLower(t.Name())), @@ -255,7 +255,7 @@ func TestAccUserChangeUsername(t *testing.T) { httpRecorder := recorder.New(t) resource.Test(t, resource.TestCase{ - ProviderFactories: ProviderTestFactories(httpRecorder), + ProviderFactories: TestFactories(httpRecorder), Steps: []resource.TestStep{ { Config: template.ParseTestName(testAccUserChangeUsernameCreate, "terra"), diff --git a/internal/provider/test_helpers.go b/internal/provider/test_helpers.go new file mode 100644 index 000000000..e62962b02 --- /dev/null +++ b/internal/provider/test_helpers.go @@ -0,0 +1,81 @@ +package provider + +import ( + "context" + "net/http" + + "github.com/auth0/go-auth0/management" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/auth0/terraform-provider-auth0/internal/recorder" +) + +// TestFactories returns the configured Auth0 provider to be used within tests. +func TestFactories(httpRecorder *recorder.Recorder) map[string]func() (*schema.Provider, error) { + return map[string]func() (*schema.Provider, error){ + "auth0": func() (*schema.Provider, error) { + auth0Provider := New() + + auth0Provider.ConfigureContextFunc = configureTestProvider(httpRecorder) + + return auth0Provider, nil + }, + } +} + +func configureTestProvider( + httpRecorder *recorder.Recorder, +) func(ctx context.Context, data *schema.ResourceData) (interface{}, diag.Diagnostics) { + return func(ctx context.Context, data *schema.ResourceData) (interface{}, diag.Diagnostics) { + domain := data.Get("domain").(string) + debug := data.Get("debug").(bool) + + testClient := http.DefaultClient + if httpRecorder != nil { + testClient = httpRecorder.GetDefaultClient() + } + + apiClient, err := management.New( + domain, + management.WithStaticToken("insecure"), + management.WithClient(testClient), + management.WithDebug(debug), + ) + if err != nil { + return nil, diag.FromErr(err) + } + + if domain != recorder.RecordingsDomain { + clientID := data.Get("client_id").(string) + clientSecret := data.Get("client_secret").(string) + apiToken := data.Get("api_token").(string) + audience := data.Get("audience").(string) + + authenticationOption := management.WithStaticToken(apiToken) + if apiToken == "" { + authenticationOption = management.WithClientCredentials(clientID, clientSecret) + + if audience != "" { + authenticationOption = management.WithClientCredentialsAndAudience( + clientID, + clientSecret, + audience, + ) + } + } + + apiClient, err = management.New( + domain, + authenticationOption, + management.WithClient(testClient), + management.WithDebug(debug), + ) + if err != nil { + return nil, diag.FromErr(err) + } + } + + return apiClient, nil + } +} diff --git a/internal/recorder/http_recorder.go b/internal/recorder/http_recorder.go index 86d239381..fde66923c 100644 --- a/internal/recorder/http_recorder.go +++ b/internal/recorder/http_recorder.go @@ -4,6 +4,8 @@ import ( "encoding/json" "net/http" "os" + "path" + "runtime" "strings" "testing" @@ -14,7 +16,7 @@ import ( ) const ( - recordingsDIR = "./../../test/data/recordings/" + recordingsDIR = "test/data/recordings/" recordingsTenant = "terraform-provider-auth0-dev" // RecordingsDomain is used for testing with our recorded http interactions. @@ -38,7 +40,7 @@ func New(t *testing.T) *Recorder { recorderTransport, err := recorder.NewWithOptions( &recorder.Options{ - CassetteName: recordingsDIR + t.Name(), + CassetteName: cassetteName(t.Name()), Mode: recorder.ModeRecordOnce, SkipRequestLatency: true, }, @@ -55,6 +57,12 @@ func New(t *testing.T) *Recorder { return &Recorder{recorderTransport} } +func cassetteName(testName string) string { + _, file, _, _ := runtime.Caller(0) + rootDir := path.Join(path.Dir(file), "../..") + return path.Join(rootDir, recordingsDIR, testName) +} + func removeSensitiveDataFromRecordings(t *testing.T, recorderTransport *recorder.Recorder) { recorderTransport.AddHook( func(i *cassette.Interaction) error {