Skip to content

Commit a3da4a0

Browse files
committed
Fix default tests for object hash and checksum
1 parent acfff2f commit a3da4a0

2 files changed

Lines changed: 88 additions & 51 deletions

File tree

google/cloud/storage/tests/object_checksum_integration_test.cc

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TEST_F(ObjectChecksumIntegrationTest, InsertObjectDefault) {
5454
auto client = MakeIntegrationTestClient();
5555
auto object_name = MakeRandomObjectName();
5656
auto meta = client.InsertObject(bucket_name_, object_name, LoremIpsum(),
57-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c), IfGenerationMatch(0));
57+
IfGenerationMatch(0));
5858
ASSERT_STATUS_OK(meta);
5959
ScheduleForDelete(*meta);
6060

@@ -64,12 +64,16 @@ TEST_F(ObjectChecksumIntegrationTest, InsertObjectDefault) {
6464
}
6565
}
6666

67-
/// @test Verify that `Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5)` works as expected.
67+
/// @test Verify that
68+
/// `Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5)`
69+
/// works as expected.
6870
TEST_F(ObjectChecksumIntegrationTest, InsertObjectExplicitDisable) {
6971
auto client = MakeIntegrationTestClient();
7072
auto object_name = MakeRandomObjectName();
71-
auto meta = client.InsertObject(bucket_name_, object_name, LoremIpsum(),
72-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kNone), IfGenerationMatch(0));
73+
auto meta = client.InsertObject(
74+
bucket_name_, object_name, LoremIpsum(),
75+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kNone),
76+
IfGenerationMatch(0));
7377
ASSERT_STATUS_OK(meta);
7478
ScheduleForDelete(*meta);
7579

@@ -79,13 +83,17 @@ TEST_F(ObjectChecksumIntegrationTest, InsertObjectExplicitDisable) {
7983
}
8084
}
8185

82-
/// @test Verify that `Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c)` works as expected.
86+
/// @test Verify that
87+
/// `Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c)`
88+
/// works as expected.
8389
TEST_F(ObjectChecksumIntegrationTest, InsertObjectExplicitEnable) {
8490
auto client = MakeIntegrationTestClient();
8591
auto object_name = MakeRandomObjectName();
8692

87-
auto meta = client.InsertObject(bucket_name_, object_name, LoremIpsum(),
88-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c), IfGenerationMatch(0));
93+
auto meta = client.InsertObject(
94+
bucket_name_, object_name, LoremIpsum(),
95+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
96+
IfGenerationMatch(0));
8997
ASSERT_STATUS_OK(meta);
9098
ScheduleForDelete(*meta);
9199

@@ -102,7 +110,8 @@ TEST_F(ObjectChecksumIntegrationTest, InsertObjectWithValueSuccess) {
102110
auto meta = client.InsertObject(
103111
bucket_name_, object_name, LoremIpsum(),
104112
Crc32cChecksumValue(ComputeCrc32cChecksum(LoremIpsum())),
105-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c), IfGenerationMatch(0));
113+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
114+
IfGenerationMatch(0));
106115
ASSERT_STATUS_OK(meta);
107116
ScheduleForDelete(*meta);
108117

