-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathobjectCopyPart.js
More file actions
157 lines (146 loc) · 5.79 KB
/
objectCopyPart.js
File metadata and controls
157 lines (146 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const assert = require('assert');
const async = require('async');
const sinon = require('sinon');
const { parseString } = require('xml2js');
const { storage } = require('arsenal');
const { bucketPut } = require('../../../lib/api/bucketPut');
const objectPut = require('../../../lib/api/objectPut');
const objectPutCopyPart = require('../../../lib/api/objectPutCopyPart');
const initiateMultipartUpload
= require('../../../lib/api/initiateMultipartUpload');
const { metadata } = storage.metadata.inMemory.metadata;
const metadataswitch = require('../metadataswitch');
const DummyRequest = require('../DummyRequest');
const { cleanup, DummyRequestLogger, makeAuthInfo, versioningTestUtils }
= require('../helpers');
const log = new DummyRequestLogger();
const canonicalID = 'accessKey1';
const authInfo = makeAuthInfo(canonicalID);
const namespace = 'default';
const destBucketName = 'destbucketname';
const sourceBucketName = 'sourcebucketname';
const objectKey = 'objectName';
function _createBucketPutRequest(bucketName) {
return new DummyRequest({
bucketName,
namespace,
headers: { host: `${bucketName}.s3.amazonaws.com` },
url: '/',
});
}
function _createInitiateRequest(bucketName) {
const params = {
bucketName,
namespace,
objectKey,
headers: { host: `${bucketName}.s3.amazonaws.com` },
url: `/${objectKey}?uploads`,
};
return new DummyRequest(params);
}
function _createObjectCopyPartRequest(destBucketName, uploadId, headers) {
const params = {
bucketName: destBucketName,
namespace,
objectKey,
headers: headers || {},
url: `/${destBucketName}/${objectKey}?partNumber=1`,
query: {
partNumber: 1,
uploadId,
},
};
return new DummyRequest(params);
}
const putDestBucketRequest = _createBucketPutRequest(destBucketName);
const putSourceBucketRequest = _createBucketPutRequest(sourceBucketName);
const initiateRequest = _createInitiateRequest(destBucketName);
describe('objectCopyPart', () => {
let uploadId;
const objData = Buffer.from('foo', 'utf8');
const testPutObjectRequest =
versioningTestUtils.createPutObjectRequest(sourceBucketName, objectKey,
objData);
before(done => {
cleanup();
sinon.spy(metadataswitch, 'putObjectMD');
async.waterfall([
callback => bucketPut(authInfo, putDestBucketRequest, log,
err => callback(err)),
callback => bucketPut(authInfo, putSourceBucketRequest, log,
err => callback(err)),
callback => objectPut(authInfo, testPutObjectRequest,
undefined, log, err => callback(err)),
callback => initiateMultipartUpload(authInfo, initiateRequest,
log, (err, res) => callback(err, res)),
], (err, res) => {
if (err) {
return done(err);
}
return parseString(res, (err, json) => {
uploadId = json.InitiateMultipartUploadResult.UploadId[0];
return done();
});
});
});
after(() => {
metadataswitch.putObjectMD.restore();
cleanup();
});
it('should copy part even if legacy metadata without dataStoreName',
done => {
// force metadata for dataStoreName to be undefined
metadata.keyMaps.get(sourceBucketName).get(objectKey).dataStoreName = undefined;
const testObjectCopyRequest = _createObjectCopyPartRequest(destBucketName, uploadId);
objectPutCopyPart(authInfo, testObjectCopyRequest, sourceBucketName, objectKey, undefined, log, err => {
assert.ifError(err);
done();
});
});
it('should return InvalidArgument error given invalid range', done => {
const headers = { 'x-amz-copy-source-range': 'bad-range-parameter' };
const req =
_createObjectCopyPartRequest(destBucketName, uploadId, headers);
objectPutCopyPart(
authInfo, req, sourceBucketName, objectKey, undefined, log, err => {
assert(err.is.InvalidArgument);
assert.strictEqual(err.description,
'The x-amz-copy-source-range value must be of the form ' +
'bytes=first-last where first and last are the ' +
'zero-based offsets of the first and last bytes to copy');
done();
});
});
it('should pass overheadField', done => {
const testObjectCopyRequest = _createObjectCopyPartRequest(destBucketName, uploadId);
objectPutCopyPart(authInfo, testObjectCopyRequest, sourceBucketName, objectKey, undefined, log, err => {
assert.ifError(err);
sinon.assert.calledWith(
metadataswitch.putObjectMD,
sinon.match.string, // MPU shadow bucket
objectKey,
sinon.match.any,
sinon.match({ overheadField: sinon.match.array }),
sinon.match.any,
sinon.match.any
);
done();
});
});
it('should set owner-id to the canonicalId of the dest bucket owner', done => {
const testObjectCopyRequest = _createObjectCopyPartRequest(destBucketName, uploadId);
objectPutCopyPart(authInfo, testObjectCopyRequest, sourceBucketName, objectKey, undefined, log, err => {
assert.ifError(err);
sinon.assert.calledWith(
metadataswitch.putObjectMD.lastCall,
sinon.match.string, // MPU shadow bucket
`${uploadId}..|..00001`,
sinon.match({ 'owner-id': authInfo.canonicalID }),
sinon.match.any,
sinon.match.any,
sinon.match.any
);
done();
});
});
});