Skip to content

Commit 1acb14f

Browse files
committed
ARSN-575: return part checksum external AWS backend
1 parent d66e665 commit 1acb14f

2 files changed

Lines changed: 86 additions & 5 deletions

File tree

lib/storage/data/external/AwsClient.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ const missingVerIdInternalError = errorInstances.InternalError.customizeDescript
3333
'Invalid state. Please ensure versioning is enabled ' +
3434
'in AWS for the location constraint and try again.',
3535
);
36+
const awsPartChecksumFields = {
37+
ChecksumCRC32: 'crc32',
38+
ChecksumCRC32C: 'crc32c',
39+
ChecksumCRC64NVME: 'crc64nvme',
40+
ChecksumSHA1: 'sha1',
41+
ChecksumSHA256: 'sha256',
42+
};
3643

3744
class AwsClient {
3845
constructor(config) {
@@ -435,13 +442,22 @@ class AwsClient {
435442
// We manually add quotes to ETag later, so remove quotes here
436443
const noQuotesETag =
437444
item.ETag.substring(1, item.ETag.length - 1);
445+
const value = {
446+
Size: item.Size,
447+
ETag: noQuotesETag,
448+
LastModified: item.LastModified,
449+
};
450+
Object.entries(awsPartChecksumFields).some(([field, algorithm]) => {
451+
if (item[field] !== undefined) {
452+
value.ChecksumAlgorithm = algorithm;
453+
value.ChecksumValue = item[field];
454+
return true;
455+
}
456+
return false;
457+
});
438458
return {
439459
partNumber: item.PartNumber,
440-
value: {
441-
Size: item.Size,
442-
ETag: noQuotesETag,
443-
LastModified: item.LastModified,
444-
},
460+
value,
445461
};
446462
});
447463
return callback(null, storedParts);

tests/unit/storage/data/external/ExternalClients.spec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ const backendClients = [
4949
},
5050
},
5151
];
52+
const awsPartChecksumFields = [
53+
['ChecksumCRC32', 'crc32', 'crc32-value'],
54+
['ChecksumCRC32C', 'crc32c', 'crc32c-value'],
55+
['ChecksumCRC64NVME', 'crc64nvme', 'crc64-value'],
56+
['ChecksumSHA1', 'sha1', 'sha1-value'],
57+
['ChecksumSHA256', 'sha256', 'sha256-value'],
58+
];
5259
const log = new DummyRequestLogger();
5360
let sandbox;
5461

@@ -285,6 +292,64 @@ describe('external backend clients', () => {
285292
assert(firstPart.value);
286293
assert.strictEqual(firstPart.value.ETag.includes('"'), false);
287294
});
295+
296+
awsPartChecksumFields.forEach(([checksumField, checksumAlgorithm, checksumValue]) => {
297+
it(`${backend.name} listParts() should normalize ${checksumField}`, async () => {
298+
const key = 'externalBackendTestKey';
299+
const bucketName = 'externalBackendTestBucket';
300+
const lastModified = new Date();
301+
sandbox.stub(testClient._client, 'send').resolves({
302+
IsTruncated: true,
303+
Parts: [
304+
{
305+
PartNumber: 1,
306+
ETag: '"part-etag-1"',
307+
Size: 1024,
308+
LastModified: lastModified,
309+
[checksumField]: checksumValue,
310+
},
311+
],
312+
});
313+
314+
const storedParts = await listPartsAsync(key, 'uploadId-123', bucketName, 0, 1000, log);
315+
316+
assert.strictEqual(storedParts.IsTruncated, true);
317+
assert.strictEqual(storedParts.Contents.length, 1);
318+
assert.deepStrictEqual(storedParts.Contents[0], {
319+
partNumber: 1,
320+
value: {
321+
Size: 1024,
322+
ETag: 'part-etag-1',
323+
LastModified: lastModified,
324+
ChecksumAlgorithm: checksumAlgorithm,
325+
ChecksumValue: checksumValue,
326+
},
327+
});
328+
});
329+
});
330+
331+
it(`${backend.name} listParts() should omit absent checksum fields`, async () => {
332+
const key = 'externalBackendTestKey';
333+
const bucketName = 'externalBackendTestBucket';
334+
sandbox.stub(testClient._client, 'send').resolves({
335+
IsTruncated: false,
336+
Parts: [
337+
{
338+
PartNumber: 2,
339+
ETag: '"part-etag-2"',
340+
Size: 2048,
341+
LastModified: new Date(),
342+
},
343+
],
344+
});
345+
346+
const storedParts = await listPartsAsync(key, 'uploadId-123', bucketName, 0, 1000, log);
347+
const { value } = storedParts.Contents[0];
348+
349+
assert.strictEqual(value.ETag, 'part-etag-2');
350+
assert.strictEqual(value.ChecksumAlgorithm, undefined);
351+
assert.strictEqual(value.ChecksumValue, undefined);
352+
});
288353
}
289354

290355
it(`${backend.name} createMPU() should trim metadata and forward tagging`, async () => {

0 commit comments

Comments
 (0)