@@ -120,7 +129,8 @@ TEST_F(ObjectChecksumIntegrationTest, InsertObjectWithValueFailure) {
120129
auto object_name = MakeRandomObjectName();
121130

122131
auto failure = client.InsertObject(
123-
bucket_name_, object_name, LoremIpsum(), Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
132+
bucket_name_, object_name, LoremIpsum(),
133+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
124134
IfGenerationMatch(0), Crc32cChecksumValue(ComputeCrc32cChecksum("")));
125135
EXPECT_THAT(failure, Not(IsOk()));
126136
}
@@ -130,8 +140,7 @@ TEST_F(ObjectChecksumIntegrationTest, WriteObjectDefault) {
130140
auto client = MakeIntegrationTestClient();
131141
auto object_name = MakeRandomObjectName();
132142

133-
auto os = client.WriteObject(bucket_name_, object_name, Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
134-
IfGenerationMatch(0));
143+
auto os = client.WriteObject(bucket_name_, object_name, IfGenerationMatch(0));
135144
os << LoremIpsum();
136145
os.Close();
137146
auto meta = os.metadata();
@@ -155,8 +164,10 @@ TEST_F(ObjectChecksumIntegrationTest, WriteObjectExplicitDisable) {
155164
auto client = MakeIntegrationTestClient();
156165
auto object_name = MakeRandomObjectName();
157166

158-
auto os =
159-
client.WriteObject(bucket_name_, object_name, Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kNone), IfGenerationMatch(0));
167+
auto os = client.WriteObject(
168+
bucket_name_, object_name,
169+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kNone),
170+
IfGenerationMatch(0));
160171
os << LoremIpsum();
161172
os.Close();
162173
auto meta = os.metadata();
@@ -178,8 +189,10 @@ TEST_F(ObjectChecksumIntegrationTest, WriteObjectExplicitDisable) {
178189
TEST_F(ObjectChecksumIntegrationTest, WriteObjectExplicitEnable) {
179190
auto client = MakeIntegrationTestClient();
180191
auto object_name = MakeRandomObjectName();
181-
auto os = client.WriteObject(bucket_name_, object_name,
182-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c), IfGenerationMatch(0));
192+
auto os = client.WriteObject(
193+
bucket_name_, object_name,
194+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
195+
IfGenerationMatch(0));
183196
os << LoremIpsum();
184197
os.Close();
185198
auto meta = os.metadata();
@@ -204,7 +217,8 @@ TEST_F(ObjectChecksumIntegrationTest, WriteObjectWithValueSuccess) {
204217
auto os = client.WriteObject(
205218
bucket_name_, object_name,
206219
Crc32cChecksumValue(ComputeCrc32cChecksum(LoremIpsum())),
207-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c), IfGenerationMatch(0));
220+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
221+
IfGenerationMatch(0));
208222
os << LoremIpsum();
209223
os.Close();
210224
auto meta = os.metadata();
@@ -227,7 +241,8 @@ TEST_F(ObjectChecksumIntegrationTest, WriteObjectWithValueFailure) {
227241

228242
auto os = client.WriteObject(
229243
bucket_name_, object_name, MD5HashValue(ComputeMD5Hash("")),
230-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5), IfGenerationMatch(0));
244+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
245+
IfGenerationMatch(0));
231246
os << LoremIpsum();
232247
os.Close();
233248
auto meta = os.metadata();
@@ -246,7 +261,8 @@ TEST_F(ObjectChecksumIntegrationTest, WriteObjectReceiveBadChecksum) {
246261

247262
// Create a stream to upload an object.
248263
ObjectWriteStream stream = client.WriteObject(
249-
bucket_name_, object_name, Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
264+
bucket_name_, object_name,
265+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
250266
CustomHeader("x-goog-emulator-instructions", "inject-upload-data-error"),
251267
IfGenerationMatch(0));
252268
stream << LoremIpsum() << "\n";
@@ -267,7 +283,8 @@ TEST_F(ObjectChecksumIntegrationTest, WriteObjectUploadBadChecksum) {
267283
// Create a stream to upload an object.
268284
ObjectWriteStream stream = client.WriteObject(
269285
bucket_name_, object_name, Crc32cChecksumValue(ComputeCrc32cChecksum("")),
270-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c), IfGenerationMatch(0));
286+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
287+
IfGenerationMatch(0));
271288
stream << LoremIpsum() << "\n";
272289
stream.Close();
273290
EXPECT_TRUE(stream.bad());
@@ -281,8 +298,10 @@ TEST_F(ObjectChecksumIntegrationTest, WriteObjectWithFullChecksumValidation) {
281298
auto content = LoremIpsum();
282299
auto expected_crc32c = ComputeCrc32cChecksum(content);
283300

284-
auto os = client.WriteObject(bucket_name_, object_name,
285-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c), IfGenerationMatch(0));
301+
auto os = client.WriteObject(
302+
bucket_name_, object_name,
303+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
304+
IfGenerationMatch(0));
286305
os << content;
287306
os.Close();
288307
auto meta = os.metadata();
@@ -310,9 +329,10 @@ TEST_F(ObjectChecksumIntegrationTest, WriteObjectWithIncorrectChecksumValue) {
310329
auto bad_crc32c =
311330
ComputeCrc32cChecksum("this is not the data being uploaded");
312331

313-
auto os = client.WriteObject(bucket_name_, object_name,
314-
Crc32cChecksumValue(bad_crc32c),
315-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c), IfGenerationMatch(0));
332+
auto os = client.WriteObject(
333+
bucket_name_, object_name, Crc32cChecksumValue(bad_crc32c),
334+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
335+
IfGenerationMatch(0));
316336

