Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Adds a new test case for update credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
vijetm committed Nov 19, 2019
1 parent 6270b93 commit 4e0debd
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
1 change: 0 additions & 1 deletion examples/okta_user/all_attributes.tf
Expand Up @@ -31,5 +31,4 @@ resource "okta_user" "test" {
title = "Director"
user_type = "Employee"
zip_code = "11111"
password = "Abcd1234"
}
1 change: 0 additions & 1 deletion examples/okta_user/basic.tf
Expand Up @@ -3,5 +3,4 @@ resource "okta_user" "test" {
last_name = "Smith"
login = "test-acc-replace_with_uuid@example.com"
email = "test-acc-replace_with_uuid@example.com"
password = "Abcd1234"
}
2 changes: 1 addition & 1 deletion examples/okta_user/basic_with_credentials.tf
Expand Up @@ -3,7 +3,7 @@ resource "okta_user" "test" {
last_name = "Smith"
login = "test-acc-replace_with_uuid@example.com"
email = "test-acc-replace_with_uuid@example.com"
password = "SuperSecret007"
password = "Abcd1234"
recovery_question = "What is the answer to life, the universe, and everything?"
recovery_answer = "Forty Two"
}
9 changes: 9 additions & 0 deletions examples/okta_user/basic_with_credentials_updated.tf
@@ -0,0 +1,9 @@
resource "okta_user" "test" {
first_name = "TestAcc"
last_name = "Smith"
login = "test-acc-replace_with_uuid@example.com"
email = "test-acc-replace_with_uuid@example.com"
password = "SuperSecret007"
recovery_question = "Which symbol has the ASCII code of Forty Two?"
recovery_answer = "Asterisk"
}
1 change: 0 additions & 1 deletion examples/okta_user/staged.tf
Expand Up @@ -4,6 +4,5 @@ resource "okta_user" "test" {
last_name = "Smith"
login = "test-acc-replace_with_uuid@example.com"
email = "test-acc-replace_with_uuid@example.com"
password = "Abcd1234"
status = "STAGED"
}
4 changes: 0 additions & 4 deletions okta/resource_okta_user.go
Expand Up @@ -316,10 +316,6 @@ func resourceUserCreate(d *schema.ResourceData, m interface{}) error {
recoveryQuestion := d.Get("recovery_question").(string)
recoveryAnswer := d.Get("recovery_answer").(string)

if recoveryQuestion != "" {
return fmt.Errorf("[ERROR] Okta does not allow security answers with less than 4 characters")
}

uc := &okta.UserCredentials{
Password: &okta.PasswordCredential{
Value: password,
Expand Down
31 changes: 29 additions & 2 deletions okta/resource_okta_user_test.go
Expand Up @@ -169,7 +169,6 @@ func TestAccOktaUser_updateAllAttributes(t *testing.T) {
config := mgr.GetFixtures("staged.tf", ri, t)
updatedConfig := mgr.GetFixtures("all_attributes.tf", ri, t)
minimalConfig := mgr.GetFixtures("basic.tf", ri, t)
minimalConfigWithCredentials := mgr.GetFixtures("basic_with_credentials.tf", ri, t)
resourceName := fmt.Sprintf("%s.test", oktaUser)
email := fmt.Sprintf("test-acc-%d@example.com", ri)

Expand Down Expand Up @@ -234,6 +233,34 @@ func TestAccOktaUser_updateAllAttributes(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "email", email),
),
},
},
})
}

func TestAccOktaUser_updateCredentials(t *testing.T) {
ri := acctest.RandInt()
mgr := newFixtureManager(oktaUser)
config := mgr.GetFixtures("basic_with_credentials.tf", ri, t)
minimalConfigWithCredentials := mgr.GetFixtures("basic_with_credentials_updated.tf", ri, t)
resourceName := fmt.Sprintf("%s.test", oktaUser)
email := fmt.Sprintf("test-acc-%d@example.com", ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckUserDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "first_name", "TestAcc"),
resource.TestCheckResourceAttr(resourceName, "last_name", "Smith"),
resource.TestCheckResourceAttr(resourceName, "login", email),
resource.TestCheckResourceAttr(resourceName, "email", email),
resource.TestCheckResourceAttr(resourceName, "password", "Abcd1234"),
resource.TestCheckResourceAttr(resourceName, "recovery_answer", "Forty Two"),
),
},
{
Config: minimalConfigWithCredentials,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -242,7 +269,7 @@ func TestAccOktaUser_updateAllAttributes(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "login", email),
resource.TestCheckResourceAttr(resourceName, "email", email),
resource.TestCheckResourceAttr(resourceName, "password", "SuperSecret007"),
resource.TestCheckResourceAttr(resourceName, "recovery_answer", "Forty Two"),
resource.TestCheckResourceAttr(resourceName, "recovery_answer", "Asterisk"),
),
},
},
Expand Down

0 comments on commit 4e0debd

Please sign in to comment.