Skip to content
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

Update RepoKey validator to match web UI #55

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.22.1 (Mar 20, 2024)

IMPROVEMENTS:

* Improve `RepoKey` validation to match Artifactory web UI.

PR: [#55](https://github.com/jfrog/terraform-provider-shared/pull/55)

## 1.22.0 (Mar 11, 2024)

IMPROVEMENTS:
Expand Down
9 changes: 7 additions & 2 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ var CommaSeperatedList = validation.ToDiagFunc(
validation.StringMatch(regexp.MustCompile(`.+(?:,.+)*`), "must be comma separated string"),
)

var RepoKey = validation.ToDiagFunc(
validation.StringDoesNotContainAny(" !@#$%^&*()+={}[]:;<>,/?~`|\\"),
var RepoKey = validation.AllDiag(
validation.ToDiagFunc(
validation.StringLenBetween(1, 64),
),
validation.ToDiagFunc(
validation.StringDoesNotContainAny(" !@#$%^&*()+={}[]:;<>,/?~`|\\"),
),
)

var ProjectKey = validation.ToDiagFunc(
Expand Down
47 changes: 47 additions & 0 deletions validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,53 @@ import (
"testing"
)

func TestRepoKey(t *testing.T) {
t.Parallel()

validRepoKeys := []string{
"a", // min 1
"abcd123456789012345678912345678901234567890123456789012345678901", // max 64
"abc-123", // hyphen is supported
"abc123-", // hyphen can be anywhere
"123abc123", // begin with number
}

for _, repoKey := range validRepoKeys {
k := repoKey
t.Run(k, func(t *testing.T) {
t.Parallel()

diag := RepoKey(k, nil)
if diag.HasError() {
t.Errorf("RepoKey validation failed. diag: %v", diag)
}
})
}
}

func TestRepoKey_invalidKeys(t *testing.T) {
t.Parallel()

invalidRepoKeys := []string{
"", // empty
" ", // has space
"abcd1234567890123456789123456789012345678901234567890123456789012", // 65 chars, too long
"abc,", // invalid characters
}

for _, repoKey := range invalidRepoKeys {
k := repoKey
t.Run(k, func(t *testing.T) {
t.Parallel()

diag := RepoKey(k, nil)
if !diag.HasError() {
t.Errorf("RepoKey '%s' should fail", k)
}
})
}
}

func TestProjectKey(t *testing.T) {
t.Parallel()

Expand Down
Loading