Skip to content

Commit f71c56d

Browse files
committed
Removed too much
1 parent fa7e456 commit f71c56d

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

google/cloud/storage/internal/grpc_client.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,12 @@ std::string GrpcClient::MD5FromProto(std::string const& v) {
18711871
return internal::Base64Encode(binary);
18721872
}
18731873

1874+
std::string GrpcClient::MD5ToProto(std::string const& v) {
1875+
if (v.empty()) return {};
1876+
auto binary = internal::Base64Decode(v);
1877+
return internal::HexEncode(binary);
1878+
}
1879+
18741880
std::string GrpcClient::ComputeMD5Hash(const std::string& payload) {
18751881
return internal::HexEncode(internal::MD5Hash(payload));
18761882
}

google/cloud/storage/internal/grpc_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ class GrpcClient : public RawClient,
322322
static std::string Crc32cFromProto(google::protobuf::UInt32Value const&);
323323
static std::uint32_t Crc32cToProto(std::string const&);
324324
static std::string MD5FromProto(std::string const&);
325+
static std::string MD5ToProto(std::string const&);
325326
static std::string ComputeMD5Hash(std::string const& payload);
326327

327328
protected:

google/cloud/storage/internal/grpc_client_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ TEST(GrpcClientFromProto, MD5Roundtrip) {
221221
{"96HF9K981B+JfoQuTVnyCg==", "f7a1c5f4af7cd41f897e842e4d59f20a"},
222222
};
223223
for (auto const& test : cases) {
224-
auto actual = GrpcClient::MD5FromProto(test.proto);
225-
EXPECT_EQ(actual, test.rest);
224+
EXPECT_EQ(GrpcClient::MD5FromProto(test.proto), test.rest);
225+
EXPECT_EQ(GrpcClient::MD5ToProto(test.rest), test.proto);
226226
}
227227
}
228228

google/cloud/storage/internal/grpc_object_read_source_test.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,16 @@ TEST(GrpcObjectReadSource, UseSpillBufferMany) {
190190

191191
TEST(GrpcObjectReadSource, PreserveChecksums) {
192192
auto mock = absl::make_unique<MockStream>();
193-
std::string const expected_md5 = "9e107d9d372bb6826bd81d3542a419d6";
194-
std::string const expected_crc32c = "ImIEBA==";
193+
std::string const expected_payload =
194+
"The quick brown fox jumps over the lazy dog";
195+
auto const expected_md5 = ComputeMD5Hash(expected_payload);
196+
auto const expected_crc32c = ComputeCrc32cChecksum(expected_payload);
195197
EXPECT_CALL(*mock, Read)
196198
.WillOnce([&]() {
197199
storage_proto::GetObjectMediaResponse response;
198200
response.mutable_checksummed_data()->set_content("The quick brown");
199-
response.mutable_object_checksums()->set_md5_hash(expected_md5);
201+
response.mutable_object_checksums()->set_md5_hash(
202+
GrpcClient::MD5ToProto(expected_md5));
200203
response.mutable_object_checksums()->mutable_crc32c()->set_value(
201204
GrpcClient::Crc32cToProto(expected_crc32c));
202205
return response;
@@ -207,21 +210,21 @@ TEST(GrpcObjectReadSource, PreserveChecksums) {
207210
" fox jumps over the lazy dog");
208211
// The headers may be included more than once in the stream,
209212
// `GrpcObjectReadSource` should return them only once.
210-
response.mutable_object_checksums()->set_md5_hash(expected_md5);
213+
response.mutable_object_checksums()->set_md5_hash(
214+
GrpcClient::MD5ToProto(expected_md5));
211215
response.mutable_object_checksums()->mutable_crc32c()->set_value(
212216
GrpcClient::Crc32cToProto(expected_crc32c));
213217
return response;
214218
})
215219
.WillOnce(Return(Status{}));
216220
GrpcObjectReadSource tested(std::move(mock));
217-
std::string const expected = "The quick brown fox jumps over the lazy dog";
218221
std::vector<char> buffer(1024);
219222
auto response = tested.Read(buffer.data(), buffer.size());
220223
ASSERT_STATUS_OK(response);
221-
EXPECT_EQ(expected.size(), response->bytes_received);
224+
EXPECT_EQ(expected_payload.size(), response->bytes_received);
222225
EXPECT_EQ(100, response->response.status_code);
223-
std::string actual(buffer.data(), expected.size());
224-
EXPECT_EQ(expected, actual);
226+
auto const actual = std::string(buffer.data(), response->bytes_received);
227+
EXPECT_EQ(expected_payload, actual);
225228
auto const& headers = response->response.headers;
226229
EXPECT_FALSE(headers.find("x-goog-hash") == headers.end());
227230
auto const values = [&headers] {
@@ -232,9 +235,8 @@ TEST(GrpcObjectReadSource, PreserveChecksums) {
232235
}
233236
return v;
234237
}();
235-
EXPECT_THAT(values, UnorderedElementsAre(
236-
"crc32c=" + expected_crc32c,
237-
"md5=" + GrpcClient::MD5FromProto(expected_md5)));
238+
EXPECT_THAT(values, UnorderedElementsAre("crc32c=" + expected_crc32c,
239+
"md5=" + expected_md5));
238240

239241
auto status = tested.Close();
240242
EXPECT_STATUS_OK(status);

0 commit comments

Comments
 (0)