Compare commits

...

3 Commits

Author SHA1 Message Date
philipyoo b29c0617b4 log 2018-07-25 12:29:35 -07:00
philipyoo 7d12e4431b bump vers 2018-07-25 11:25:35 -07:00
philipyoo 6d565dc7ec test 2018-07-25 11:25:29 -07:00
4 changed files with 33 additions and 3 deletions

View File

@ -48,12 +48,16 @@ function checkBucketAndKey(bucketName, objectKey, method, reqQuery,
return errors.InvalidBucketName; return errors.InvalidBucketName;
} }
if (objectKey !== undefined) { if (objectKey !== undefined) {
console.log('\n\nIn checkBucketAndKey:', objectKey);
const result = routesUtils.isValidObjectKey(objectKey, const result = routesUtils.isValidObjectKey(objectKey,
blacklistedPrefixes.object); blacklistedPrefixes.object);
if (!result.isValid) { if (!result.isValid) {
log.debug('invalid object key', { objectKey }); log.debug('invalid object key', { objectKey });
return errors.InvalidArgument.customizeDescription('Object key ' + if (result.invalidPrefix) {
`must not start with "${result.invalidPrefix}".`); return errors.InvalidArgument.customizeDescription('Object ' +
`key must not start with "${result.invalidPrefix}".`);
}
return errors.KeyTooLong;
} }
} }
if ((reqQuery.partNumber || reqQuery.uploadId) if ((reqQuery.partNumber || reqQuery.uploadId)

View File

@ -874,6 +874,9 @@ const routesUtils = {
if (invalidPrefix) { if (invalidPrefix) {
return { isValid: false, invalidPrefix }; return { isValid: false, invalidPrefix };
} }
if (objectKey.length > 1024) {
return { isValid: false };
}
return { isValid: true }; return { isValid: true };
}, },

View File

@ -3,7 +3,7 @@
"engines": { "engines": {
"node": ">=6.9.5" "node": ">=6.9.5"
}, },
"version": "8.0.0", "version": "8.2.0",
"description": "Common utilities for the S3 project components", "description": "Common utilities for the S3 project components",
"main": "index.js", "main": "index.js",
"repository": { "repository": {

View File

@ -0,0 +1,23 @@
const assert = require('assert');
const routesUtils = require('../../../../lib/s3routes/routesUtils.js');
const bannedStr = 'banned';
const prefixBlacklist = [];
describe('routesUtils.isValidObjectKey', () => {
it('should return isValid false if object key name starts with a ' +
'blacklisted prefix', () => {
const result = routesUtils.isValidObjectKey('bannedkey', [bannedStr]);
// return { isValid: false, invalidPrefix };
assert.strictEqual(result.isValid, false);
assert.strictEqual(result.invalidPrefix, bannedStr);
});
it('should return isValid false if object key name exceeds length of 1024',
() => {
const keyLength1025 = 'a'.repeat(1025);
const result = routesUtils.isValidObjectKey(keyLength1025,
prefixBlacklist);
assert.strictEqual(result.isValid, false);
});
});