Skip to content

Commit c30f901

Browse files
alexanderchan-scalityrahulreddy
authored andcommitted
add supportsVersioning unit tests
1 parent 94c21c9 commit c30f901

File tree

6 files changed

+409
-4
lines changed

6 files changed

+409
-4
lines changed

tests/locationConfig/locationConfigLegacy.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,27 @@
126126
"bucketMatch": true,
127127
"credentialsProfile": "google"
128128
}
129+
},
130+
"withversioning": {
131+
"type": "aws_s3",
132+
"legacyAwsBehavior": true,
133+
"details": {
134+
"awsEndpoint": "s3.amazonaws.com",
135+
"bucketName": "multitester555",
136+
"bucketMatch": true,
137+
"credentialsProfile": "default",
138+
"supportsVersioning": true
139+
}
140+
},
141+
"withoutversioning": {
142+
"type": "aws_s3",
143+
"legacyAwsBehavior": true,
144+
"details": {
145+
"awsEndpoint": "s3.amazonaws.com",
146+
"bucketName": "multitester555",
147+
"bucketMatch": true,
148+
"credentialsProfile": "default",
149+
"supportsVersioning": false
150+
}
129151
}
130152
}

tests/locationConfig/locationConfigTests.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,27 @@
163163
"bucketMatch": false,
164164
"credentialsProfile": "google"
165165
}
166+
},
167+
"withversioning": {
168+
"type": "aws_s3",
169+
"legacyAwsBehavior": true,
170+
"details": {
171+
"awsEndpoint": "s3.amazonaws.com",
172+
"bucketName": "multitester555",
173+
"bucketMatch": true,
174+
"credentialsProfile": "default",
175+
"supportsVersioning": true
176+
}
177+
},
178+
"withoutversioning": {
179+
"type": "aws_s3",
180+
"legacyAwsBehavior": true,
181+
"details": {
182+
"awsEndpoint": "s3.amazonaws.com",
183+
"bucketName": "multitester555",
184+
"bucketMatch": true,
185+
"credentialsProfile": "default",
186+
"supportsVersioning": false
187+
}
166188
}
167189
}

tests/unit/DummyService.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
const uuid = require('uuid/v4');
22

