Skip to content

Commit

Permalink
fix connection test
Browse files Browse the repository at this point in the history
fix setting/getting of userMetadata and appMetadat
format metadata in user test
  • Loading branch information
Thilo Keber committed Jul 3, 2019
1 parent c281764 commit 1cf3467
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
6 changes: 3 additions & 3 deletions auth0/resource_auth0_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestAccConnection(t *testing.T) {
resource.TestCheckResourceAttr("auth0_connection.my_connection", "strategy", "auth0"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.password_policy", "fair"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.password_no_personal_info.0.enable", "true"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.enabled_database_customization", "false"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.enabled_database_customization", "true"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.brute_force_protection", "true"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.import_mode", "true"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.disable_signup", "false"),
Expand Down Expand Up @@ -57,7 +57,7 @@ resource "auth0_connection" "my_connection" {
password_no_personal_info {
enable = true
}
enabled_database_customization = false
enabled_database_customization = true
brute_force_protection = true
import_mode = true
disable_signup = false
Expand Down Expand Up @@ -88,7 +88,7 @@ resource "auth0_connection" "my_connection" {
password_no_personal_info {
enable = true
}
enabled_database_customization = false
enabled_database_customization = true
brute_force_protection = false
import_mode = true
disable_signup = false
Expand Down
8 changes: 4 additions & 4 deletions auth0/resource_auth0_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ func readUser(d *schema.ResourceData, m interface{}) error {
d.Set("verify_email", u.VerifyEmail)
d.Set("email", u.Email)

if userMeta, err := structure.FlattenJsonToString(u.UserMetadata); err != nil {
if userMeta, err := structure.FlattenJsonToString(u.UserMetadata); err == nil {
d.Set("user_metadata", userMeta)
}

if appMeta, err := structure.FlattenJsonToString(u.AppMetadata); err != nil {
if appMeta, err := structure.FlattenJsonToString(u.AppMetadata); err == nil {
d.Set("app_metadata", appMeta)
}

Expand Down Expand Up @@ -144,14 +144,14 @@ func buildUser(d *schema.ResourceData) *management.User {

if d.HasChange("user_metadata") {
userMeta, err := structure.ExpandJsonFromString(d.Get("user_metadata").(string))
if err != nil {
if err == nil {
u.UserMetadata = userMeta
}
}

if d.HasChange("app_metadata") {
appMeta, err := structure.ExpandJsonFromString(d.Get("app_metadata").(string))
if err != nil {
if err == nil {
u.AppMetadata = appMeta
}
}
Expand Down
17 changes: 3 additions & 14 deletions auth0/resource_auth0_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func TestAccUserCreateUser(t *testing.T) {
}

const testAccUserCreateUser = `
provider "auth0" {
}
provider "auth0" {}
resource "auth0_user" "user" {
connection_name = "Username-Password-Authentication"
Expand All @@ -59,17 +58,7 @@ resource "auth0_user" "user" {
email = "test@test.com"
password = "passpass$12$12"
nickname = "testnick"
user_metadata = <<EOF
{
"foo": "bar",
"bar": { "baz": "qux" }
}
EOF
app_metadata = <<EOF
{
"foo": "bar",
"bar": { "baz": "qux" }
}
EOF
user_metadata = "{\"bar\":{\"baz\":\"qux\"},\"foo\":\"bar\"}"
app_metadata = "{\"bar\":{\"baz\":\"qux\"},\"foo\":\"bar\"}"
}
`

0 comments on commit 1cf3467

Please sign in to comment.