Skip to content

Commit

Permalink
update messages and update conformance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversun9 committed Nov 20, 2023
1 parent 9c91017 commit 23bed22
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion proto/protovalidate/buf/validate/validate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2818,7 +2818,7 @@ message StringRules {
expression: "this.isUri() || this == ''",
},
(priv.field).cel = {
id: "string.uri_emtpy",
id: "string.uri_empty",
message: "value is empty, which is not a valid URI",
expression: "this != ''",
}
Expand Down
76 changes: 73 additions & 3 deletions tools/protovalidate-conformance/internal/cases/cases_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ func stringSuite() suites.Suite {
Message: &cases.StringEmail{Val: "[email protected]"},
Expected: results.Success(true),
},
"email/invalid/empty": {
Message: &cases.StringEmail{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.email_empty"}),
},
"email/invalid/malformed": {
Message: &cases.StringEmail{Val: "foobar"},
Expected: results.Violations(
Expand Down Expand Up @@ -321,6 +326,11 @@ func stringSuite() suites.Suite {
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.email"}),
},
"hostname/invalid/empty": {
Message: &cases.StringHostname{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.hostname_empty"}),
},
"hostname/valid/lowercase": {
Message: &cases.StringHostname{Val: "example.com"},
Expected: results.Success(true),
Expand Down Expand Up @@ -362,7 +372,7 @@ func stringSuite() suites.Suite {
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.hostname"}),
},
"hostname/invalid/empty": {
"hostname/invalid/empty_part": {
Message: &cases.StringHostname{Val: "foo..bar.com"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.hostname"}),
Expand Down Expand Up @@ -390,10 +400,20 @@ func stringSuite() suites.Suite {
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ip"}),
},
"ip/invalid/empty": {
Message: &cases.StringIP{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ip_empty"}),
},
"ipv4/valid": {
Message: &cases.StringIPv4{Val: "192.168.0.1"},
Expected: results.Success(true),
},
"ipv4/invalid/empty": {
Message: &cases.StringIPv4{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ipv4_empty"}),
},
"ipv4/invalid/malformed": {
Message: &cases.StringIPv4{Val: "foobar"},
Expected: results.Violations(
Expand All @@ -417,6 +437,11 @@ func stringSuite() suites.Suite {
Message: &cases.StringIPv6{Val: "2001:0db8:85a3::8a2e:0370:7334"},
Expected: results.Success(true),
},
"ipv6/invalid/empty": {
Message: &cases.StringIPv6{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ipv6_empty"}),
},
"ipv6/invalid/malformed": {
Message: &cases.StringIPv6{Val: "foobar"},
Expected: results.Violations(
Expand Down Expand Up @@ -445,10 +470,20 @@ func stringSuite() suites.Suite {
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ip_with_prefixlen"}),
},
"ip_with_prefixlen/invalid/empty": {
Message: &cases.StringIPWithPrefixLen{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ip_with_prefixlen_empty"}),
},
"ipv4_with_prefixlen/valid": {
Message: &cases.StringIPv4WithPrefixLen{Val: "192.168.0.1/24"},
Expected: results.Success(true),
},
"ipv4_with_prefixlen/invalid/empty": {
Message: &cases.StringIPv4WithPrefixLen{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ipv4_with_prefixlen_empty"}),
},
"ipv4_with_prefixlen/invalid/malformed": {
Message: &cases.StringIPv4WithPrefixLen{Val: "foobar"},
Expected: results.Violations(
Expand All @@ -463,6 +498,11 @@ func stringSuite() suites.Suite {
Message: &cases.StringIPv6WithPrefixLen{Val: "2001:db8:1::1/64"},
Expected: results.Success(true),
},
"ipv6_with_prefixlen/invalid/invalid": {
Message: &cases.StringIPv6WithPrefixLen{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ipv6_with_prefixlen_empty"}),
},
"ipv6_with_prefixlen/invalid/malformed": {
Message: &cases.StringIPv6WithPrefixLen{Val: "foobar"},
Expected: results.Violations(
Expand All @@ -481,6 +521,11 @@ func stringSuite() suites.Suite {
Message: &cases.StringIPPrefix{Val: "2001:db8:1::/48"},
Expected: results.Success(true),
},
"ip_prefix/invalid/empty": {
Message: &cases.StringIPPrefix{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ip_prefix_empty"}),
},
"ip_prefix/invalid/malformed": {
Message: &cases.StringIPPrefix{Val: "foobar"},
Expected: results.Violations(
Expand All @@ -490,6 +535,11 @@ func stringSuite() suites.Suite {
Message: &cases.StringIPv4Prefix{Val: "192.168.0.0/24"},
Expected: results.Success(true),
},
"ipv4_prefix/invalid/empty": {
Message: &cases.StringIPv4Prefix{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ipv4_prefix_empty"}),
},
"ipv4_prefix/invalid/not_network_address": {
Message: &cases.StringIPv4Prefix{Val: "192.168.0.1/24"},
Expected: results.Violations(
Expand All @@ -509,6 +559,11 @@ func stringSuite() suites.Suite {
Message: &cases.StringIPv6Prefix{Val: "2001:db8:1::/48"},
Expected: results.Success(true),
},
"ipv6_prefix/invalid/empty": {
Message: &cases.StringIPv6Prefix{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.ipv6_prefix_empty"}),
},
"ipv6_prefix/invalid/not_network_address": {
Message: &cases.StringIPv6Prefix{Val: "2001:db8:1::1/48"},
Expected: results.Violations(
Expand All @@ -528,6 +583,11 @@ func stringSuite() suites.Suite {
Message: &cases.StringURI{Val: "https://example.com/foo/bar?baz=quux"},
Expected: results.Success(true),
},
"uri/invalid/empty": {
Message: &cases.StringURI{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.uri_empty"}),
},
"uri/invalid/malformed": {
Message: &cases.StringURI{Val: "!@#$%^&*"},
Expected: results.Violations(
Expand Down Expand Up @@ -563,6 +623,11 @@ func stringSuite() suites.Suite {
Message: &cases.StringAddress{Val: "3e::99"},
Expected: results.Success(true),
},
"address/invalid/empty": {
Message: &cases.StringAddress{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.address_empty"}),
},
"address/invalid/hostname": {
Message: &cases.StringAddress{Val: "-foo.bar"},
Expected: results.Violations(
Expand Down Expand Up @@ -617,6 +682,11 @@ func stringSuite() suites.Suite {
Message: &cases.StringUUID{Val: "A6EDC906-2F9F-5FB2-A373-EFAC406F0EF2"},
Expected: results.Success(true),
},
"uuid/invalid/empty": {
Message: &cases.StringUUID{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.uuid_empty"}),
},
"uuid/invalid/malformed": {
Message: &cases.StringUUID{Val: "foobar"},
Expected: results.Violations(
Expand Down Expand Up @@ -650,7 +720,7 @@ func stringSuite() suites.Suite {
"well_known_regex/header_name/strict/invalid/empty": {
Message: &cases.StringHttpHeaderName{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.well_known_regex.header_name"}),
&validate.Violation{FieldPath: "val", ConstraintId: "string.well_known_regex.header_name_empty"}),
},
"well_known_regex/header_name/strict/invalid/solo_colon": {
Message: &cases.StringHttpHeaderName{Val: ":"},
Expand Down Expand Up @@ -707,7 +777,7 @@ func stringSuite() suites.Suite {
"well_known_regex/header_name/loose/invalid/empty": {
Message: &cases.StringHttpHeaderNameLoose{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.well_known_regex.header_name"}),
&validate.Violation{FieldPath: "val", ConstraintId: "string.well_known_regex.header_name_empty"}),
},
"well_known_regex/header_name/loose/invalid/cr": {
Message: &cases.StringHttpHeaderNameLoose{Val: "foo\rbar"},
Expand Down

0 comments on commit 23bed22

Please sign in to comment.