Skip to content

Commit a8406fa

Browse files
committed
post reviews fixups
1 parent 0bd90df commit a8406fa

File tree

4 files changed

+14
-43
lines changed

4 files changed

+14
-43
lines changed

tests/functional/sse-kms-migration/arnPrefix.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,12 @@ describe('KMS error', () => {
602602
},
603603
{
604604
action: 'getObject', kmsAction: 'Decrypt',
605-
fct: async () => helpers.s3.getObject({ Bucket, Key }) ,
605+
fct: async () => helpers.s3.getObject({ Bucket, Key }),
606606
},
607607
{
608608
action: 'copyObject', detail: ' when getting from source', kmsAction: 'Decrypt',
609609
fct: async () =>
610-
helpers.s3.copyObject({ Bucket, Key: 'copy', CopySource: `${Bucket}/${Key}` }) ,
610+
helpers.s3.copyObject({ Bucket, Key: 'copy', CopySource: `${Bucket}/${Key}` }),
611611
},
612612
{
613613
action: 'copyObject', detail: ' when putting to destination', kmsAction: 'Encrypt',
@@ -617,7 +617,7 @@ describe('KMS error', () => {
617617
CopySource: `${Bucket}/plaintext`,
618618
ServerSideEncryption: 'aws:kms',
619619
SSEKMSKeyId: masterKeyArn,
620-
}) ,
620+
}),
621621
},
622622
{
623623
action: 'createMPU', kmsAction: 'Encrypt',
@@ -632,7 +632,7 @@ describe('KMS error', () => {
632632
Key: 'mpuPlaintext',
633633
PartNumber: 1,
634634
CopySource: `${Bucket}/${Key}`,
635-
}) ,
635+
}),
636636
},
637637
{
638638
action: 'mpu uploadPart', detail: ' when putting to destination', kmsAction: 'Encrypt',

tests/functional/sse-kms-migration/beforeMigration.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ describe('SSE KMS before migration', () => {
326326
it(`should PutObject versioned with SSE ${obj.name}`, async () => {
327327
// ensure versioned bucket is empty
328328
await helpers.bucketUtil.empty(bkt.vname);
329-
let { Versions } = await helpers.s3.listObjectVersions({ Bucket: bkt.vname }) || [];
330-
// regularly count versioned objects
329+
let { Versions } = await helpers.s3.listObjectVersions({ Bucket: bkt.vname }) || { Versions: [] };
331330
assert.strictEqual(Versions.length, 0);
332331

333332
const bodyBase = `BODY(${obj.name})-base`;

tests/functional/sse-kms-migration/helpers.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const { S3Client,
2020
HeadBucketCommand,
2121
} = require('@aws-sdk/client-s3');
2222
const { NodeHttpHandler } = require('@smithy/node-http-handler');
23-
const { StandardRetryStrategy } = require('@aws-sdk/middleware-retry');
2423
const { Agent: HttpAgent } = require('http');
2524
const { Agent: HttpsAgent } = require('https');
2625
const kms = require('../../../lib/kms/wrapper');
@@ -40,7 +39,6 @@ function getKey(key) {
4039
// For Integration use default profile, in cloudserver use vault profile
4140
const credsProfile = process.env.S3_END_TO_END === 'true' ? 'default' : 'vault';
4241

43-
// Create custom agents with specific pooling settings
4442
const httpAgent = new HttpAgent({
4543
keepAlive: true,
4644
keepAliveMsecs: 30000,
@@ -65,36 +63,21 @@ const s3config = {
6563
httpAgent,
6664
httpsAgent,
6765
}),
68-
maxAttempts: 8,
69-
retryStrategy: new StandardRetryStrategy({
70-
maxAttempts: 8,
71-
retryDecider: error =>
72-
(
73-
error.code === 'ECONNREFUSED' ||
74-
error.code === 'ECONNRESET' ||
75-
error.name === 'TimeoutError' ||
76-
error.message?.includes('socket hang up') ||
77-
error.code === 'ThrottlingException' ||
78-
error.code === 'RequestTimeout'
79-
)
80-
,
81-
delayDecider: attempts => Math.min(1000 * Math.pow(2, attempts), 30000), // Exponential backoff
82-
}),
66+
maxAttempts: 3,
8367
};
8468

8569
const s3Client = new S3Client(s3config);
8670

87-
// Remove logger middleware if present
8871
if (s3Client.middlewareStack.identify().includes('loggerMiddleware')) {
8972
s3Client.middlewareStack.remove('loggerMiddleware');
9073
}
9174

9275
const bucketUtil = new BucketUtility(credsProfile);
9376

94-
// Wrapper for SDK v3 commands to return promises directly
9577
const wrap = exec => exec();
9678
const s3 = {
9779
createBucket: params => wrap(() => s3Client.send(new CreateBucketCommand(params))),
80+
deleteBucket: params => wrap(() => s3Client.send(new DeleteBucketCommand(params))),
9881
putBucketEncryption: params => wrap(() => s3Client.send(new PutBucketEncryptionCommand(params))),
9982
getBucketEncryption: params => wrap(() => s3Client.send(new GetBucketEncryptionCommand(params))),
10083
putObject: params => wrap(() => s3Client.send(new PutObjectCommand(params))),
@@ -176,7 +159,7 @@ const MD = {
176159

177160
async function getBucketSSE(Bucket) {
178161
try {
179-
const sse = await s3Client.send(new GetBucketEncryptionCommand({ Bucket }));
162+
const sse = await s3.getBucketEncryption({ Bucket });
180163
return sse.ServerSideEncryptionConfiguration.Rules[0].ApplyServerSideEncryptionByDefault;
181164
} catch (error) {
182165
if (error.name === 'ServerSideEncryptionConfigurationNotFoundError') {
@@ -187,10 +170,10 @@ async function getBucketSSE(Bucket) {
187170
}
188171

189172
async function putEncryptedObject(Bucket, Key, sseConfig, kmsKeyId, Body) {
190-
return s3Client.send(new PutObjectCommand({
173+
return s3.putObject({
191174
...putObjParams(Bucket, Key, sseConfig, kmsKeyId),
192175
Body,
193-
}));
176+
});
194177
}
195178

196179
async function getObjectMDSSE(Bucket, Key) {
@@ -221,7 +204,7 @@ const destroyKmsKey = promisify(kms.destroyBucketKey);
221204

222205
async function cleanup(Bucket) {
223206
await bucketUtil.empty(Bucket);
224-
await s3Client.send(new DeleteBucketCommand({ Bucket }));
207+
await s3.deleteBucket({ Bucket });
225208
}
226209

227210
module.exports = {

tests/functional/sse-kms-migration/scenarios.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,6 @@ async function copyObjectAndSSE(
235235
// check MPU headers against the MPU overview MD
236236
// because there is no migration for ongoing MPU
237237
function assertMPUSSEHeaders(actual, expected, algo) {
238-
// eslint-disable-next-line no-console
239-
console.log('actual', actual);
240-
// eslint-disable-next-line no-console
241-
console.log('expected', expected);
242238
if (algo) {
243239
assert.strictEqual(actual.ServerSideEncryption, algo);
244240
}
@@ -284,16 +280,9 @@ async function mpuUploadPartCopy(
284280
// before has no headers to assert
285281
async function mpuComplete({ UploadId, Bucket, Key }, { existingParts, newParts }, mpuOverviewMDSSE, algo, testCase) {
286282
const extractETag = part => {
287-
// For uploadPartCopy responses, ETag is in CopyPartResult
288-
if (part.CopyPartResult && part.CopyPartResult.ETag) {
289-
return part.CopyPartResult.ETag;
290-
}
291-
// For regular uploadPart responses, ETag is at the top level
292-
if (part.ETag) {
293-
return part.ETag;
294-
}
295-
// If neither exists, throw an error for debugging
296-
throw new Error(`Could not find ETag in part: ${JSON.stringify(part)}`);
283+
const eTag = part.CopyPartResult?.ETag || part.ETag;
284+
assert(eTag, `Could not find ETag in part: ${JSON.stringify(part)}`);
285+
return eTag;
297286
};
298287

299288
// Build the parts array with proper ETag extraction

0 commit comments

Comments
 (0)