diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e177b3..f320ee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog +### 3.3.5 + +#### Enhancements + +- Extend custom provider resource to support custom provider new api contract. + ### 3.3.4 #### Enhancements diff --git a/helpers/cidaas/custom_provider.go b/helpers/cidaas/custom_provider.go index b686151..08d8a7b 100644 --- a/helpers/cidaas/custom_provider.go +++ b/helpers/cidaas/custom_provider.go @@ -19,19 +19,23 @@ type ScopeChild struct { Recommended bool `json:"recommended,omitempty"` } type CustomProviderModel struct { - ID string `json:"_id,omitempty"` - ClientID string `json:"client_id,omitempty"` - ClientSecret string `json:"client_secret,omitempty"` - DisplayName string `json:"display_name,omitempty"` - StandardType string `json:"standard_type,omitempty"` - AuthorizationEndpoint string `json:"authorization_endpoint,omitempty"` - TokenEndpoint string `json:"token_endpoint,omitempty"` - ProviderName string `json:"provider_name,omitempty"` - LogoURL string `json:"logo_url,omitempty"` - UserinfoEndpoint string `json:"userinfo_endpoint,omitempty"` - UserinfoFields map[string]string `json:"userinfo_fields,omitempty"` - Scopes Scopes `json:"scopes,omitempty"` - Domains []string `json:"domains,omitempty"` + ID string `json:"_id,omitempty"` + ClientID string `json:"client_id,omitempty"` + ClientSecret string `json:"client_secret,omitempty"` + DisplayName string `json:"display_name,omitempty"` + StandardType string `json:"standard_type,omitempty"` + AuthorizationEndpoint string `json:"authorization_endpoint,omitempty"` + TokenEndpoint string `json:"token_endpoint,omitempty"` + ProviderName string `json:"provider_name,omitempty"` + LogoURL string `json:"logo_url,omitempty"` + UserinfoEndpoint string `json:"userinfo_endpoint,omitempty"` + UserinfoFields map[string]*UserInfoField `json:"userInfoFields,omitempty"` + Scopes Scopes `json:"scopes,omitempty"` + Domains []string `json:"domains,omitempty"` +} + +type UserInfoField struct { + ExtFieldKey string `json:"extFieldKey"` } type CustomProviderResponse struct { diff --git a/internal/resources/resource_custom_provider.go b/internal/resources/resource_custom_provider.go index a7ee1ad..54d0c31 100644 --- a/internal/resources/resource_custom_provider.go +++ b/internal/resources/resource_custom_provider.go @@ -336,32 +336,65 @@ func (r *CustomProvider) Read(ctx context.Context, req resource.ReadRequest, res return } - metadataAttributeTypes := map[string]attr.Type{} - metadataAttributes := map[string]attr.Value{} - customFields := map[string]attr.Value{} + metadataAttributeTypes := map[string]attr.Type{ + "name": types.StringType, + "family_name": types.StringType, + "given_name": types.StringType, + "middle_name": types.StringType, + "nickname": types.StringType, + "preferred_username": types.StringType, + "profile": types.StringType, + "picture": types.StringType, + "website": types.StringType, + "gender": types.StringType, + "birthdate": types.StringType, + "zoneinfo": types.StringType, + "locale": types.StringType, + "updated_at": types.StringType, + "email": types.StringType, + "email_verified": types.StringType, + "phone_number": types.StringType, + "mobile_number": types.StringType, + "address": types.StringType, + "sub": types.StringType, + } + metadataAttributes := map[string]attr.Value{ + "name": types.StringNull(), + "family_name": types.StringNull(), + "given_name": types.StringNull(), + "middle_name": types.StringNull(), + "nickname": types.StringNull(), + "preferred_username": types.StringNull(), + "profile": types.StringNull(), + "picture": types.StringNull(), + "website": types.StringNull(), + "gender": types.StringNull(), + "birthdate": types.StringNull(), + "zoneinfo": types.StringNull(), + "locale": types.StringNull(), + "updated_at": types.StringNull(), + "email": types.StringNull(), + "email_verified": types.StringNull(), + "phone_number": types.StringNull(), + "mobile_number": types.StringNull(), + "address": types.StringNull(), + "sub": types.StringNull(), + } + + customFields := map[string]attr.Value{} hasCustomfield := false - for key, value := range res.Data.UserinfoFields { - val := value - supportedUserInfoFields := []string{ - "name", "family_name", "given_name", "middle_name", "nickname", "preferred_username", - "profile", "picture", "website", "gender", "birthdate", "zoneinfo", "locale", "updated_at", "email", "email_verified", - "phone_number", "mobile_number", "address", "sub", - } + + for key, field := range res.Data.UserinfoFields { if strings.HasPrefix(key, "customFields.") { - customFields[strings.TrimPrefix(key, "customFields.")] = util.StringValueOrNull(&val) + customFieldKey := strings.TrimPrefix(key, "customFields.") + customFields[customFieldKey] = types.StringValue(field.ExtFieldKey) hasCustomfield = true - } else if util.StringInSlice(key, supportedUserInfoFields) { - metadataAttributeTypes[key] = types.StringType - metadataAttributes[key] = util.StringValueOrNull(&val) + } else if _, exists := metadataAttributes[key]; exists { + metadataAttributes[key] = types.StringValue(field.ExtFieldKey) } } - // The sub attribute is handled separately to support in userinfo configuration. The attribute is not available in admin ui - if _, exists := metadataAttributes["sub"]; !exists { - metadataAttributeTypes["sub"] = types.StringType - metadataAttributes["sub"] = types.StringNull() - } metadataAttributeTypes["custom_fields"] = types.MapType{ElemType: types.StringType} if hasCustomfield { metadataAttributes["custom_fields"] = types.MapValueMust(types.StringType, customFields) @@ -443,42 +476,87 @@ func prepareCpRequestPayload(ctx context.Context, plan ProviderConfig) (*cidaas. cp.Scopes.Scopes = childScopes cp.Scopes.DisplayLabel = plan.ScopeDisplayLabel.ValueString() - uf := map[string]string{} - if !plan.UserinfoFields.IsNull() { - uf["name"] = plan.userinfoFields.Name.ValueString() - uf["family_name"] = plan.userinfoFields.FamilyName.ValueString() - uf["given_name"] = plan.userinfoFields.GivenName.ValueString() - uf["middle_name"] = plan.userinfoFields.MiddleName.ValueString() - uf["nickname"] = plan.userinfoFields.Nickname.ValueString() - uf["preferred_username"] = plan.userinfoFields.PreferredUsername.ValueString() - uf["profile"] = plan.userinfoFields.Profile.ValueString() - uf["picture"] = plan.userinfoFields.Picture.ValueString() - uf["website"] = plan.userinfoFields.Website.ValueString() - uf["gender"] = plan.userinfoFields.Gender.ValueString() - uf["birthdate"] = plan.userinfoFields.Birthdate.ValueString() - uf["zoneinfo"] = plan.userinfoFields.Zoneinfo.ValueString() - uf["locale"] = plan.userinfoFields.Locale.ValueString() - uf["updated_at"] = plan.userinfoFields.UpdatedAt.ValueString() - uf["email"] = plan.userinfoFields.Email.ValueString() - uf["email_verified"] = plan.userinfoFields.EmailVerified.ValueString() - uf["phone_number"] = plan.userinfoFields.PhoneNumber.ValueString() - uf["mobile_number"] = plan.userinfoFields.MobileNumber.ValueString() - uf["address"] = plan.userinfoFields.Address.ValueString() - uf["sub"] = plan.userinfoFields.Sub.ValueString() - - if len(plan.userinfoFields.CustomFields.Elements()) > 0 { + // Initialize the map + cp.UserinfoFields = make(map[string]*cidaas.UserInfoField) + + // Add standard fields + if !plan.userinfoFields.Name.IsNull() { + cp.UserinfoFields["name"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Name.ValueString()} + } + if !plan.userinfoFields.FamilyName.IsNull() { + cp.UserinfoFields["family_name"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.FamilyName.ValueString()} + } + if !plan.userinfoFields.GivenName.IsNull() { + cp.UserinfoFields["given_name"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.GivenName.ValueString()} + } + if !plan.userinfoFields.MiddleName.IsNull() { + cp.UserinfoFields["middle_name"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.MiddleName.ValueString()} + } + if !plan.userinfoFields.Nickname.IsNull() { + cp.UserinfoFields["nickname"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Nickname.ValueString()} + } + if !plan.userinfoFields.PreferredUsername.IsNull() { + cp.UserinfoFields["preferred_username"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.PreferredUsername.ValueString()} + } + if !plan.userinfoFields.Profile.IsNull() { + cp.UserinfoFields["profile"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Profile.ValueString()} + } + if !plan.userinfoFields.Picture.IsNull() { + cp.UserinfoFields["picture"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Picture.ValueString()} + } + if !plan.userinfoFields.Website.IsNull() { + cp.UserinfoFields["website"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Website.ValueString()} + } + if !plan.userinfoFields.Gender.IsNull() { + cp.UserinfoFields["gender"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Gender.ValueString()} + } + if !plan.userinfoFields.Birthdate.IsNull() { + cp.UserinfoFields["birthdate"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Birthdate.ValueString()} + } + if !plan.userinfoFields.Zoneinfo.IsNull() { + cp.UserinfoFields["zoneinfo"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Zoneinfo.ValueString()} + } + if !plan.userinfoFields.Locale.IsNull() { + cp.UserinfoFields["locale"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Locale.ValueString()} + } + if !plan.userinfoFields.UpdatedAt.IsNull() { + cp.UserinfoFields["updated_at"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.UpdatedAt.ValueString()} + } + if !plan.userinfoFields.Email.IsNull() { + cp.UserinfoFields["email"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Email.ValueString()} + } + if !plan.userinfoFields.EmailVerified.IsNull() { + cp.UserinfoFields["email_verified"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.EmailVerified.ValueString()} + } + if !plan.userinfoFields.PhoneNumber.IsNull() { + cp.UserinfoFields["phone_number"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.PhoneNumber.ValueString()} + } + if !plan.userinfoFields.MobileNumber.IsNull() { + cp.UserinfoFields["mobile_number"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.MobileNumber.ValueString()} + } + if !plan.userinfoFields.Address.IsNull() { + cp.UserinfoFields["address"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Address.ValueString()} + } + if !plan.userinfoFields.Sub.IsNull() { + cp.UserinfoFields["sub"] = &cidaas.UserInfoField{ExtFieldKey: plan.userinfoFields.Sub.ValueString()} + } + + // Handle custom fields + if !plan.userinfoFields.CustomFields.IsNull() { var cfMap map[string]string diag = plan.userinfoFields.CustomFields.ElementsAs(ctx, &cfMap, false) if diag.HasError() { return nil, diag } - for k, v := range cfMap { - uf["customFields."+k] = v + + // Add custom fields with "customFields." prefix + for key, value := range cfMap { + cp.UserinfoFields["customFields."+key] = &cidaas.UserInfoField{ExtFieldKey: value} } } } - cp.UserinfoFields = uf + return &cp, nil } diff --git a/internal/resources/resource_custom_provider_test.go b/internal/resources/resource_custom_provider_test.go index 2438119..5ff236c 100644 --- a/internal/resources/resource_custom_provider_test.go +++ b/internal/resources/resource_custom_provider_test.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "regexp" + "strconv" "testing" "github.com/Cidaas/terraform-provider-cidaas/helpers/cidaas" @@ -30,101 +31,101 @@ var ( ) // create, read and update test -// func TestAccCustomProviderResource_Basic(t *testing.T) { -// updatedDisplayName := "Updated Sample Terraform" -// updatedOauth2StandardType := "OPENID_CONNECT" -// updatedAuthorizationEndpoint := "https://cidaas.de/authz-srv/v2/authz" -// updatedTokenEndpoint := "https://cidaas.de/token-srv/v2/token" //nolint:gosec -// updatedLogoURL := "https://cidaas.de/v2/logo" -// updatedUserinfoEndpoint := "https://cidaas.de/users-srv/v2/userinfo" -// updatedScopeDisplayLabel := "updated terraform sample scope display name" -// updatedClientID := acctest.RandString(10) -// updatedClientSecret := acctest.RandString(10) -// resource.Test(t, resource.TestCase{ -// PreCheck: func() { acctest.TestAccPreCheck(t) }, -// ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, -// CheckDestroy: checkCustomProviderDestroyed, -// Steps: []resource.TestStep{ -// { -// Config: resourceCustomProviderConfig(oauth2StandardType, providerName), -// Check: resource.ComposeAggregateTestCheckFunc( -// resource.TestCheckResourceAttr(resourceCustomProvider, "standard_type", oauth2StandardType), -// resource.TestCheckResourceAttr(resourceCustomProvider, "authorization_endpoint", authorizationEndpoint), -// resource.TestCheckResourceAttr(resourceCustomProvider, "token_endpoint", tokenEndpoint), -// resource.TestCheckResourceAttr(resourceCustomProvider, "provider_name", providerName), -// resource.TestCheckResourceAttr(resourceCustomProvider, "display_name", displayName), -// resource.TestCheckResourceAttr(resourceCustomProvider, "logo_url", logoURL), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_endpoint", userinfoEndpoint), -// resource.TestCheckResourceAttr(resourceCustomProvider, "scope_display_label", scopeDisplayLabel), -// resource.TestCheckResourceAttr(resourceCustomProvider, "client_id", clientID), -// resource.TestCheckResourceAttr(resourceCustomProvider, "client_secret", clientSecret), -// resource.TestCheckResourceAttr(resourceCustomProvider, "domains.0", "cidaas.de"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "domains.1", "cidaas.org"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.recommended", strconv.FormatBool(true)), -// resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.required", strconv.FormatBool(true)), -// resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.scope_name", "email"), -// resource.TestCheckResourceAttrSet(resourceCustomProvider, "id"), -// ), -// }, -// { -// ResourceName: resourceCustomProvider, -// ImportState: true, -// ImportStateVerify: true, -// ImportStateId: providerName, -// }, -// { -// Config: fmt.Sprintf(` -// provider "cidaas" { -// base_url = "%s" -// } -// resource "cidaas_custom_provider" "example" { -// standard_type = "`+updatedOauth2StandardType+`" -// authorization_endpoint = "`+updatedAuthorizationEndpoint+`" -// token_endpoint = "`+updatedTokenEndpoint+`" -// provider_name = "`+providerName+`" -// display_name = "`+updatedDisplayName+`" -// logo_url = "`+updatedLogoURL+`" -// userinfo_endpoint = "`+updatedUserinfoEndpoint+`" -// scope_display_label = "`+updatedScopeDisplayLabel+`" -// client_id = "`+updatedClientID+`" -// client_secret = "`+updatedClientSecret+`" -// domains = ["cidaas.in", "cidaas.com"] +func TestAccCustomProviderResource_Basic(t *testing.T) { + updatedDisplayName := "Updated Sample Terraform" + updatedOauth2StandardType := "OPENID_CONNECT" + updatedAuthorizationEndpoint := "https://cidaas.de/authz-srv/v2/authz" + updatedTokenEndpoint := "https://cidaas.de/token-srv/v2/token" //nolint:gosec + updatedLogoURL := "https://cidaas.de/v2/logo" + updatedUserinfoEndpoint := "https://cidaas.de/users-srv/v2/userinfo" + updatedScopeDisplayLabel := "updated terraform sample scope display name" + updatedClientID := acctest.RandString(10) + updatedClientSecret := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, + CheckDestroy: checkCustomProviderDestroyed, + Steps: []resource.TestStep{ + { + Config: resourceCustomProviderConfig(oauth2StandardType, providerName), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(resourceCustomProvider, "standard_type", oauth2StandardType), + resource.TestCheckResourceAttr(resourceCustomProvider, "authorization_endpoint", authorizationEndpoint), + resource.TestCheckResourceAttr(resourceCustomProvider, "token_endpoint", tokenEndpoint), + resource.TestCheckResourceAttr(resourceCustomProvider, "provider_name", providerName), + resource.TestCheckResourceAttr(resourceCustomProvider, "display_name", displayName), + resource.TestCheckResourceAttr(resourceCustomProvider, "logo_url", logoURL), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_endpoint", userinfoEndpoint), + resource.TestCheckResourceAttr(resourceCustomProvider, "scope_display_label", scopeDisplayLabel), + resource.TestCheckResourceAttr(resourceCustomProvider, "client_id", clientID), + resource.TestCheckResourceAttr(resourceCustomProvider, "client_secret", clientSecret), + resource.TestCheckResourceAttr(resourceCustomProvider, "domains.0", "cidaas.de"), + resource.TestCheckResourceAttr(resourceCustomProvider, "domains.1", "cidaas.org"), + resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.recommended", strconv.FormatBool(true)), + resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.required", strconv.FormatBool(true)), + resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.scope_name", "email"), + resource.TestCheckResourceAttrSet(resourceCustomProvider, "id"), + ), + }, + { + ResourceName: resourceCustomProvider, + ImportState: true, + ImportStateVerify: true, + ImportStateId: providerName, + }, + { + Config: fmt.Sprintf(` + provider "cidaas" { + base_url = "%s" + } + resource "cidaas_custom_provider" "example" { + standard_type = "`+updatedOauth2StandardType+`" + authorization_endpoint = "`+updatedAuthorizationEndpoint+`" + token_endpoint = "`+updatedTokenEndpoint+`" + provider_name = "`+providerName+`" + display_name = "`+updatedDisplayName+`" + logo_url = "`+updatedLogoURL+`" + userinfo_endpoint = "`+updatedUserinfoEndpoint+`" + scope_display_label = "`+updatedScopeDisplayLabel+`" + client_id = "`+updatedClientID+`" + client_secret = "`+updatedClientSecret+`" + domains = ["cidaas.in", "cidaas.com"] -// scopes = [ -// { -// scope_name = "openid" -// } -// ] -// } -// `, acctest.BaseURL), -// Check: resource.ComposeAggregateTestCheckFunc( -// resource.TestCheckResourceAttr(resourceCustomProvider, "standard_type", updatedOauth2StandardType), -// resource.TestCheckResourceAttr(resourceCustomProvider, "authorization_endpoint", updatedAuthorizationEndpoint), -// resource.TestCheckResourceAttr(resourceCustomProvider, "token_endpoint", updatedTokenEndpoint), -// resource.TestCheckResourceAttr(resourceCustomProvider, "provider_name", providerName), -// resource.TestCheckResourceAttr(resourceCustomProvider, "display_name", updatedDisplayName), -// resource.TestCheckResourceAttr(resourceCustomProvider, "logo_url", updatedLogoURL), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_endpoint", updatedUserinfoEndpoint), -// resource.TestCheckResourceAttr(resourceCustomProvider, "scope_display_label", updatedScopeDisplayLabel), -// resource.TestCheckResourceAttr(resourceCustomProvider, "client_id", updatedClientID), -// resource.TestCheckResourceAttr(resourceCustomProvider, "client_secret", updatedClientSecret), -// resource.TestCheckResourceAttr(resourceCustomProvider, "domains.0", "cidaas.com"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "domains.1", "cidaas.in"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.scope_name", "openid"), -// // default value check scopes[i].recommended & scopes[i].required -// resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.recommended", strconv.FormatBool(false)), -// resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.required", strconv.FormatBool(false)), -// resource.TestCheckResourceAttrSet(resourceCustomProvider, "id"), -// ), -// }, -// { -// // provider_name cannot be updated -// Config: resourceCustomProviderConfig(oauth2StandardType, "new_provider_name"), -// ExpectError: regexp.MustCompile(`Attribute 'provider_name' can't be modified`), -// }, -// }, -// }) -// } + scopes = [ + { + scope_name = "openid" + } + ] + } + `, acctest.BaseURL), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(resourceCustomProvider, "standard_type", updatedOauth2StandardType), + resource.TestCheckResourceAttr(resourceCustomProvider, "authorization_endpoint", updatedAuthorizationEndpoint), + resource.TestCheckResourceAttr(resourceCustomProvider, "token_endpoint", updatedTokenEndpoint), + resource.TestCheckResourceAttr(resourceCustomProvider, "provider_name", providerName), + resource.TestCheckResourceAttr(resourceCustomProvider, "display_name", updatedDisplayName), + resource.TestCheckResourceAttr(resourceCustomProvider, "logo_url", updatedLogoURL), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_endpoint", updatedUserinfoEndpoint), + resource.TestCheckResourceAttr(resourceCustomProvider, "scope_display_label", updatedScopeDisplayLabel), + resource.TestCheckResourceAttr(resourceCustomProvider, "client_id", updatedClientID), + resource.TestCheckResourceAttr(resourceCustomProvider, "client_secret", updatedClientSecret), + resource.TestCheckResourceAttr(resourceCustomProvider, "domains.0", "cidaas.com"), + resource.TestCheckResourceAttr(resourceCustomProvider, "domains.1", "cidaas.in"), + resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.scope_name", "openid"), + // default value check scopes[i].recommended & scopes[i].required + resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.recommended", strconv.FormatBool(false)), + resource.TestCheckResourceAttr(resourceCustomProvider, "scopes.0.required", strconv.FormatBool(false)), + resource.TestCheckResourceAttrSet(resourceCustomProvider, "id"), + ), + }, + { + // provider_name cannot be updated + Config: resourceCustomProviderConfig(oauth2StandardType, "new_provider_name"), + ExpectError: regexp.MustCompile(`Attribute 'provider_name' can't be modified`), + }, + }, + }) +} func resourceCustomProviderConfig(standardType, providerName string) string { return fmt.Sprintf(` @@ -216,78 +217,78 @@ func TestAccCustomProviderResource_MissingRequired(t *testing.T) { } // check userinfo_fields parameters -// func TestAccCustomProviderResource_UserinfoFieldsCheck(t *testing.T) { -// resource.Test(t, resource.TestCase{ -// PreCheck: func() { acctest.TestAccPreCheck(t) }, -// ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, -// Steps: []resource.TestStep{ -// { -// Config: fmt.Sprintf(` -// provider "cidaas" { -// base_url = "%s" -// } -// resource "cidaas_custom_provider" "example" { -// standard_type = "`+oauth2StandardType+`" -// authorization_endpoint = "`+authorizationEndpoint+`" -// token_endpoint = "`+tokenEndpoint+`" -// provider_name = "`+providerName+`" -// display_name = "`+displayName+`" -// userinfo_endpoint = "`+userinfoEndpoint+`" -// scope_display_label = "`+scopeDisplayLabel+`" -// client_id = "`+clientID+`" -// client_secret = "`+clientSecret+`" -// scopes = [ -// { -// scope_name = "email" -// } -// ] -// userinfo_fields = { -// family_name = "cp_family_name" -// address = "cp_address" -// birthdate = "01-01-2000" -// email = "cp@cidaas.de" -// email_verified = "true" -// gender = "male" -// given_name = "cp_given_name" -// locale = "cp_locale" -// middle_name = "cp_middle_name" -// mobile_number = "100000000" -// phone_number = "10000000" -// picture = "https://cidaas.de/image.jpg" -// preferred_username = "cp_preferred_username" -// profile = "cp_profile" -// updated_at = "01-01-01" -// website = "https://cidaas.de" -// zoneinfo = "cp_zone_info" -// custom_fields = { -// zipcode = "123456" -// alternate_phone = "1234567890" -// } -// } -// }`, acctest.BaseURL), -// Check: resource.ComposeAggregateTestCheckFunc( -// // default value check -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.family_name", "cp_family_name"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.address", "cp_address"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.birthdate", "01-01-2000"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.email", "cp@cidaas.de"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.email_verified", "true"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.gender", "male"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.given_name", "cp_given_name"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.locale", "cp_locale"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.middle_name", "cp_middle_name"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.mobile_number", "100000000"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.phone_number", "10000000"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.picture", "https://cidaas.de/image.jpg"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.preferred_username", "cp_preferred_username"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.profile", "cp_profile"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.updated_at", "01-01-01"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.website", "https://cidaas.de"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.zoneinfo", "cp_zone_info"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.custom_fields.zipcode", "123456"), -// resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.custom_fields.alternate_phone", "1234567890"), -// ), -// }, -// }, -// }) -// } +func TestAccCustomProviderResource_UserinfoFieldsCheck(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: fmt.Sprintf(` + provider "cidaas" { + base_url = "%s" + } + resource "cidaas_custom_provider" "example" { + standard_type = "`+oauth2StandardType+`" + authorization_endpoint = "`+authorizationEndpoint+`" + token_endpoint = "`+tokenEndpoint+`" + provider_name = "`+providerName+`" + display_name = "`+displayName+`" + userinfo_endpoint = "`+userinfoEndpoint+`" + scope_display_label = "`+scopeDisplayLabel+`" + client_id = "`+clientID+`" + client_secret = "`+clientSecret+`" + scopes = [ + { + scope_name = "email" + } + ] + userinfo_fields = { + family_name = "cp_family_name" + address = "cp_address" + birthdate = "01-01-2000" + email = "cp@cidaas.de" + email_verified = "true" + gender = "male" + given_name = "cp_given_name" + locale = "cp_locale" + middle_name = "cp_middle_name" + mobile_number = "100000000" + phone_number = "10000000" + picture = "https://cidaas.de/image.jpg" + preferred_username = "cp_preferred_username" + profile = "cp_profile" + updated_at = "01-01-01" + website = "https://cidaas.de" + zoneinfo = "cp_zone_info" + custom_fields = { + zipcode = "123456" + alternate_phone = "1234567890" + } + } + }`, acctest.BaseURL), + Check: resource.ComposeAggregateTestCheckFunc( + // default value check + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.family_name", "cp_family_name"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.address", "cp_address"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.birthdate", "01-01-2000"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.email", "cp@cidaas.de"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.email_verified", "true"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.gender", "male"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.given_name", "cp_given_name"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.locale", "cp_locale"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.middle_name", "cp_middle_name"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.mobile_number", "100000000"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.phone_number", "10000000"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.picture", "https://cidaas.de/image.jpg"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.preferred_username", "cp_preferred_username"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.profile", "cp_profile"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.updated_at", "01-01-01"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.website", "https://cidaas.de"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.zoneinfo", "cp_zone_info"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.custom_fields.zipcode", "123456"), + resource.TestCheckResourceAttr(resourceCustomProvider, "userinfo_fields.custom_fields.alternate_phone", "1234567890"), + ), + }, + }, + }) +}