-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix user password validation
- Loading branch information
Showing
6 changed files
with
376 additions
and
132 deletions.
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
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 |
---|---|---|
|
@@ -230,11 +230,11 @@ func TestAccManagedUser_password_policy(t *testing.T) { | |
password string | ||
errorRegex string | ||
}{ | ||
{"Uppercase", "Abcde1234--", `.*Attribute password string must have at least 2 uppercase letters.*`}, | ||
{"Lowercase", "ABCDe1234--", `.*Attribute password string must have at least 2 lowercase letters.*`}, | ||
{"Special Char", "ABCDefgh12-", `.*Attribute password string must have at least 2 special characters.*`}, | ||
{"Digit", "ABCDEfghi1--", `.*Attribute password string must have at least 2 digits.*`}, | ||
{"Length", "ABcd123--", `.*Attribute password string length must be at least.*`}, | ||
{"Uppercase", "-A1b2c3d4e-", `.*Attribute password string must have at least 2 uppercase letters.*`}, | ||
{"Lowercase", "-A1B2C3D4e-", `.*Attribute password string must have at least 2 lowercase letters.*`}, | ||
{"Special Char", "A1B2CDefgh-", `.*Attribute password string must have at least 2 special characters.*`}, | ||
{"Digit", "-AfBgChDiE1-", `.*Attribute password string must have at least 2 digits.*`}, | ||
{"Length", "-A1B2c3d-", `.*Attribute password string length must be at least.*`}, | ||
} | ||
|
||
for _, tc := range testCase { | ||
|
@@ -282,6 +282,116 @@ func testAccManagedUserPasswordPolicy(password, errorRegex string) func(t *testi | |
} | ||
} | ||
|
||
func TestAccManagedUser_password_policy_interpolated(t *testing.T) { | ||
testCase := []struct { | ||
name string | ||
passwordCriteria string | ||
errorRegex string | ||
}{ | ||
{ | ||
"Uppercase", | ||
`length = 10 | ||
min_lower = 2 | ||
upper = false | ||
min_numeric = 2 | ||
min_special = 2 | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string must have at least 2 uppercase letters.*`, | ||
}, | ||
{ | ||
"Lowercase", | ||
`length = 10 | ||
lower = false | ||
min_upper = 2 | ||
min_numeric = 2 | ||
min_special = 2 | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string must have at least 2 lowercase letters.*`, | ||
}, | ||
{ | ||
"Special Char", | ||
`length = 10 | ||
min_lower = 2 | ||
min_upper = 2 | ||
min_numeric = 2 | ||
special = false | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string must have at least 2 special characters.*`, | ||
}, | ||
{ | ||
"Digit", | ||
`length = 10 | ||
min_lower = 2 | ||
min_upper = 2 | ||
numeric = false | ||
min_special = 2 | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string must have at least 2 digits.*`, | ||
}, | ||
{ | ||
"Length", | ||
`length = 9 | ||
min_lower = 2 | ||
min_upper = 2 | ||
min_numeric = 2 | ||
min_special = 2 | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string length must be at least.*`, | ||
}, | ||
} | ||
|
||
for _, tc := range testCase { | ||
t.Run(tc.name, testAccManagedUserPasswordPolicyInterpolated(tc.passwordCriteria, tc.errorRegex)) | ||
} | ||
} | ||
|
||
func testAccManagedUserPasswordPolicyInterpolated(passwordCriteria, errorRegex string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
id, _, name := testutil.MkNames("test-", "artifactory_user") | ||
|
||
temp := ` | ||
resource "random_password" "test" { | ||
{{ .passwordCriteria }} | ||
} | ||
resource "artifactory_managed_user" "{{ .resourceName }}" { | ||
name = "{{ .name }}" | ||
password = random_password.test.result | ||
password_policy = { | ||
uppercase = 2 | ||
lowercase = 2 | ||
special_char = 2 | ||
digit = 2 | ||
length = 10 | ||
} | ||
email = "{{ .email }}" | ||
}` | ||
|
||
config := util.ExecuteTemplate("TestAccUser_password_policy", temp, map[string]string{ | ||
"resourceName": name, | ||
"name": fmt.Sprintf("test-%d", id), | ||
"email": fmt.Sprintf("test-%[email protected]", id), | ||
"passwordCriteria": passwordCriteria, | ||
}) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ExternalProviders: map[string]resource.ExternalProvider{ | ||
"random": { | ||
Source: "hashicorp/random", | ||
}, | ||
}, | ||
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
ExpectError: regexp.MustCompile(errorRegex), | ||
}, | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
func TestAccManagedUser_basic(t *testing.T) { | ||
id, fqrn, name := testutil.MkNames("test-user-", "artifactory_managed_user") | ||
_, _, groupName := testutil.MkNames("test-group-", "artifactory_group") | ||
|
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 |
---|---|---|
|
@@ -547,11 +547,11 @@ func TestAccUser_password_policy(t *testing.T) { | |
password string | ||
errorRegex string | ||
}{ | ||
{"Uppercase", "Abcde1234--", `.*Attribute password string must have at least 2 uppercase letters.*`}, | ||
{"Lowercase", "ABCDe1234--", `.*Attribute password string must have at least 2 lowercase letters.*`}, | ||
{"Special Char", "ABCDefgh12-", `.*Attribute password string must have at least 2 special characters.*`}, | ||
{"Digit", "ABCDEfghi1--", `.*Attribute password string must have at least 2 digits.*`}, | ||
{"Length", "ABcd123--", `.*Attribute password string length must be at least.*`}, | ||
{"Uppercase", "-A1b2c3d4e-", `.*Attribute password string must have at least 2 uppercase letters.*`}, | ||
{"Lowercase", "-A1B2C3D4e-", `.*Attribute password string must have at least 2 lowercase letters.*`}, | ||
{"Special Char", "A1B2CDefgh-", `.*Attribute password string must have at least 2 special characters.*`}, | ||
{"Digit", "-AfBgChDiE1-", `.*Attribute password string must have at least 2 digits.*`}, | ||
{"Length", "-A1B2c3d-", `.*Attribute password string length must be at least.*`}, | ||
} | ||
|
||
for _, tc := range testCase { | ||
|
@@ -561,7 +561,7 @@ func TestAccUser_password_policy(t *testing.T) { | |
|
||
func testAccUserPasswordPolicy(password, errorRegex string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
id, fqrn, name := testutil.MkNames("test-", "artifactory_user") | ||
id, _, name := testutil.MkNames("test-", "artifactory_user") | ||
|
||
temp := ` | ||
resource "artifactory_user" "{{ .resourceName }}" { | ||
|
@@ -588,7 +588,116 @@ func testAccUserPasswordPolicy(password, errorRegex string) func(t *testing.T) { | |
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, | ||
CheckDestroy: testAccCheckUserDestroy(fqrn), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
ExpectError: regexp.MustCompile(errorRegex), | ||
}, | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
func TestAccUser_password_policy_interpolated(t *testing.T) { | ||
testCase := []struct { | ||
name string | ||
passwordCriteria string | ||
errorRegex string | ||
}{ | ||
{ | ||
"Uppercase", | ||
`length = 10 | ||
min_lower = 2 | ||
upper = false | ||
min_numeric = 2 | ||
min_special = 2 | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string must have at least 2 uppercase letters.*`, | ||
}, | ||
{ | ||
"Lowercase", | ||
`length = 10 | ||
lower = false | ||
min_upper = 2 | ||
min_numeric = 2 | ||
min_special = 2 | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string must have at least 2 lowercase letters.*`, | ||
}, | ||
{ | ||
"Special Char", | ||
`length = 10 | ||
min_lower = 2 | ||
min_upper = 2 | ||
min_numeric = 2 | ||
special = false | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string must have at least 2 special characters.*`, | ||
}, | ||
{ | ||
"Digit", | ||
`length = 10 | ||
min_lower = 2 | ||
min_upper = 2 | ||
numeric = false | ||
min_special = 2 | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string must have at least 2 digits.*`, | ||
}, | ||
{ | ||
"Length", | ||
`length = 9 | ||
min_lower = 2 | ||
min_upper = 2 | ||
min_numeric = 2 | ||
min_special = 2 | ||
override_special = "!"#$%%&'()*+,-./:;<=>?@[\]^_\x60{|}~"`, | ||
`.*Attribute password string length must be at least.*`, | ||
}, | ||
} | ||
|
||
for _, tc := range testCase { | ||
t.Run(tc.name, testAccUserPasswordPolicyInterpolated(tc.passwordCriteria, tc.errorRegex)) | ||
} | ||
} | ||
|
||
func testAccUserPasswordPolicyInterpolated(passwordCriteria, errorRegex string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
id, _, name := testutil.MkNames("test-", "artifactory_user") | ||
|
||
temp := ` | ||
resource "random_password" "test" { | ||
{{ .passwordCriteria }} | ||
} | ||
resource "artifactory_user" "{{ .resourceName }}" { | ||
name = "{{ .name }}" | ||
password = random_password.test.result | ||
password_policy = { | ||
uppercase = 2 | ||
lowercase = 2 | ||
special_char = 2 | ||
digit = 2 | ||
length = 10 | ||
} | ||
email = "{{ .email }}" | ||
}` | ||
|
||
config := util.ExecuteTemplate("TestAccUser_password_policy", temp, map[string]string{ | ||
"resourceName": name, | ||
"name": fmt.Sprintf("test-%d", id), | ||
"email": fmt.Sprintf("test-%[email protected]", id), | ||
"passwordCriteria": passwordCriteria, | ||
}) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ExternalProviders: map[string]resource.ExternalProvider{ | ||
"random": { | ||
Source: "hashicorp/random", | ||
}, | ||
}, | ||
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
|
Oops, something went wrong.