Copilot commented on code in PR #3658:
URL: https://github.com/apache/brpc/pull/3658#discussion_r4373544327
##########
test/brpc_checksum_unittest.cpp:
##########
@@ -50,6 +51,34 @@ TEST_F(ChecksumAttachmentTest,
verify_succeeds_when_body_only) {
EXPECT_TRUE(brpc::policy::Crc32cVerify(verify_in));
}
+TEST_F(ChecksumAttachmentTest, verify_rejects_invalid_checksum_lengths) {
+ brpc::Controller cntl;
+ butil::IOBuf body;
+ body.append("request body");
+ brpc::ChecksumIn in{&body, &cntl, nullptr};
+ brpc::policy::Crc32cCompute(in);
+ brpc::ControllerPrivateAccessor accessor(&cntl);
+ const std::string valid = accessor.checksum_value();
+ ASSERT_EQ(sizeof(uint32_t), valid.size());
+
+ logging::StringSink logs;
+ {
+ logging::LogSink* previous = logging::SetLogSink(&logs);
+ BUTIL_SCOPE_EXIT { logging::SetLogSink(previous); };
+ for (size_t size = 0; size <= 8; ++size) {
+ if (size == valid.size()) {
+ continue;
+ }
+ const std::string invalid(size, '\0');
+ accessor.set_checksum_value(invalid.data(), invalid.size());
+ EXPECT_FALSE(brpc::policy::Crc32cVerify(in)) << "size=" << size;
+ }
+ accessor.set_checksum_value(valid.data(), valid.size());
+ EXPECT_TRUE(brpc::policy::Crc32cVerify(in));
+ }
+ EXPECT_EQ(std::string::npos, logs.find("Check failed: val.size()"));
Review Comment:
With `BRPC_WITH_GLOG=1`, this test fails to compile: `logging::StringSink`,
`logging::LogSink`, and `logging::SetLogSink` are declared only in the non-glog
branch of `butil/logging.h`. Guard the log-capture setup, restoration, and
assertion with `#if !BRPC_WITH_GLOG`, as in
`test/brpc_socket_unittest.cpp:912–923`, while keeping the checksum assertions
enabled for both logging backends.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]