Skip to content

Commit 171a8ec

Browse files
committed
do not allow using crr location as a locationConstraint
Issue: CLDSRV-653
1 parent dee5d54 commit 171a8ec

9 files changed

+60
-6
lines changed

lib/Config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ function hdClientLocationConstraintAssert(configHd) {
305305

306306
function locationConstraintAssert(locationConstraints) {
307307
const supportedBackends = [
308-
'mem', 'file', 'scality', 'mongodb', 'tlp',
308+
'mem', 'file', 'scality', 'mongodb', 'tlp', 'crr'
309309
].concat(Object.keys(validExternalBackends));
310310
assert(typeof locationConstraints === 'object',
311311
'bad config: locationConstraints must be an object');

lib/api/bucketPut.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ function checkLocationConstraint(request, locationConstraint, log) {
5959
return { error: errorInstances.InvalidLocationConstraint.
6060
customizeDescription(errMsg) };
6161
}
62-
if (locationConstraints[locationConstraintChecked].isCold) {
62+
if (locationConstraints[locationConstraintChecked].isCold ||
63+
locationConstraints[locationConstraintChecked].type === 'crr') {
6364
return { error: errors.InvalidLocationConstraint };
6465
}
6566
if (locationConstraintAddon) {

locationConfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,11 @@
108108
"legacyAwsBehavior": false,
109109
"isCold": true,
110110
"details": {}
111+
},
112+
"location-crr-v1": {
113+
"type": "crr",
114+
"objectId": "location-crr-v1",
115+
"legacyAwsBehavior": false,
116+
"details": {}
111117
}
112118
}

tests/locationConfig/locationConfigCeph.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,11 @@
263263
"legacyAwsBehavior": false,
264264
"isCold": true,
265265
"details": {}
266+
},
267+
"location-crr-v1": {
268+
"type": "crr",
269+
"objectId": "location-crr-v1",
270+
"legacyAwsBehavior": false,
271+
"details": {}
266272
}
267273
}

tests/locationConfig/locationConfigLegacy.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,11 @@
185185
"legacyAwsBehavior": false,
186186
"isCold": true,
187187
"details": {}
188+
},
189+
"location-crr-v1": {
190+
"type": "crr",
191+
"objectId": "location-crr-v1",
192+
"legacyAwsBehavior": false,
193+
"details": {}
188194
}
189195
}

tests/locationConfig/locationConfigTests.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,11 @@
274274
"legacyAwsBehavior": false,
275275
"isCold": true,
276276
"details": {}
277+
},
278+
"location-crr-v1": {
279+
"type": "crr",
280+
"objectId": "location-crr-v1",
281+
"legacyAwsBehavior": false,
282+
"details": {}
277283
}
278284
}

tests/unit/api/bucketGetLocation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ describe('getBucketLocation API', () => {
4747
// see next test.
4848
return;
4949
}
50-
if (location === 'location-dmf-v1') {
51-
// if region location-dmf-v1 should return InvalidLocationConstraint error
50+
if (location === 'location-dmf-v1' || location === 'location-crr-v1') {
51+
// if region location-dmf-v1 or location-crr-v1 should return InvalidLocationConstraint error
5252
return;
5353
}
5454
const bucketPutRequest = getBucketRequestObject(location);

tests/unit/api/bucketPut.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ const testChecks = [
7878
isError: true,
7979
expectedError: 'InvalidLocationConstraint',
8080
},
81+
{
82+
data: 'multiple',
83+
locationSent: 'location-crr-v1',
84+
parsedHost: '127.3.2.1',
85+
locationReturn: 'location-crr-v1',
86+
isError: true,
87+
expectedError: 'InvalidLocationConstraint',
88+
},
8189
];
8290

8391
describe('checkLocationConstraint function', () => {
@@ -376,6 +384,27 @@ describe('bucketPut API', () => {
376384
});
377385
});
378386

387+
it('should deny put bucket if locationConstraint is the crr location', done => {
388+
const bucketName = 'bucket-name';
389+
const newRestEndpoint = 'location-crr-v1';
390+
const location = 'location-crr-v1';
391+
392+
const req = {
393+
...testRequest,
394+
parsedHost: newRestEndpoint,
395+
bucketName,
396+
};
397+
398+
const newRestEndpoints = Object.assign({}, config.restEndpoints);
399+
newRestEndpoints[newRestEndpoint] = location;
400+
config.setRestEndpoints(newRestEndpoints);
401+
402+
bucketPut(authInfo, req, log, err => {
403+
assert.strictEqual(err.is.InvalidLocationConstraint, true);
404+
done();
405+
});
406+
});
407+
379408
describe('Config::setLocationConstraints', () => {
380409
const bucketName = `test-bucket-${Date.now()}`;
381410
const newLC = {};

tests/unit/testConfigs/locConstraintAssert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ describe('locationConstraintAssert', () => {
5656
/bad config: locationConstraints[region].type is mandatory/ +
5757
/and must be a string/);
5858
});
59-
it('should throw error if type is not mem/file/scality/dmf', () => {
59+
it('should throw error if type is not mem/file/scality/dmf/crr', () => {
6060
const locationConstraint = new LocationConstraint(
6161
'notSupportedType', 'locId');
6262
assert.throws(() => {
6363
locationConstraintAssert({ 'scality-east': locationConstraint });
6464
},
6565
/bad config: locationConstraints[region].type must be/ +
66-
/one of mem,file,scality,tlp/);
66+
/one of mem,file,scality,tlp,crr/);
6767
});
6868
it('should throw error if legacyAwsBehavior is not a boolean', () => {
6969
const locationConstraint = new LocationConstraint(

0 commit comments

Comments
 (0)