From 4d1144943981b99723f4bcbf99a400937f97258c Mon Sep 17 00:00:00 2001 From: arun1587 Date: Sun, 11 Feb 2024 19:28:30 +0100 Subject: [PATCH 1/2] Add conformance tests for email addresses to cover semi-valid email addresses --- .../validate/conformance/cases/emails.proto | 36 +++ .../validate/conformance/cases/emails.pb.go | 251 ++++++++++++++++++ .../internal/cases/cases.go | 1 + .../internal/cases/cases_email.go | 71 +++++ 4 files changed, 359 insertions(+) create mode 100644 proto/protovalidate-testing/buf/validate/conformance/cases/emails.proto create mode 100644 tools/internal/gen/buf/validate/conformance/cases/emails.pb.go create mode 100644 tools/protovalidate-conformance/internal/cases/cases_email.go diff --git a/proto/protovalidate-testing/buf/validate/conformance/cases/emails.proto b/proto/protovalidate-testing/buf/validate/conformance/cases/emails.proto new file mode 100644 index 00000000..c6c99c69 --- /dev/null +++ b/proto/protovalidate-testing/buf/validate/conformance/cases/emails.proto @@ -0,0 +1,36 @@ +// Copyright 2023 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package buf.validate.conformance.cases; + +import "buf/validate/validate.proto"; + +message MessageInvalidEmail { + string email = 1 [(buf.validate.field).cel = { + id: "invalid_email", + message: "email must be a valid email", + expression: "this.isEmail()" + }]; +} + + +message MessageValidEmail { + string email = 1 [(buf.validate.field).cel = { + id: "valid_email", + message: "email must be a valid email", + expression: "this.isEmail()" + }]; +} diff --git a/tools/internal/gen/buf/validate/conformance/cases/emails.pb.go b/tools/internal/gen/buf/validate/conformance/cases/emails.pb.go new file mode 100644 index 00000000..c67bb9ce --- /dev/null +++ b/tools/internal/gen/buf/validate/conformance/cases/emails.pb.go @@ -0,0 +1,251 @@ +// Copyright 2023 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: buf/validate/conformance/cases/emails.proto + +package cases + +import ( + _ "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type MessageInvalidEmail struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` +} + +func (x *MessageInvalidEmail) Reset() { + *x = MessageInvalidEmail{} + if protoimpl.UnsafeEnabled { + mi := &file_buf_validate_conformance_cases_emails_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MessageInvalidEmail) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MessageInvalidEmail) ProtoMessage() {} + +func (x *MessageInvalidEmail) ProtoReflect() protoreflect.Message { + mi := &file_buf_validate_conformance_cases_emails_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MessageInvalidEmail.ProtoReflect.Descriptor instead. +func (*MessageInvalidEmail) Descriptor() ([]byte, []int) { + return file_buf_validate_conformance_cases_emails_proto_rawDescGZIP(), []int{0} +} + +func (x *MessageInvalidEmail) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +type MessageValidEmail struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` +} + +func (x *MessageValidEmail) Reset() { + *x = MessageValidEmail{} + if protoimpl.UnsafeEnabled { + mi := &file_buf_validate_conformance_cases_emails_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MessageValidEmail) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MessageValidEmail) ProtoMessage() {} + +func (x *MessageValidEmail) ProtoReflect() protoreflect.Message { + mi := &file_buf_validate_conformance_cases_emails_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MessageValidEmail.ProtoReflect.Descriptor instead. +func (*MessageValidEmail) Descriptor() ([]byte, []int) { + return file_buf_validate_conformance_cases_emails_proto_rawDescGZIP(), []int{1} +} + +func (x *MessageValidEmail) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +var File_buf_validate_conformance_cases_emails_proto protoreflect.FileDescriptor + +var file_buf_validate_conformance_cases_emails_proto_rawDesc = []byte{ + 0x0a, 0x2b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x63, + 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2f, 0x63, 0x61, 0x73, 0x65, 0x73, + 0x2f, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1e, 0x62, + 0x75, 0x66, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, + 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x63, 0x61, 0x73, 0x65, 0x73, 0x1a, 0x1b, 0x62, + 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, + 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x6f, 0x0a, 0x13, 0x4d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x45, 0x6d, 0x61, 0x69, + 0x6c, 0x12, 0x58, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x42, 0xba, 0x48, 0x3f, 0xba, 0x01, 0x3c, 0x0a, 0x0d, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, + 0x64, 0x5f, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1b, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x20, 0x6d, + 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, 0x61, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x65, + 0x6d, 0x61, 0x69, 0x6c, 0x1a, 0x0e, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x69, 0x73, 0x45, 0x6d, 0x61, + 0x69, 0x6c, 0x28, 0x29, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x22, 0x6b, 0x0a, 0x11, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x45, 0x6d, 0x61, 0x69, 0x6c, + 0x12, 0x56, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, + 0x40, 0xba, 0x48, 0x3d, 0xba, 0x01, 0x3a, 0x0a, 0x0b, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x5f, 0x65, + 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1b, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x20, 0x6d, 0x75, 0x73, 0x74, + 0x20, 0x62, 0x65, 0x20, 0x61, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x65, 0x6d, 0x61, 0x69, + 0x6c, 0x1a, 0x0e, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x69, 0x73, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x28, + 0x29, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x42, 0xa2, 0x02, 0x0a, 0x22, 0x63, 0x6f, 0x6d, + 0x2e, 0x62, 0x75, 0x66, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x6f, + 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x63, 0x61, 0x73, 0x65, 0x73, 0x42, + 0x0b, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x53, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, + 0x69, 0x6c, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, + 0x65, 0x2f, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, + 0x65, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2f, 0x63, 0x61, + 0x73, 0x65, 0x73, 0xa2, 0x02, 0x04, 0x42, 0x56, 0x43, 0x43, 0xaa, 0x02, 0x1e, 0x42, 0x75, 0x66, + 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, + 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x43, 0x61, 0x73, 0x65, 0x73, 0xca, 0x02, 0x1e, 0x42, 0x75, + 0x66, 0x5c, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, 0x6f, + 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0xe2, 0x02, 0x2a, 0x42, + 0x75, 0x66, 0x5c, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, + 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0x5c, 0x47, 0x50, + 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x21, 0x42, 0x75, 0x66, 0x3a, + 0x3a, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, 0x66, 0x6f, + 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x3a, 0x3a, 0x43, 0x61, 0x73, 0x65, 0x73, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_buf_validate_conformance_cases_emails_proto_rawDescOnce sync.Once + file_buf_validate_conformance_cases_emails_proto_rawDescData = file_buf_validate_conformance_cases_emails_proto_rawDesc +) + +func file_buf_validate_conformance_cases_emails_proto_rawDescGZIP() []byte { + file_buf_validate_conformance_cases_emails_proto_rawDescOnce.Do(func() { + file_buf_validate_conformance_cases_emails_proto_rawDescData = protoimpl.X.CompressGZIP(file_buf_validate_conformance_cases_emails_proto_rawDescData) + }) + return file_buf_validate_conformance_cases_emails_proto_rawDescData +} + +var file_buf_validate_conformance_cases_emails_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_buf_validate_conformance_cases_emails_proto_goTypes = []interface{}{ + (*MessageInvalidEmail)(nil), // 0: buf.validate.conformance.cases.MessageInvalidEmail + (*MessageValidEmail)(nil), // 1: buf.validate.conformance.cases.MessageValidEmail +} +var file_buf_validate_conformance_cases_emails_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_buf_validate_conformance_cases_emails_proto_init() } +func file_buf_validate_conformance_cases_emails_proto_init() { + if File_buf_validate_conformance_cases_emails_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_buf_validate_conformance_cases_emails_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MessageInvalidEmail); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_buf_validate_conformance_cases_emails_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MessageValidEmail); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_buf_validate_conformance_cases_emails_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_buf_validate_conformance_cases_emails_proto_goTypes, + DependencyIndexes: file_buf_validate_conformance_cases_emails_proto_depIdxs, + MessageInfos: file_buf_validate_conformance_cases_emails_proto_msgTypes, + }.Build() + File_buf_validate_conformance_cases_emails_proto = out.File + file_buf_validate_conformance_cases_emails_proto_rawDesc = nil + file_buf_validate_conformance_cases_emails_proto_goTypes = nil + file_buf_validate_conformance_cases_emails_proto_depIdxs = nil +} diff --git a/tools/protovalidate-conformance/internal/cases/cases.go b/tools/protovalidate-conformance/internal/cases/cases.go index f0725026..f95c936c 100644 --- a/tools/protovalidate-conformance/internal/cases/cases.go +++ b/tools/protovalidate-conformance/internal/cases/cases.go @@ -53,5 +53,6 @@ func GlobalSuites() suites.Suites { "standard_constraints/well_known_types/duration": durationSuite(), "standard_constraints/well_known_types/timestamp": timestampSuite(), "standard_constraints/well_known_types/wrapper": wrapperSuite(), + "standard_constraints/email": emailSuite(), } } diff --git a/tools/protovalidate-conformance/internal/cases/cases_email.go b/tools/protovalidate-conformance/internal/cases/cases_email.go new file mode 100644 index 00000000..a33a0cff --- /dev/null +++ b/tools/protovalidate-conformance/internal/cases/cases_email.go @@ -0,0 +1,71 @@ +// Copyright 2023 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cases + +import ( + "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate" + "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate/conformance/cases" + "github.com/bufbuild/protovalidate/tools/protovalidate-conformance/internal/results" + "github.com/bufbuild/protovalidate/tools/protovalidate-conformance/internal/suites" +) + +func emailSuite() suites.Suite { + return suites.Suite{ + "email/padded_center/invalid": { + Message: &cases.MessageInvalidEmail{Email: " foo@example.com "}, + Expected: results.Violations( + &validate.Violation{ + FieldPath: "email", + ConstraintId: "invalid_email", + Message: "email must be a valid email", + }, + ), + }, + "email/padded_left/invalid": { + Message: &cases.MessageInvalidEmail{Email: " foo@example.com"}, + Expected: results.Violations( + &validate.Violation{ + FieldPath: "email", + ConstraintId: "invalid_email", + Message: "email must be a valid email", + }, + ), + }, + "email/padded_right/invalid": { + Message: &cases.MessageInvalidEmail{Email: "foo@example.com "}, + Expected: results.Violations( + &validate.Violation{ + FieldPath: "email", + ConstraintId: "invalid_email", + Message: "email must be a valid email", + }, + ), + }, + "email/enclosed_<>/invalid": { + Message: &cases.MessageInvalidEmail{Email: ""}, + Expected: results.Violations( + &validate.Violation{ + FieldPath: "email", + ConstraintId: "invalid_email", + Message: "email must be a valid email", + }, + ), + }, + "email/valid": { + Message: &cases.MessageValidEmail{Email: "foo@example.com"}, + Expected: results.Success(true), + }, + } +} From 6d6634e848951adaa6c3c709805aae8071e8ce66 Mon Sep 17 00:00:00 2001 From: arun1587 Date: Sun, 18 Feb 2024 11:43:03 +0100 Subject: [PATCH 2/2] Add tests to target string.email standard constraint alongside the existing email tests --- .../validate/conformance/cases/emails.proto | 36 --- .../validate/conformance/cases/emails.pb.go | 251 ------------------ .../internal/cases/cases.go | 1 - .../internal/cases/cases_email.go | 71 ----- .../internal/cases/cases_strings.go | 20 ++ 5 files changed, 20 insertions(+), 359 deletions(-) delete mode 100644 proto/protovalidate-testing/buf/validate/conformance/cases/emails.proto delete mode 100644 tools/internal/gen/buf/validate/conformance/cases/emails.pb.go delete mode 100644 tools/protovalidate-conformance/internal/cases/cases_email.go diff --git a/proto/protovalidate-testing/buf/validate/conformance/cases/emails.proto b/proto/protovalidate-testing/buf/validate/conformance/cases/emails.proto deleted file mode 100644 index c6c99c69..00000000 --- a/proto/protovalidate-testing/buf/validate/conformance/cases/emails.proto +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2023 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package buf.validate.conformance.cases; - -import "buf/validate/validate.proto"; - -message MessageInvalidEmail { - string email = 1 [(buf.validate.field).cel = { - id: "invalid_email", - message: "email must be a valid email", - expression: "this.isEmail()" - }]; -} - - -message MessageValidEmail { - string email = 1 [(buf.validate.field).cel = { - id: "valid_email", - message: "email must be a valid email", - expression: "this.isEmail()" - }]; -} diff --git a/tools/internal/gen/buf/validate/conformance/cases/emails.pb.go b/tools/internal/gen/buf/validate/conformance/cases/emails.pb.go deleted file mode 100644 index c67bb9ce..00000000 --- a/tools/internal/gen/buf/validate/conformance/cases/emails.pb.go +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright 2023 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.31.0 -// protoc (unknown) -// source: buf/validate/conformance/cases/emails.proto - -package cases - -import ( - _ "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type MessageInvalidEmail struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` -} - -func (x *MessageInvalidEmail) Reset() { - *x = MessageInvalidEmail{} - if protoimpl.UnsafeEnabled { - mi := &file_buf_validate_conformance_cases_emails_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MessageInvalidEmail) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MessageInvalidEmail) ProtoMessage() {} - -func (x *MessageInvalidEmail) ProtoReflect() protoreflect.Message { - mi := &file_buf_validate_conformance_cases_emails_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use MessageInvalidEmail.ProtoReflect.Descriptor instead. -func (*MessageInvalidEmail) Descriptor() ([]byte, []int) { - return file_buf_validate_conformance_cases_emails_proto_rawDescGZIP(), []int{0} -} - -func (x *MessageInvalidEmail) GetEmail() string { - if x != nil { - return x.Email - } - return "" -} - -type MessageValidEmail struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` -} - -func (x *MessageValidEmail) Reset() { - *x = MessageValidEmail{} - if protoimpl.UnsafeEnabled { - mi := &file_buf_validate_conformance_cases_emails_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MessageValidEmail) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MessageValidEmail) ProtoMessage() {} - -func (x *MessageValidEmail) ProtoReflect() protoreflect.Message { - mi := &file_buf_validate_conformance_cases_emails_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use MessageValidEmail.ProtoReflect.Descriptor instead. -func (*MessageValidEmail) Descriptor() ([]byte, []int) { - return file_buf_validate_conformance_cases_emails_proto_rawDescGZIP(), []int{1} -} - -func (x *MessageValidEmail) GetEmail() string { - if x != nil { - return x.Email - } - return "" -} - -var File_buf_validate_conformance_cases_emails_proto protoreflect.FileDescriptor - -var file_buf_validate_conformance_cases_emails_proto_rawDesc = []byte{ - 0x0a, 0x2b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x63, - 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2f, 0x63, 0x61, 0x73, 0x65, 0x73, - 0x2f, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1e, 0x62, - 0x75, 0x66, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, - 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x63, 0x61, 0x73, 0x65, 0x73, 0x1a, 0x1b, 0x62, - 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x6f, 0x0a, 0x13, 0x4d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x45, 0x6d, 0x61, 0x69, - 0x6c, 0x12, 0x58, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x42, 0x42, 0xba, 0x48, 0x3f, 0xba, 0x01, 0x3c, 0x0a, 0x0d, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x5f, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1b, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x20, 0x6d, - 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, 0x61, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x65, - 0x6d, 0x61, 0x69, 0x6c, 0x1a, 0x0e, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x69, 0x73, 0x45, 0x6d, 0x61, - 0x69, 0x6c, 0x28, 0x29, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x22, 0x6b, 0x0a, 0x11, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x45, 0x6d, 0x61, 0x69, 0x6c, - 0x12, 0x56, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, - 0x40, 0xba, 0x48, 0x3d, 0xba, 0x01, 0x3a, 0x0a, 0x0b, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x5f, 0x65, - 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1b, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x20, 0x6d, 0x75, 0x73, 0x74, - 0x20, 0x62, 0x65, 0x20, 0x61, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x65, 0x6d, 0x61, 0x69, - 0x6c, 0x1a, 0x0e, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x69, 0x73, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x28, - 0x29, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x42, 0xa2, 0x02, 0x0a, 0x22, 0x63, 0x6f, 0x6d, - 0x2e, 0x62, 0x75, 0x66, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x6f, - 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x63, 0x61, 0x73, 0x65, 0x73, 0x42, - 0x0b, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x53, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, - 0x69, 0x6c, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, - 0x65, 0x2f, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, - 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, - 0x65, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2f, 0x63, 0x61, - 0x73, 0x65, 0x73, 0xa2, 0x02, 0x04, 0x42, 0x56, 0x43, 0x43, 0xaa, 0x02, 0x1e, 0x42, 0x75, 0x66, - 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, - 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x43, 0x61, 0x73, 0x65, 0x73, 0xca, 0x02, 0x1e, 0x42, 0x75, - 0x66, 0x5c, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, 0x6f, - 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0xe2, 0x02, 0x2a, 0x42, - 0x75, 0x66, 0x5c, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, - 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0x5c, 0x47, 0x50, - 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x21, 0x42, 0x75, 0x66, 0x3a, - 0x3a, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, 0x66, 0x6f, - 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x3a, 0x3a, 0x43, 0x61, 0x73, 0x65, 0x73, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_buf_validate_conformance_cases_emails_proto_rawDescOnce sync.Once - file_buf_validate_conformance_cases_emails_proto_rawDescData = file_buf_validate_conformance_cases_emails_proto_rawDesc -) - -func file_buf_validate_conformance_cases_emails_proto_rawDescGZIP() []byte { - file_buf_validate_conformance_cases_emails_proto_rawDescOnce.Do(func() { - file_buf_validate_conformance_cases_emails_proto_rawDescData = protoimpl.X.CompressGZIP(file_buf_validate_conformance_cases_emails_proto_rawDescData) - }) - return file_buf_validate_conformance_cases_emails_proto_rawDescData -} - -var file_buf_validate_conformance_cases_emails_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_buf_validate_conformance_cases_emails_proto_goTypes = []interface{}{ - (*MessageInvalidEmail)(nil), // 0: buf.validate.conformance.cases.MessageInvalidEmail - (*MessageValidEmail)(nil), // 1: buf.validate.conformance.cases.MessageValidEmail -} -var file_buf_validate_conformance_cases_emails_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_buf_validate_conformance_cases_emails_proto_init() } -func file_buf_validate_conformance_cases_emails_proto_init() { - if File_buf_validate_conformance_cases_emails_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_buf_validate_conformance_cases_emails_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MessageInvalidEmail); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_buf_validate_conformance_cases_emails_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MessageValidEmail); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_buf_validate_conformance_cases_emails_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_buf_validate_conformance_cases_emails_proto_goTypes, - DependencyIndexes: file_buf_validate_conformance_cases_emails_proto_depIdxs, - MessageInfos: file_buf_validate_conformance_cases_emails_proto_msgTypes, - }.Build() - File_buf_validate_conformance_cases_emails_proto = out.File - file_buf_validate_conformance_cases_emails_proto_rawDesc = nil - file_buf_validate_conformance_cases_emails_proto_goTypes = nil - file_buf_validate_conformance_cases_emails_proto_depIdxs = nil -} diff --git a/tools/protovalidate-conformance/internal/cases/cases.go b/tools/protovalidate-conformance/internal/cases/cases.go index f95c936c..f0725026 100644 --- a/tools/protovalidate-conformance/internal/cases/cases.go +++ b/tools/protovalidate-conformance/internal/cases/cases.go @@ -53,6 +53,5 @@ func GlobalSuites() suites.Suites { "standard_constraints/well_known_types/duration": durationSuite(), "standard_constraints/well_known_types/timestamp": timestampSuite(), "standard_constraints/well_known_types/wrapper": wrapperSuite(), - "standard_constraints/email": emailSuite(), } } diff --git a/tools/protovalidate-conformance/internal/cases/cases_email.go b/tools/protovalidate-conformance/internal/cases/cases_email.go deleted file mode 100644 index a33a0cff..00000000 --- a/tools/protovalidate-conformance/internal/cases/cases_email.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2023 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cases - -import ( - "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate" - "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate/conformance/cases" - "github.com/bufbuild/protovalidate/tools/protovalidate-conformance/internal/results" - "github.com/bufbuild/protovalidate/tools/protovalidate-conformance/internal/suites" -) - -func emailSuite() suites.Suite { - return suites.Suite{ - "email/padded_center/invalid": { - Message: &cases.MessageInvalidEmail{Email: " foo@example.com "}, - Expected: results.Violations( - &validate.Violation{ - FieldPath: "email", - ConstraintId: "invalid_email", - Message: "email must be a valid email", - }, - ), - }, - "email/padded_left/invalid": { - Message: &cases.MessageInvalidEmail{Email: " foo@example.com"}, - Expected: results.Violations( - &validate.Violation{ - FieldPath: "email", - ConstraintId: "invalid_email", - Message: "email must be a valid email", - }, - ), - }, - "email/padded_right/invalid": { - Message: &cases.MessageInvalidEmail{Email: "foo@example.com "}, - Expected: results.Violations( - &validate.Violation{ - FieldPath: "email", - ConstraintId: "invalid_email", - Message: "email must be a valid email", - }, - ), - }, - "email/enclosed_<>/invalid": { - Message: &cases.MessageInvalidEmail{Email: ""}, - Expected: results.Violations( - &validate.Violation{ - FieldPath: "email", - ConstraintId: "invalid_email", - Message: "email must be a valid email", - }, - ), - }, - "email/valid": { - Message: &cases.MessageValidEmail{Email: "foo@example.com"}, - Expected: results.Success(true), - }, - } -} diff --git a/tools/protovalidate-conformance/internal/cases/cases_strings.go b/tools/protovalidate-conformance/internal/cases/cases_strings.go index ce4acc38..e4b50164 100644 --- a/tools/protovalidate-conformance/internal/cases/cases_strings.go +++ b/tools/protovalidate-conformance/internal/cases/cases_strings.go @@ -326,6 +326,26 @@ func stringSuite() suites.Suite { Expected: results.Violations( &validate.Violation{FieldPath: "val", ConstraintId: "string.email"}), }, + "email/invalid/white_spaces": { + Message: &cases.StringEmail{Val: " foo@example.com "}, + Expected: results.Violations( + &validate.Violation{FieldPath: "val", ConstraintId: "string.email"}), + }, + "email/invalid/trailing_white_space": { + Message: &cases.StringEmail{Val: "foo@example.com "}, + Expected: results.Violations( + &validate.Violation{FieldPath: "val", ConstraintId: "string.email"}), + }, + "email/invalid/leading_white_space": { + Message: &cases.StringEmail{Val: " foo@example.com"}, + Expected: results.Violations( + &validate.Violation{FieldPath: "val", ConstraintId: "string.email"}), + }, + "email/invalid/angled_brackets": { + Message: &cases.StringEmail{Val: ""}, + Expected: results.Violations( + &validate.Violation{FieldPath: "val", ConstraintId: "string.email"}), + }, "hostname/invalid/empty": { Message: &cases.StringHostname{Val: ""}, Expected: results.Violations(