317337
os << content;
318338
os.Close();
@@ -358,7 +378,9 @@ TEST_F(ObjectChecksumIntegrationTest, ReadObjectCorruptedByServerGetc) {
358378
ScheduleForDelete(*meta);
359379

360380
auto stream = client.ReadObject(
361-
bucket_name_, object_name, Options{}.set<DownloadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
381+
bucket_name_, object_name,
382+
Options{}.set<DownloadChecksumValidationOption>(
383+
ChecksumAlgorithm::kCrc32c),
362384
CustomHeader("x-goog-emulator-instructions", "return-corrupted-data"));
363385

364386
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
@@ -398,7 +420,9 @@ TEST_F(ObjectChecksumIntegrationTest, ReadObjectCorruptedByServerRead) {
398420
ScheduleForDelete(*meta);
399421

400422
auto stream = client.ReadObject(
401-
bucket_name_, object_name, Options{}.set<DownloadChecksumValidationOption>(ChecksumAlgorithm::kCrc32c),
423+
bucket_name_, object_name,
424+
Options{}.set<DownloadChecksumValidationOption>(
425+
ChecksumAlgorithm::kCrc32c),
402426
CustomHeader("x-goog-emulator-instructions", "return-corrupted-data"));
403427

404428
// Create a buffer large enough to read the full contents.

google/cloud/storage/tests/object_hash_integration_test.cc

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,13 @@ class ObjectHashIntegrationTest
5757
TEST_F(ObjectHashIntegrationTest, InsertObjectDefault) {
5858
auto client = MakeIntegrationTestClient();
5959
auto object_name = MakeRandomObjectName();
60-
auto meta =
61-
client.InsertObject(bucket_name_, object_name, LoremIpsum(),
62-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5), IfGenerationMatch(0));
60+
auto meta = client.InsertObject(bucket_name_, object_name, LoremIpsum(),
61+
IfGenerationMatch(0));
6362
ASSERT_STATUS_OK(meta);
6463
ScheduleForDelete(*meta);
6564

6665
if (meta->has_metadata("x_emulator_upload")) {
67-
ASSERT_FALSE(meta->has_metadata("x_emulator_crc32c"));
66+
ASSERT_TRUE(meta->has_metadata("x_emulator_crc32c"));
6867
ASSERT_FALSE(meta->has_metadata("x_emulator_md5"));
6968
}
7069
}
@@ -75,7 +74,9 @@ TEST_F(ObjectHashIntegrationTest, InsertObjectExplicitDisable) {
7574
auto object_name = MakeRandomObjectName();
7675

7776
auto meta = client.InsertObject(
78-
bucket_name_, object_name, LoremIpsum(), Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kNone), IfGenerationMatch(0));
77+
bucket_name_, object_name, LoremIpsum(),
78+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kNone),
79+
IfGenerationMatch(0));
7980
ASSERT_STATUS_OK(meta);
8081
ScheduleForDelete(*meta);
8182

