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

Reapply host_and_port conformance tests #166

Merged
merged 2 commits into from
Feb 12, 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
4 changes: 2 additions & 2 deletions proto/protovalidate-testing/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ deps:
- remote: buf.build
owner: bufbuild
repository: protovalidate
commit: 12f9cba37c9d49eeb6827dde227d6031
digest: shake256:a9470135a1736bdb74396e35342b4431b0bf3a5e7a2198fb77f49be46af744aae134f8e0593683216e836f1f0a551ccf86a9f8857c6829b8d33f4b604602a5ff
commit: 3014d81c3a48461dbcc5b57536699f9e
digest: shake256:6b40454a0754bf624c8fc965f3576bd26bf72a480c554514672d2fac887f420c82d68cf50d40f5a77d8b6e96dda87e395aeedae84d513dde7c4bfd4d95f5657a
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,15 @@ message StringInOneof {
}];
}
}

message StringHostAndPort {
string val = 1 [(buf.validate.field).string.host_and_port = true];
}

message StringHostAndOptionalPort {
string val = 1 [(field).cel = {
id: "string.host_and_port.optional_port",
message: "value must be a host and (optional) port pair",
expression: "this.isHostAndPort(false)",
}];
}
176 changes: 155 additions & 21 deletions tools/internal/gen/buf/validate/conformance/cases/strings.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions tools/protovalidate-conformance/internal/cases/cases_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,5 +852,96 @@ func stringSuite() suites.Suite {
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.well_known_regex.header_value"}),
},
"host_and_port/valid/hostname": {
Message: &cases.StringHostAndPort{Val: "localhost:1234"},
Expected: results.Success(true),
},
"host_and_port/valid/ipv4": {
Message: &cases.StringHostAndPort{Val: "127.0.0.1:12345"},
Expected: results.Success(true),
},
"host_and_port/valid/ipv6": {
Message: &cases.StringHostAndPort{Val: "[::1]:8080"},
Expected: results.Success(true),
},
"host_and_port/invalid/empty": {
Message: &cases.StringHostAndPort{Val: ""},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port_empty"}),
},
"host_and_port/invalid/missing_port": {
Message: &cases.StringHostAndPort{Val: "localhost"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port"}),
},
"host_and_port/invalid/whitespace": {
Message: &cases.StringHostAndPort{Val: " localhost:8080 "},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port"}),
},
"host_and_port/invalid/malformed_hostname": {
Message: &cases.StringHostAndPort{Val: "abc#123:456"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port"}),
},
"host_and_port/invalid/malformed_ipv4": {
Message: &cases.StringHostAndPort{Val: "123.456.789.100:8080"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port"}),
},
"host_and_port/invalid/malformed_ipv6": {
Message: &cases.StringHostAndPort{Val: "[1::jk::3]:8080"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port"}),
},
"host_and_port/invalid/unbracketed_ipv6": {
Message: &cases.StringHostAndPort{Val: "::1:8080"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port"}),
},
"host_and_port/invalid/port_out_of_range": {
Message: &cases.StringHostAndPort{Val: "localhost:99999"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port"}),
},
"host_and_port/optional_port/valid/hostname": {
Message: &cases.StringHostAndOptionalPort{Val: "localhost"},
Expected: results.Success(true),
},
"host_and_port/optional_port/valid/ipv4": {
Message: &cases.StringHostAndOptionalPort{Val: "192.168.0.1"},
Expected: results.Success(true),
},
"host_and_port/optional_port/valid/ipv6": {
Message: &cases.StringHostAndOptionalPort{Val: "[838e:3861:529f:0e68:2c40:906a:d7b6:4006]"},
Expected: results.Success(true),
},
"host_and_port/optional_port/valid/hostname_and_port": {
Message: &cases.StringHostAndOptionalPort{Val: "localhost:1234"},
Expected: results.Success(true),
},
"host_and_port/optional_port/valid/ipv4_and_port": {
Message: &cases.StringHostAndOptionalPort{Val: "127.0.0.1:12345"},
Expected: results.Success(true),
},
"host_and_port/optional_port/valid/ipv6_and_port": {
Message: &cases.StringHostAndOptionalPort{Val: "[::1]:8080"},
Expected: results.Success(true),
},
"host_and_port/optional_port/invalid/malformed_hostname": {
Message: &cases.StringHostAndOptionalPort{Val: "abc#123"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port.optional_port"}),
},
"host_and_port/optional_port/invalid/malformed_ipv4": {
Message: &cases.StringHostAndOptionalPort{Val: "123.456.789.100"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port.optional_port"}),
},
"host_and_port/optional_port/invalid/malformed_ipv6": {
Message: &cases.StringHostAndOptionalPort{Val: "[1::jk::3]"},
Expected: results.Violations(
&validate.Violation{FieldPath: "val", ConstraintId: "string.host_and_port.optional_port"}),
},
}
}
Loading