Skip to content

Commit

Permalink
Merge pull request #2677 from infrahq/dnephin/remove-group-name-valid…
Browse files Browse the repository at this point in the history
…ation

fix: remove group name validation
  • Loading branch information
dnephin authored Jul 21, 2022
2 parents 9939e44 + b9a6bd9 commit f4499a9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
7 changes: 0 additions & 7 deletions api/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,10 @@ type CreateGroupRequest struct {

func (r CreateGroupRequest) ValidationRules() []validate.ValidationRule {
return []validate.ValidationRule{
validateGroupName(r.Name),
validate.Required("name", r.Name),
}
}

func validateGroupName(value string) validate.StringRule {
nameRule := ValidateName(value)
nameRule.CharacterRanges = append(nameRule.CharacterRanges, validate.AtSign)
return nameRule
}

type UpdateUsersInGroupRequest struct {
GroupID uid.ID `uri:"id" json:"-"`
UserIDsToAdd []uid.ID `json:"usersToAdd"`
Expand Down
2 changes: 1 addition & 1 deletion internal/server/access_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestAPI_CreateAccessKey(t *testing.T) {
assert.NilError(t, err)

expected := []api.FieldError{
{FieldName: "name", Errors: []string{"character / at position 34 is not allowed"}},
{FieldName: "name", Errors: []string{"character '/' at position 34 is not allowed"}},
}
assert.DeepEqual(t, respBody.FieldErrors, expected)
},
Expand Down
3 changes: 0 additions & 3 deletions internal/server/testdata/openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2446,9 +2446,6 @@
"schema": {
"properties": {
"name": {
"format": "[a-zA-Z0-9\\-_.@]",
"maxLength": 256,
"minLength": 3,
"type": "string"
}
},
Expand Down
2 changes: 1 addition & 1 deletion internal/validate/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s StringRule) Validate() *Failure {
if len(s.CharacterRanges) > 0 {
for i, c := range value {
if !inRange(s.CharacterRanges, c) {
add("character %c at position %v is not allowed", c, i)
add("character %q at position %v is not allowed", c, i)
break
}
}
Expand Down
16 changes: 15 additions & 1 deletion internal/validate/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ func TestStringRule_Validate(t *testing.T) {
expected := Error{
"strField": {
"length of string is 12, must be no more than 10",
"character ~ at position 6 is not allowed",
"character '~' at position 6 is not allowed",
},
}
assert.DeepEqual(t, verr, expected)
})
t.Run("character ranges whitespace", func(t *testing.T) {
r := StringExample{Field: "almost valid"}
err := Validate(r)

var verr Error
assert.Assert(t, errors.As(err, &verr), "wrong type %T", err)
expected := Error{
"strField": {
"length of string is 12, must be no more than 10",
`character ' ' at position 6 is not allowed`,
},
}
assert.DeepEqual(t, verr, expected)
Expand Down
2 changes: 1 addition & 1 deletion internal/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestValidate_AllRules(t *testing.T) {
"emailOther": {`email address must not contain display name "Display Name"`},
"tooFew": {"length of string is 1, must be at least 5"},
"tooMany": {"length of string is 6, must be no more than 5"},
"wrongOnes": {"character C at position 2 is not allowed"},
"wrongOnes": {"character 'C' at position 2 is not allowed"},
"tooHigh": {"value 22 must be at most 20"},
"tooLow": {"value 2 must be at least 20"},
"kind": {"must be one of (fruit, legume, grain)"},
Expand Down

0 comments on commit f4499a9

Please sign in to comment.