@@ -91,7 +92,9 @@ TEST_F(ObjectHashIntegrationTest, InsertObjectExplicitEnable) {
9192
auto object_name = MakeRandomObjectName();
9293

9394
auto meta = client.InsertObject(
94-
bucket_name_, object_name, LoremIpsum(), Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5), IfGenerationMatch(0));
95+
bucket_name_, object_name, LoremIpsum(),
96+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
97+
IfGenerationMatch(0));
9598
ASSERT_STATUS_OK(meta);
9699
ScheduleForDelete(*meta);
97100

@@ -105,10 +108,11 @@ TEST_F(ObjectHashIntegrationTest, InsertObjectExplicitEnable) {
105108
TEST_F(ObjectHashIntegrationTest, InsertObjectWithValueSuccess) {
106109
auto client = MakeIntegrationTestClient();
107110
auto object_name = MakeRandomObjectName();
108-
auto meta =
109-
client.InsertObject(bucket_name_, object_name, LoremIpsum(),
110-
MD5HashValue(ComputeMD5Hash(LoremIpsum())),
111-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5), IfGenerationMatch(0));
111+
auto meta = client.InsertObject(
112+
bucket_name_, object_name, LoremIpsum(),
113+
MD5HashValue(ComputeMD5Hash(LoremIpsum())),
114+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
115+
IfGenerationMatch(0));
112116
ASSERT_STATUS_OK(meta);
113117
ScheduleForDelete(*meta);
114118

@@ -128,17 +132,16 @@ TEST_F(ObjectHashIntegrationTest, InsertObjectWithValueFailure) {
128132

129133
auto failure = client.InsertObject(
130134
bucket_name_, object_name, LoremIpsum(), MD5HashValue(ComputeMD5Hash("")),
131-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5), IfGenerationMatch(0));
135+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
136+
IfGenerationMatch(0));
132137
EXPECT_THAT(failure, Not(IsOk()));
133138
}
134139

