-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2/2] #35 Fix infinite plan on user metadata #250
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,22 +75,10 @@ resource auth0_user user { | |
family_name = "Lastname" | ||
nickname = "{{.testName}}" | ||
picture = "https://www.example.com/picture.jpg" | ||
user_metadata = <<EOF | ||
{ | ||
"foo": "bar", | ||
"bar": { "baz": "qux" } | ||
} | ||
EOF | ||
app_metadata = <<EOF | ||
{ | ||
"foo": "bar", | ||
"bar": { "baz": "qux" } | ||
} | ||
EOF | ||
} | ||
` | ||
|
||
const testAccUserAddRole = ` | ||
const testAccUserUpdateWithRolesAndMetadata = ` | ||
resource auth0_user user { | ||
depends_on = [auth0_role.owner, auth0_role.admin] | ||
connection_name = "Username-Password-Authentication" | ||
|
@@ -104,18 +92,14 @@ resource auth0_user user { | |
nickname = "{{.testName}}" | ||
picture = "https://www.example.com/picture.jpg" | ||
roles = [ auth0_role.owner.id, auth0_role.admin.id ] | ||
user_metadata = <<EOF | ||
{ | ||
"foo": "bar", | ||
"bar": { "baz": "qux" } | ||
} | ||
EOF | ||
app_metadata = <<EOF | ||
{ | ||
"foo": "bar", | ||
"bar": { "baz": "qux" } | ||
} | ||
EOF | ||
user_metadata = jsonencode({ | ||
"foo": "bar", | ||
"baz": "qux" | ||
}) | ||
app_metadata = jsonencode({ | ||
"foo": "bar", | ||
"baz": "qux" | ||
}) | ||
} | ||
|
||
resource auth0_role owner { | ||
|
@@ -130,7 +114,7 @@ resource auth0_role admin { | |
} | ||
` | ||
|
||
const testAccUserRemoveRole = ` | ||
const testAccUserUpdateRemovingOneRoleAndUpdatingMetadata = ` | ||
resource auth0_user user { | ||
depends_on = [auth0_role.admin] | ||
connection_name = "Username-Password-Authentication" | ||
|
@@ -144,18 +128,12 @@ resource auth0_user user { | |
nickname = "{{.testName}}" | ||
picture = "https://www.example.com/picture.jpg" | ||
roles = [ auth0_role.admin.id ] | ||
user_metadata = <<EOF | ||
{ | ||
"foo": "bar", | ||
"bar": { "baz": "qux" } | ||
} | ||
EOF | ||
app_metadata = <<EOF | ||
{ | ||
"foo": "bar", | ||
"bar": { "baz": "qux" } | ||
} | ||
EOF | ||
user_metadata = jsonencode({ | ||
"foo": "bars", | ||
}) | ||
app_metadata = jsonencode({ | ||
"foo": "bars", | ||
}) | ||
} | ||
|
||
resource auth0_role admin { | ||
|
@@ -164,6 +142,44 @@ resource auth0_role admin { | |
} | ||
` | ||
|
||
const testAccUserUpdateRemovingAllRolesAndUpdatingMetadata = ` | ||
resource auth0_user user { | ||
connection_name = "Username-Password-Authentication" | ||
username = "{{.testName}}" | ||
user_id = "{{.testName}}" | ||
email = "{{.testName}}@acceptance.test.com" | ||
password = "passpass$12$12" | ||
name = "Firstname Lastname" | ||
given_name = "Firstname" | ||
family_name = "Lastname" | ||
nickname = "{{.testName}}" | ||
picture = "https://www.example.com/picture.jpg" | ||
user_metadata = jsonencode({ | ||
"foo": "barss", | ||
"foo2": "bar2", | ||
}) | ||
app_metadata = jsonencode({ | ||
"foo": "barss", | ||
"foo2": "bar2", | ||
}) | ||
} | ||
` | ||
|
||
const testAccUserUpdateRemovingMetadata = ` | ||
resource auth0_user user { | ||
connection_name = "Username-Password-Authentication" | ||
username = "{{.testName}}" | ||
user_id = "{{.testName}}" | ||
email = "{{.testName}}@acceptance.test.com" | ||
password = "passpass$12$12" | ||
name = "Firstname Lastname" | ||
given_name = "Firstname" | ||
family_name = "Lastname" | ||
nickname = "{{.testName}}" | ||
picture = "https://www.example.com/picture.jpg" | ||
} | ||
` | ||
|
||
func TestAccUser(t *testing.T) { | ||
httpRecorder := configureHTTPRecorder(t) | ||
|
||
|
@@ -173,62 +189,53 @@ func TestAccUser(t *testing.T) { | |
{ | ||
Config: template.ParseTestName(testAccUserCreate, strings.ToLower(t.Name())), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("auth0_user.user", "connection_name", "Username-Password-Authentication"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "username", strings.ToLower(t.Name())), | ||
resource.TestCheckResourceAttr("auth0_user.user", "user_id", fmt.Sprintf("auth0|%s", strings.ToLower(t.Name()))), | ||
resource.TestCheckResourceAttr("auth0_user.user", "email", fmt.Sprintf("%s@acceptance.test.com", strings.ToLower(t.Name()))), | ||
resource.TestCheckResourceAttr("auth0_user.user", "name", "Firstname Lastname"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "family_name", "Lastname"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "given_name", "Firstname"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "family_name", "Lastname"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "nickname", strings.ToLower(t.Name())), | ||
resource.TestCheckResourceAttr("auth0_user.user", "connection_name", "Username-Password-Authentication"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "roles.#", "0"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "picture", "https://www.example.com/picture.jpg"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "user_metadata", ""), | ||
resource.TestCheckResourceAttr("auth0_user.user", "app_metadata", ""), | ||
resource.TestCheckResourceAttr("auth0_user.user", "roles.#", "0"), | ||
), | ||
}, | ||
{ | ||
Config: template.ParseTestName(testAccUserAddRole, strings.ToLower(t.Name())), | ||
Config: template.ParseTestName(testAccUserUpdateWithRolesAndMetadata, strings.ToLower(t.Name())), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("auth0_user.user", "roles.#", "2"), | ||
resource.TestCheckResourceAttr("auth0_role.owner", "name", "owner"), | ||
resource.TestCheckResourceAttr("auth0_role.admin", "name", "admin"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "user_metadata", `{"baz":"qux","foo":"bar"}`), | ||
resource.TestCheckResourceAttr("auth0_user.user", "app_metadata", `{"baz":"qux","foo":"bar"}`), | ||
), | ||
}, | ||
{ | ||
Config: template.ParseTestName(testAccUserRemoveRole, strings.ToLower(t.Name())), | ||
Config: template.ParseTestName(testAccUserUpdateRemovingOneRoleAndUpdatingMetadata, strings.ToLower(t.Name())), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("auth0_user.user", "roles.#", "1"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "user_metadata", `{"foo":"bars"}`), | ||
resource.TestCheckResourceAttr("auth0_user.user", "app_metadata", `{"foo":"bars"}`), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccUserCanSerializeEmptyMetadataFields = ` | ||
resource auth0_user auth0_user_issue_218 { | ||
connection_name = "Username-Password-Authentication" | ||
user_id = "id_{{.testName}}" | ||
username = "user_{{.testName}}" | ||
email = "issue.218.{{.testName}}@acceptance.test.com" | ||
email_verified = true | ||
password = "MyPass123$" | ||
} | ||
` | ||
|
||
func TestAccUserCanSerializeEmptyMetadataFields(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're removing this as we added it as a last test case for the TestAccUser scenario. |
||
httpRecorder := configureHTTPRecorder(t) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
ProviderFactories: testProviders(httpRecorder), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: template.ParseTestName(testAccUserCanSerializeEmptyMetadataFields, "issue#218"), | ||
Config: template.ParseTestName(testAccUserUpdateRemovingAllRolesAndUpdatingMetadata, strings.ToLower(t.Name())), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("auth0_user.auth0_user_issue_218", "user_id", "auth0|id_issue#218"), | ||
resource.TestCheckResourceAttr("auth0_user.auth0_user_issue_218", "username", "user_issue#218"), | ||
resource.TestCheckResourceAttr("auth0_user.auth0_user_issue_218", "email", "issue.218.issue#218@acceptance.test.com"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "roles.#", "0"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "user_metadata", `{"foo":"barss","foo2":"bar2"}`), | ||
resource.TestCheckResourceAttr("auth0_user.user", "app_metadata", `{"foo":"barss","foo2":"bar2"}`), | ||
), | ||
}, | ||
{ | ||
Config: template.ParseTestName(testAccUserCanSerializeEmptyMetadataFields, "issue#218"), | ||
Config: template.ParseTestName(testAccUserUpdateRemovingMetadata, strings.ToLower(t.Name())), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("auth0_user.user", "roles.#", "0"), | ||
resource.TestCheckResourceAttr("auth0_user.user", "user_metadata", ""), | ||
resource.TestCheckResourceAttr("auth0_user.user", "app_metadata", ""), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're applying the following explained logic in alexkappa/terraform-provider-auth0#392 (comment), where in order to properly remove something we need to send it's value as null.
This is because the metadata fields are merged instead of being replaced but the merge only occurs on the first level during a PATCH.