-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
protobuf: report field numbers for unknown fields. #7978
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,15 +147,31 @@ TEST_F(ProtobufUtilityTest, LoadBinaryProtoFromFile) { | |
EXPECT_TRUE(TestUtility::protoEqual(bootstrap, proto_from_file)); | ||
} | ||
|
||
// An unknown field (or with wrong type) in a message is rejected. | ||
TEST_F(ProtobufUtilityTest, LoadBinaryProtoUnknownFieldFromFile) { | ||
ProtobufWkt::Duration source_duration; | ||
source_duration.set_seconds(42); | ||
const std::string filename = | ||
TestEnvironment::writeStringToFileForTest("proto.pb", source_duration.SerializeAsString()); | ||
envoy::config::bootstrap::v2::Bootstrap proto_from_file; | ||
EXPECT_THROW_WITH_MESSAGE( | ||
TestUtility::loadFromFile(filename, proto_from_file, *api_), EnvoyException, | ||
"Protobuf message (type envoy.config.bootstrap.v2.Bootstrap) has unknown fields"); | ||
EXPECT_THROW_WITH_MESSAGE(TestUtility::loadFromFile(filename, proto_from_file, *api_), | ||
EnvoyException, | ||
"Protobuf message (type envoy.config.bootstrap.v2.Bootstrap with " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this error message is a bit redundant with multiple "unknown fields." Any way to clean it up a bit with the new logic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed this to |
||
"unknown field(s) 1) has unknown fields"); | ||
} | ||
|
||
// Multiple unknown fields (or with wrong type) in a message are rejected. | ||
TEST_F(ProtobufUtilityTest, LoadBinaryProtoUnknownMultipleFieldsFromFile) { | ||
ProtobufWkt::Duration source_duration; | ||
source_duration.set_seconds(42); | ||
source_duration.set_nanos(42); | ||
const std::string filename = | ||
TestEnvironment::writeStringToFileForTest("proto.pb", source_duration.SerializeAsString()); | ||
envoy::config::bootstrap::v2::Bootstrap proto_from_file; | ||
EXPECT_THROW_WITH_MESSAGE(TestUtility::loadFromFile(filename, proto_from_file, *api_), | ||
EnvoyException, | ||
"Protobuf message (type envoy.config.bootstrap.v2.Bootstrap with " | ||
"unknown field(s) 1, 2) has unknown fields"); | ||
} | ||
|
||
TEST_F(ProtobufUtilityTest, LoadTextProtoFromFile) { | ||
|
@@ -333,7 +349,8 @@ TEST_F(ProtobufUtilityTest, AnyConvertWrongFields) { | |
source_any.set_type_url("type.google.com/google.protobuf.Timestamp"); | ||
EXPECT_THROW_WITH_MESSAGE(TestUtility::anyConvert<ProtobufWkt::Timestamp>(source_any), | ||
EnvoyException, | ||
"Protobuf message (type google.protobuf.Timestamp) has unknown fields"); | ||
"Protobuf message (type google.protobuf.Timestamp with unknown " | ||
"field(s) 1) has unknown fields"); | ||
} | ||
|
||
TEST_F(ProtobufUtilityTest, JsonConvertSuccess) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be done recursively for embedded message fields?
If I remember, this method also causes allocation of metadata and has performance impact. Perhaps, things are better now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fair point; this is actually a bug in the existing implementation. We should do it (folks can always disable the checking if they don't want the performance impact). Let me fix that in a followup PR, tracking in #7980.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: const auto