Skip to content

Commit 2555b8e

Browse files
committed
rest of object related tests migration
Issue: CLDSRV-724
1 parent 1bb2228 commit 2555b8e

File tree

9 files changed

+424
-336
lines changed

9 files changed

+424
-336
lines changed

tests/functional/aws-node-sdk/test/object/100-continue.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const assert = require('assert');
22
const http = require('http');
33
const https = require('https');
44
const url = require('url');
5+
const { CreateBucketCommand, PutObjectCommand } = require('@aws-sdk/client-s3');
6+
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner');
57

68
const withV4 = require('../support/withV4');
79
const BucketUtility = require('../../lib/utility/bucket-util');
@@ -121,17 +123,19 @@ describeSkipIfE2E('PUT public object with 100-continue header', () => {
121123
let continueRequest;
122124
const invalidSignedURL = `/${bucket}/${key}`;
123125

124-
beforeEach(() => {
126+
beforeEach(async () => {
125127
bucketUtil = new BucketUtility('default', sigCfg);
126128
s3 = bucketUtil.s3;
127129
const params = {
128130
Bucket: bucket,
129131
Key: key,
132+
'Content-Length': 0,
130133
};
131-
const signedUrl = s3.getSignedUrl('putObject', params);
134+
const command = new PutObjectCommand(params);
135+
const signedUrl = await getSignedUrl(s3, command);
132136
const { path } = url.parse(signedUrl);
133137
continueRequest = new ContinueRequestHandler(path);
134-
return s3.createBucket({ Bucket: bucket }).promise();
138+
await s3.send(new CreateBucketCommand({ Bucket: bucket }));
135139
});
136140

137141
afterEach(() =>

tests/functional/aws-node-sdk/test/object/encryptionHeaders.js

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
const assert = require('assert');
22
const async = require('async');
33
const uuid = require('uuid');
4+
const {
5+
CreateBucketCommand,
6+
HeadObjectCommand,
7+
PutObjectCommand,
8+
PutBucketEncryptionCommand,
9+
CopyObjectCommand,
10+
CreateMultipartUploadCommand,
11+
UploadPartCommand,
12+
} = require('@aws-sdk/client-s3');
413
const BucketInfo = require('arsenal').models.BucketInfo;
514
const withV4 = require('../support/withV4');
615
const BucketUtility = require('../../lib/utility/bucket-util');
@@ -31,26 +40,37 @@ const testCases = [
3140
function s3NoOp(_, cb) { cb(); }
3241

3342
function getSSEConfig(s3, Bucket, Key, cb) {
34-
return s3.headObject({ Bucket, Key }, (err, resp) => {
35-
if (err) {
36-
return cb(err);
37-
}
38-
return cb(null,
39-
JSON.parse(JSON.stringify({ algo: resp.ServerSideEncryption, masterKeyId: resp.SSEKMSKeyId })));
40-
});
43+
const command = new HeadObjectCommand({ Bucket, Key });
44+
s3.send(command)
45+
.then(resp => {
46+
const sseConfig = JSON.parse(JSON.stringify({
47+
algo: resp.ServerSideEncryption,
48+
masterKeyId: resp.SSEKMSKeyId
49+
}));
50+
cb(null, sseConfig);
51+
})
52+
.catch(cb);
4153
}
4254

4355
function putEncryptedObject(s3, Bucket, Key, sseConfig, kmsKeyId, cb) {
4456
const params = {
4557
Bucket,
4658
Key,
47-
ServerSideEncryption: sseConfig.algo,
4859
Body: 'somedata',
4960
};
61+
62+
if (sseConfig.algo) {
63+
params.ServerSideEncryption = sseConfig.algo;
64+
}
65+
5066
if (sseConfig.masterKeyId) {
5167
params.SSEKMSKeyId = kmsKeyId;
5268
}
53-
return s3.putObject(params, cb);
69+
70+
const command = new PutObjectCommand(params);
71+
s3.send(command)
72+
.then(response => cb(null, response))
73+
.catch(cb);
5474
}
5575

5676
function createExpected(sseConfig, kmsKeyId) {
@@ -84,6 +104,34 @@ function hydrateSSEConfig({ algo: SSEAlgorithm, masterKeyId: KMSMasterKeyID }) {
84104
);
85105
}
86106

107+
function putBucketEncryption(s3, params, cb) {
108+
const command = new PutBucketEncryptionCommand(params);
109+
s3.send(command)
110+
.then(response => cb(null, response))
111+
.catch(cb);
112+
}
113+
114+
function copyObject(s3, params, cb) {
115+
const command = new CopyObjectCommand(params);
116+
s3.send(command)
117+
.then(response => cb(null, response))
118+
.catch(cb);
119+
}
120+
121+
function createMultipartUpload(s3, params, cb) {
122+
const command = new CreateMultipartUploadCommand(params);
123+
s3.send(command)
124+
.then(response => cb(null, response))
125+
.catch(cb);
126+
}
127+
128+
function uploadPart(s3, params, cb) {
129+
const command = new UploadPartCommand(params);
130+
s3.send(command)
131+
.then(response => cb(null, response))
132+
.catch(cb);
133+
}
134+
87135
describe('per object encryption headers', () => {
88136
withV4(sigCfg => {
89137
let bucket;
@@ -106,19 +154,15 @@ describe('per object encryption headers', () => {
106154
);
107155
});
108156

109-
beforeEach(() => {
157+
beforeEach(async () => {
110158
bucket = `enc-bucket-${uuid.v4()}`;
111159
bucket2 = `enc-bucket-2-${uuid.v4()}`;
112160
object = `enc-object-${uuid.v4()}`;
113161
object2 = `enc-object-2-${uuid.v4()}`;
114162
bucketUtil = new BucketUtility('default', sigCfg);
115163
s3 = bucketUtil.s3;
116-
return s3.createBucket({ Bucket: bucket }).promise()
117-
.then(() => s3.createBucket({ Bucket: bucket2 }).promise())
118-
.catch(err => {
119-
process.stdout.write(`Error creating bucket: ${err}\n`);
120-
throw err;
121-
});
164+
await s3.send(new CreateBucketCommand({ Bucket: bucket }));
165+
await s3.send(new CreateBucketCommand({ Bucket: bucket2 }));
122166
});
123167

124168
afterEach(() => {
@@ -190,8 +234,9 @@ describe('per object encryption headers', () => {
190234
Bucket: bucket,
191235
ServerSideEncryptionConfiguration: hydrateSSEConfig(_existing),
192236
};
193-
// no op putBucketNotification for the unencrypted case
194-
const s3Op = existing.algo ? (...args) => s3.putBucketEncryption(...args) : s3NoOp;
237+
// no op putBucketEncryption for the unencrypted case
238+
const s3Op = existing.algo ?
239+
(params, cb) => putBucketEncryption(s3, params, cb) : s3NoOp;
195240
s3Op(params, error => {
196241
assert.ifError(error);
197242
return putEncryptedObject(s3, bucket, object, target, kmsKeyId, error => {
@@ -236,8 +281,9 @@ describe('per object encryption headers', () => {
236281
Bucket: bucket2,
237282
ServerSideEncryptionConfiguration: hydrateSSEConfig(_existing),
238283
};
239-
// no op putBucketNotification for the unencrypted case
240-
const s3Op = existing.algo ? (...args) => s3.putBucketEncryption(...args) : s3NoOp;
284+
// no op putBucketEncryption for the unencrypted case
285+
const s3Op = existing.algo ?
286+
(params, cb) => putBucketEncryption(s3, params, cb) : s3NoOp;
241287
s3Op(params, error => {
242288
assert.ifError(error);
243289
return putEncryptedObject(s3, bucket, object, target, kmsKeyId, error => {
@@ -253,7 +299,7 @@ describe('per object encryption headers', () => {
253299
if (target.masterKeyId) {
254300
copyParams.SSEKMSKeyId = kmsKeyId;
255301
}
256-
return s3.copyObject(copyParams, error => {
302+
return copyObject(s3, copyParams, error => {
257303
assert.ifError(error);
258304
return getSSEConfig(
259305
s3,
@@ -293,7 +339,7 @@ describe('per object encryption headers', () => {
293339
if (target.masterKeyId) {
294340
params.SSEKMSKeyId = kmsKeyId;
295341
}
296-
s3.createMultipartUpload(params, (error, resp) => {
342+
createMultipartUpload(s3, params, (error, resp) => {
297343
assert.ifError(error);
298344
const { UploadId } = resp;
299345
const partParams = {
@@ -303,7 +349,7 @@ describe('per object encryption headers', () => {
303349
Key: object,
304350
PartNumber: 1,
305351
};
306-
s3.uploadPart(partParams, error => {
352+
uploadPart(s3, partParams, error => {
307353
assert.ifError(error);
308354
done();
309355
});
@@ -315,7 +361,7 @@ describe('per object encryption headers', () => {
315361
Bucket: bucket,
316362
Key: object,
317363
};
318-
s3.createMultipartUpload(sourceParams, (error, resp) => {
364+
createMultipartUpload(s3, sourceParams, (error, resp) => {
319365
assert.ifError(error);
320366
const { UploadId: sourceUploadId } = resp;
321367
const sourcePartParams = {
@@ -325,7 +371,7 @@ describe('per object encryption headers', () => {
325371
Key: object,
326372
PartNumber: 1,
327373
};
328-
s3.uploadPart(sourcePartParams, error => {
374+
uploadPart(s3, sourcePartParams, error => {
329375
assert.ifError(error);
330376
const targetParams = {
331377
Bucket: bucket,
@@ -337,7 +383,8 @@ describe('per object encryption headers', () => {
337383
if (target.masterKeyId) {
338384
targetParams.SSEKMSKeyId = kmsKeyId;
339385
}
340-
s3.createMultipartUpload(targetParams, (error, resp) => {
386+
createMultipartUpload(s3, targetParams, (error, resp) => {
387+
assert.ifError(error);
341388
const { UploadId: targetUploadId } = resp;
342389
const targetPartParams = {
343390
UploadId: targetUploadId,
@@ -346,7 +393,7 @@ describe('per object encryption headers', () => {
346393
Key: object2,
347394
PartNumber: 1,
348395
};
349-
s3.uploadPart(targetPartParams, error => {
396+
uploadPart(s3, targetPartParams, error => {
350397
assert.ifError(error);
351398
done();
352399
});

0 commit comments

Comments
 (0)