Skip to content

Commit

Permalink
Merge pull request #17621 from dortort/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Feb 19, 2021
2 parents 962ebd5 + ab2c862 commit 59c72cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changelog/17621.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_transfer_ssh_key: Corrects user_name validation
```

```release-note:bug
resource/aws_transfer_user: Corrects user_name validation
```
8 changes: 4 additions & 4 deletions aws/resource_aws_transfer_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ func TestAccAWSTransferUser_UserName_Validation(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccAWSTransferUserName_validation("!@#$%^"),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
ExpectError: regexp.MustCompile(`Invalid "user_name": `),
},
{
Config: testAccAWSTransferUserName_validation(acctest.RandString(2)),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
ExpectError: regexp.MustCompile(`Invalid "user_name": `),
},
{
Config: testAccAWSTransferUserName_validation(acctest.RandString(33)),
Expand All @@ -147,11 +147,11 @@ func TestAccAWSTransferUser_UserName_Validation(t *testing.T) {
},
{
Config: testAccAWSTransferUserName_validation(acctest.RandString(101)),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
ExpectError: regexp.MustCompile(`Invalid "user_name": `),
},
{
Config: testAccAWSTransferUserName_validation("-abcdef"),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
ExpectError: regexp.MustCompile(`Invalid "user_name": `),
},
{
Config: testAccAWSTransferUserName_validation("valid_username"),
Expand Down
4 changes: 2 additions & 2 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func validateTransferServerID(v interface{}, k string) (ws []string, errors []er
func validateTransferUserName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
// https://docs.aws.amazon.com/transfer/latest/userguide/API_CreateUser.html
if !regexp.MustCompile(`^[a-zA-Z0-9_][a-zA-Z0-9_-]{2,99}$`).MatchString(value) {
errors = append(errors, fmt.Errorf("Invalid %q: must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, %q cannot begin with a hyphen", k, k))
if !regexp.MustCompile(`^[\w][\w@.-]{2,99}$`).MatchString(value) {
errors = append(errors, fmt.Errorf("Invalid %q: must be between 3 and 100 alphanumeric characters, special characters, hyphens, or underscores. However, it cannot begin with a hyphen, period, or at sign", k))
}
return
}
Expand Down

0 comments on commit 59c72cd

Please sign in to comment.