33
class DummyService {
4+
constructor(config = {}) {
5+
this.versioning = config.versioning;
6+
}
7+
headBucket(params, callback) {
8+
return callback();
9+
}
10+
getBucketVersioning(params, callback) {
11+
if (this.versioning) {
12+
return callback(null, { Status: 'Enabled' });
13+
}
14+
return callback(null, {});
15+
}
416
headObject(params, callback) {
517
const retObj = {
618
ContentLength: `${1024 * 1024 * 1024}`,
@@ -11,10 +23,37 @@ class DummyService {
1123
const retObj = {
1224
Bucket: params.Bucket,
1325
Key: params.Key,
14-
VersionId: uuid().replace(/-/g, ''),
1526
ETag: `"${uuid().replace(/-/g, '')}"`,
1627
ContentLength: `${1024 * 1024 * 1024}`,
1728
};
29+
if (this.versioning) {
30+
retObj.VersionId = uuid().replace(/-/g, '');
31+
}
32+
return callback(null, retObj);
33+
}
34+
upload(params, callback) {
35+
this.putObject(params, callback);
36+
}
37+
putObject(params, callback) {
38+
const retObj = {
39+
ETag: `"${uuid().replace(/-/g, '')}"`,
40+
};
41+
if (this.versioning) {
42+
retObj.VersionId = uuid().replace(/-/g, '');
43+
}
44+
return callback(null, retObj);
45+
}
46+
copyObject(params, callback) {
47+
const retObj = {
48+
CopyObjectResult: {
49+
ETag: `"${uuid().replace(/-/g, '')}"`,
50+
LastModified: new Date().toISOString(),
51+
},
52+
VersionId: null,
53+
};
54+
if (this.versioning) {
55+
retObj.VersionId = uuid().replace(/-/g, '');
56+
}
1857
return callback(null, retObj);
1958
}
2059
// To-Do: add tests for other methods
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
const assert = require('assert');
2+
3+
const { errors } = require('arsenal');
4+
const { bucketPut } = require('../../../lib/api/bucketPut');
5+
const bucketPutVersioning = require('../../../lib/api/bucketPutVersioning');
6+
7+
const { cleanup,
8+
DummyRequestLogger,
9+
makeAuthInfo } = require('../helpers');
10+
const metadata = require('../../../lib/metadata/wrapper');
11+
12+
const xmlEnableVersioning =
13+
'<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">' +
14+
'<Status>Enabled</Status>' +
15+
'</VersioningConfiguration>';
16+
17+
const xmlSuspendVersioning =
18+
'<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">' +
19+
'<Status>Suspended</Status>' +
20+
'</VersioningConfiguration>';
21+
22+
const locConstraintVersioned =
23+
'<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">' +
24+
'<LocationConstraint>withversioning</LocationConstraint>' +
25+
'</CreateBucketConfiguration>';
26+
27+
const locConstraintNonVersioned =
28+
'<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">' +
29+
'<LocationConstraint>withoutversioning</LocationConstraint>' +
30+
'</CreateBucketConfiguration>';
31+
32+
const externalVersioningErrorMessage = 'We do not currently support putting ' +
33+
'a versioned object to a location-constraint of type Azure or GCP.';
34+
35+
const log = new DummyRequestLogger();
36+
const bucketName = 'bucketname';
37+
const authInfo = makeAuthInfo('accessKey1');
38+
39+
function _getPutBucketRequest(xml) {
40+
const request = {
41+
bucketName,
42+
headers: { host: `${bucketName}.s3.amazonaws.com` },
43+
url: '/',
44+
};
45+
request.post = xml;
46+
return request;
47+
}
48+
49+
function _putVersioningRequest(xml) {
50+
const request = {
51+
bucketName,
52+
headers: { host: `${bucketName}.s3.amazonaws.com` },
53+
url: '/?versioning',
54+
query: { versioning: '' },
55+
};
56+
request.post = xml;
57+
return request;
58+
}
59+
60+
describe('bucketPutVersioning API', () => {
61+
before(() => cleanup());
62+
afterEach(() => cleanup());
63+
64+
describe('with version enabled location constraint', () => {
65+
beforeEach(done => {
66+
const request = _getPutBucketRequest(locConstraintVersioned);
67+
bucketPut(authInfo, request, log, done);
68+
});
69+
70+
const tests = [
71+
{
72+
msg: 'should successfully enable versioning on location ' +
73+
'constraint with supportsVersioning set to true',
74+
input: xmlEnableVersioning,
75+
output: { Status: 'Enabled' },
76+
},
77+
{
78+
msg: 'should successfully suspend versioning on location ' +
79+
'constraint with supportsVersioning set to true',
80+
input: xmlSuspendVersioning,
81+
output: { Status: 'Suspended' },
82+
},
83+
];
84+
tests.forEach(test => it(test.msg, done => {
85+
const request = _putVersioningRequest(test.input);
86+
bucketPutVersioning(authInfo, request, log, err => {
87+
assert.ifError(err,
88+
`Expected success, but got err: ${err}`);
89+
metadata.getBucket(bucketName, log, (err, bucket) => {
90+
assert.ifError(err,
91+
`Expected success, but got err: ${err}`);
92+
assert.deepStrictEqual(bucket._versioningConfiguration,
93+
test.output);
94+
done();
95+
});
96+
});
97+
}));
98+
});
99+
100+
describe('with version disabled location constraint', () => {
101+
beforeEach(done => {
102+
const request = _getPutBucketRequest(locConstraintNonVersioned);
103+
bucketPut(authInfo, request, log, done);
104+
});
105+
106+
const tests = [
107+
{
108+
msg: 'should return error if enabling versioning on location ' +
109+
'constraint with supportsVersioning set to false',
110+
input: xmlEnableVersioning,
111+
output: { error: errors.NotImplemented.customizeDescription(
112+
externalVersioningErrorMessage) },
113+
},
114+
{
115+
msg: 'should return error if suspending versioning on ' +
116+
' location constraint with supportsVersioning set to false',
117+
input: xmlSuspendVersioning,
118+
output: { error: errors.NotImplemented.customizeDescription(
119+
externalVersioningErrorMessage) },
120+
},
121+
];
122+
tests.forEach(test => it(test.msg, done => {
123+
const putBucketVersioningRequest =
124+
_putVersioningRequest(test.input);
125+
bucketPutVersioning(authInfo, putBucketVersioningRequest, log,
126+
err => {
127+
assert.deepStrictEqual(err, test.output.error);
128+
done();
129+
});
130+
}));
131+
});
132+
});

tests/unit/multipleBackend/ExternalBackendClient.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
23
const AwsClient = require('../../../lib/data/external/AwsClient');
34
const GcpClient = require('../../../lib/data/external/GcpClient');
45
const DummyService = require('../DummyService');
@@ -28,13 +29,14 @@ const backendClients = [
2829
},
2930
},
3031
];
32+
const log = new DummyRequestLogger();
3133

3234
backendClients.forEach(backend => {
3335
let testClient;
3436

3537
before(() => {
3638
testClient = new backend.Class(backend.config);
37-
testClient._client = new DummyService(backend.config);
39+
testClient._client = new DummyService({ versioning: true });
3840
});
3941

4042
describe(`${backend.name} completeMPU:`, () => {
@@ -58,8 +60,6 @@ backendClients.forEach(backend => {
5860
const key = 'externalBackendTestKey';
5961
const bucketName = 'externalBackendTestBucket';
6062
const uploadId = 'externalBackendTestUploadId';
61-
const log = new DummyRequestLogger();
62-
6363
testClient.completeMPU(jsonList, null, key, uploadId, bucketName,
6464
log, (err, res) => {
6565
assert.strictEqual(typeof res.key, 'string');

0 commit comments

Comments
 (0)