135140
/// @test Verify that MD5 hashes are disabled by default in WriteObject().
136141
TEST_F(ObjectHashIntegrationTest, WriteObjectDefault) {
137142
auto client = MakeIntegrationTestClient();
138143
auto object_name = MakeRandomObjectName();
139-
auto os =
140-
client.WriteObject(bucket_name_, object_name, Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
141-
IfGenerationMatch(0));
144+
auto os = client.WriteObject(bucket_name_, object_name, IfGenerationMatch(0));
142145
os << LoremIpsum();
143146
os.Close();
144147
auto meta = os.metadata();
@@ -148,7 +151,7 @@ TEST_F(ObjectHashIntegrationTest, WriteObjectDefault) {
148151
EXPECT_THAT(os.received_hash(), Not(HasSubstr(ComputeMD5Hash(LoremIpsum()))));
149152
EXPECT_THAT(os.computed_hash(), Not(HasSubstr(ComputeMD5Hash(LoremIpsum()))));
150153
if (meta->has_metadata("x_emulator_upload")) {
151-
ASSERT_TRUE(meta->has_metadata("x_emulator_no_crc32c"));
154+
ASSERT_FALSE(meta->has_metadata("x_emulator_no_crc32c"));
152155
ASSERT_TRUE(meta->has_metadata("x_emulator_no_md5"));
153156
}
154157
}
@@ -157,8 +160,10 @@ TEST_F(ObjectHashIntegrationTest, WriteObjectDefault) {
157160
TEST_F(ObjectHashIntegrationTest, WriteObjectExplicitDisable) {
158161
auto client = MakeIntegrationTestClient();
159162
auto object_name = MakeRandomObjectName();
160-
auto os =
161-
client.WriteObject(bucket_name_, object_name, Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kNone), IfGenerationMatch(0));
163+
auto os = client.WriteObject(
164+
bucket_name_, object_name,
165+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kNone),
166+
IfGenerationMatch(0));
162167
os << LoremIpsum();
163168
os.Close();
164169
auto meta = os.metadata();
@@ -177,8 +182,10 @@ TEST_F(ObjectHashIntegrationTest, WriteObjectExplicitDisable) {
177182
TEST_F(ObjectHashIntegrationTest, WriteObjectExplicitEnable) {
178183
auto client = MakeIntegrationTestClient();
179184
auto object_name = MakeRandomObjectName();
180-
auto os =
181-
client.WriteObject(bucket_name_, object_name, Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5), IfGenerationMatch(0));
185+
auto os = client.WriteObject(
186+
bucket_name_, object_name,
187+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
188+
IfGenerationMatch(0));
182189
os << LoremIpsum();
183190
os.Close();
184191
auto meta = os.metadata();
@@ -199,7 +206,8 @@ TEST_F(ObjectHashIntegrationTest, WriteObjectWithValueSuccess) {
199206
auto object_name = MakeRandomObjectName();
200207
auto os = client.WriteObject(
201208
bucket_name_, object_name, MD5HashValue(ComputeMD5Hash(LoremIpsum())),
202-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5), IfGenerationMatch(0));
209+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
210+
IfGenerationMatch(0));
203211
os << LoremIpsum();
204212
os.Close();
205213
auto meta = os.metadata();
@@ -224,7 +232,8 @@ TEST_F(ObjectHashIntegrationTest, WriteObjectWithValueFailure) {
224232
auto object_name = MakeRandomObjectName();
225233
auto os = client.WriteObject(
226234
bucket_name_, object_name, MD5HashValue(ComputeMD5Hash("")),
227-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5), IfGenerationMatch(0));
235+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
236+
IfGenerationMatch(0));
228237
os << LoremIpsum();
229238
os.Close();
230239
auto meta = os.metadata();
@@ -243,7 +252,8 @@ TEST_F(ObjectHashIntegrationTest, WriteObjectReceiveBadChecksum) {
243252

244253
// Create a stream to upload an object.
245254
ObjectWriteStream stream = client.WriteObject(
246-
bucket_name_, object_name, Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
255+
bucket_name_, object_name,
256+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
247257
CustomHeader("x-goog-emulator-instructions", "inject-upload-data-error"),
248258
IfGenerationMatch(0));
249259
stream << LoremIpsum() << "\n";
@@ -264,7 +274,8 @@ TEST_F(ObjectHashIntegrationTest, WriteObjectUploadBadChecksum) {
264274
// Create a stream to upload an object.
265275
ObjectWriteStream stream = client.WriteObject(
266276
bucket_name_, object_name, MD5HashValue(ComputeMD5Hash("")),
267-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5), IfGenerationMatch(0));
277+
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
278+
IfGenerationMatch(0));
268279
stream << LoremIpsum() << "\n";
269280
stream.Close();
270281
EXPECT_TRUE(stream.bad());
@@ -307,7 +318,8 @@ TEST_F(ObjectHashIntegrationTest, ReadObjectCorruptedByServerGetc) {
307318
ScheduleForDelete(*meta);
308319

309320
auto stream = client.ReadObject(
310-
bucket_name_, object_name, Options{}.set<DownloadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
321+
bucket_name_, object_name,
322+
Options{}.set<DownloadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
311323
CustomHeader("x-goog-emulator-instructions", "return-corrupted-data"));
312324

313325
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
@@ -346,7 +358,8 @@ TEST_F(ObjectHashIntegrationTest, ReadObjectCorruptedByServerRead) {
346358
ScheduleForDelete(*meta);
347359

348360
auto stream = client.ReadObject(
349-
bucket_name_, object_name, Options{}.set<DownloadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
361+
bucket_name_, object_name,
362+
Options{}.set<DownloadChecksumValidationOption>(ChecksumAlgorithm::kMD5),
350363
CustomHeader("x-goog-emulator-instructions", "return-corrupted-data"));
351364

352365
// Create a buffer large enough to read the full contents.

0 commit comments

Comments
 (0)