Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ const constants = {
'STREAMING-UNSIGNED-PAYLOAD-TRAILER',
'STREAMING-AWS4-HMAC-SHA256-PAYLOAD',
]),
// Content-Encoding element added by clients for V4 streaming uploads,
// which is removed before storing the object, as AWS does. See:
// http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html
awsChunkedContentEncoding: 'aws-chunked',
ipv4Regex: /^(\d{1,3}\.){3}\d{1,3}(\/(3[0-2]|[12]?\d))?$/,
ipv6Regex: /^([\da-f]{1,4}:){7}[\da-f]{1,4}$/i,
// The AWS assumed Role resource type
Expand Down
4 changes: 2 additions & 2 deletions lib/api/apiUtils/object/createAndStoreObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const services = require('../../../services');
const { dataStore } = require('./storeObject');
const locationConstraintCheck = require('./locationConstraintCheck');
const { versioningPreprocessing, overwritingVersioning, decodeVID } = require('./versioning');
const removeAWSChunked = require('./removeAWSChunked');
const removeFromCommaSeparatedList = require('../../../utilities/removeFromCommaSeparatedList');
const getReplicationInfo = require('./getReplicationInfo');
const { config } = require('../../../Config');
const validateWebsiteHeader = require('./websiteServing')
Expand Down Expand Up @@ -144,7 +144,7 @@ function createAndStoreObject(bucketName, bucketMD, objectKey, objMD, authInfo,
metadataStoreParams.contentDisposition =
request.headers['content-disposition'];
metadataStoreParams.contentEncoding =
removeAWSChunked(request.headers['content-encoding']);
removeFromCommaSeparatedList(request.headers['content-encoding'], constants.awsChunkedContentEncoding);
metadataStoreParams.expires = request.headers.expires;
metadataStoreParams.tagging = request.headers['x-amz-tagging'];
const defaultObjectLockConfiguration
Expand Down
15 changes: 0 additions & 15 deletions lib/api/apiUtils/object/removeAWSChunked.js

This file was deleted.

7 changes: 5 additions & 2 deletions lib/api/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { data } = require('../data/wrapper');
const kms = require('../kms/wrapper');
const services = require('../services');
const { pushMetric } = require('../utapi/utilities');
const removeAWSChunked = require('./apiUtils/object/removeAWSChunked');
const removeFromCommaSeparatedList = require('../utilities/removeFromCommaSeparatedList');
const { standardMetadataValidateBucketAndObj } = require('../metadata/metadataUtils');
const validateWebsiteHeader = require('./apiUtils/object/websiteServing').validateWebsiteHeader;
const { config } = require('../Config');
Expand Down Expand Up @@ -247,7 +247,10 @@ function _prepMetadata(
contentMD5: sourceObjMD['content-md5'],
cacheControl: headersToStoreSource['cache-control'],
contentDisposition: headersToStoreSource['content-disposition'],
contentEncoding: removeAWSChunked(headersToStoreSource['content-encoding']),
// The source value may hold a separator left behind by an older
// aws-chunked removal, such as 'gzip,'
contentEncoding: removeFromCommaSeparatedList(
headersToStoreSource['content-encoding'], constants.awsChunkedContentEncoding, ''),
dataStoreName: destLocationConstraintName,
expires: headersToStoreSource.expires,
overrideMetadata,
Expand Down
5 changes: 3 additions & 2 deletions lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { config } = require('./Config');
const { data } = require('./data/wrapper');
const metadata = require('./metadata/wrapper');
const { setObjectLockInformation } = require('./api/apiUtils/object/objectLockHelpers');
const removeAWSChunked = require('./api/apiUtils/object/removeAWSChunked');
const removeFromCommaSeparatedList = require('./utilities/removeFromCommaSeparatedList');
const { parseTagFromQuery } = s3middleware.tagging;

const usersBucket = constants.usersBucket;
Expand Down Expand Up @@ -573,7 +573,8 @@ const services = {
multipartObjectMD.uploadId = params.uploadId;
multipartObjectMD['cache-control'] = params.headers['cache-control'];
multipartObjectMD['content-disposition'] = params.headers['content-disposition'];
multipartObjectMD['content-encoding'] = removeAWSChunked(params.headers['content-encoding']);
multipartObjectMD['content-encoding'] = removeFromCommaSeparatedList(
params.headers['content-encoding'], constants.awsChunkedContentEncoding);
multipartObjectMD['content-type'] = params.headers['content-type'];
multipartObjectMD.expires = params.headers.expires;
multipartObjectMD['x-amz-storage-class'] = params.storageClass; // TODO: removed CLDSRV-639
Expand Down
9 changes: 7 additions & 2 deletions lib/utilities/collectResponseHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { getVersionIdResHeader } = require('../api/apiUtils/object/versioning');
const checkUserMetadataSize
= require('../api/apiUtils/object/checkUserMetadataSize');
const { getAmzRestoreResHeader } = require('../api/apiUtils/object/coldStorage');
const removeFromCommaSeparatedList = require('./removeFromCommaSeparatedList');
const { config } = require('../Config');
const { getKeyIdFromArn } = require('arsenal/build/lib/network/KMSInterface');

Expand Down Expand Up @@ -68,8 +69,12 @@ function collectResponseHeaders(objectMD, corsHeaders, versioningCfg,
responseMetaHeaders['Content-Disposition']
= objectMD['content-disposition'];
}
if (objectMD['content-encoding']) {
responseMetaHeaders['Content-Encoding'] = objectMD['content-encoding'];
// Empty list elements are dropped from any stored value, so objects stored
// with a separator left behind by an older aws-chunked removal, such as
// 'gzip,', are returned as 'gzip' (RFC 9110, section 5.6.1)
const contentEncoding = removeFromCommaSeparatedList(objectMD['content-encoding'], '');
if (contentEncoding) {
responseMetaHeaders['Content-Encoding'] = contentEncoding;
}
if (objectMD.expires) {
responseMetaHeaders.Expires = objectMD.expires;
Expand Down
21 changes: 21 additions & 0 deletions lib/utilities/removeFromCommaSeparatedList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Removes the given elements from a comma-separated header value, along with
* their separator, wherever they appear. The other elements are kept as sent.
* Pass '' to remove empty elements, which recipients must ignore
* (RFC 9110, section 5.6.1).
* @param {string} value - comma-separated header value
* @param {...string} elements - elements to remove, compared after trimming
* @return {string} the value without those elements, trimmed
*/
function removeFromCommaSeparatedList(value, ...elements) {
if (typeof value !== 'string') {
return value;
}
return value
.split(',')
.filter(item => !elements.includes(item.trim()))
.join(',')
.trim();
}

module.exports = removeFromCommaSeparatedList;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('GET multipart upload object [Cache-Control, Content-Disposition, ' +
let uploadId;
const cacheControl = 'max-age=86400';
const contentDisposition = 'attachment; filename="fname.ext";';
const contentEncoding = 'aws-chunked,gzip';
const contentEncoding = 'gzip,aws-chunked';
// AWS Node SDK requires Date object, ISO-8601 string, or
// a UNIX timestamp for Expires header
const expires = new Date();
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/aws-node-sdk/test/object/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ describe('Object Copy', () => {
// Should remove V4 streaming value 'aws-chunked'
// to be compatible with AWS behavior
assert.strictEqual(res.ContentEncoding,
'base64,'
'base64'
);
assert.strictEqual(res.Expires.toGMTString(),
originalExpires.toGMTString());
Expand Down Expand Up @@ -484,7 +484,7 @@ describe('Object Copy', () => {
newContentDisposition);
// Should remove V4 streaming value 'aws-chunked'
// to be compatible with AWS behavior
assert.strictEqual(res.ContentEncoding, 'gzip,');
assert.strictEqual(res.ContentEncoding, 'gzip');
assert.strictEqual(res.Expires.toGMTString(),
newExpires.toGMTString());
done();
Expand Down Expand Up @@ -538,7 +538,7 @@ describe('Object Copy', () => {
assert.strictEqual(res.ContentDisposition,
originalContentDisposition);
assert.strictEqual(res.ContentEncoding,
'base64,');
'base64');
assert.strictEqual(res.Expires.toGMTString(),
originalExpires.toGMTString());
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('HEAD object, compatibility headers [Cache-Control, ' +
// Should remove V4 streaming value 'aws-chunked'
// to be compatible with AWS behavior
assert.strictEqual(res.ContentEncoding,
'gzip,');
'gzip');
assert.strictEqual(res.Expires.toGMTString(),
expires.toGMTString());
return done();
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/aws-node-sdk/test/versioning/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ describe('Object Version Copy', () => {
const res = await s3.send(new GetObjectCommand({ Bucket: destBucketName, Key: destObjName }));
assert.strictEqual(res.CacheControl, originalCacheControl);
assert.strictEqual(res.ContentDisposition, originalContentDisposition);
assert.strictEqual(res.ContentEncoding, 'base64,');
assert.strictEqual(res.ContentEncoding, 'base64');
assert.strictEqual(res.Expires.toGMTString(), originalExpires.toGMTString());
});

Expand Down Expand Up @@ -332,7 +332,7 @@ describe('Object Version Copy', () => {
const res = await s3.send(new GetObjectCommand({ Bucket: destBucketName, Key: destObjName }));
assert.strictEqual(res.CacheControl, newCacheControl);
assert.strictEqual(res.ContentDisposition, newContentDisposition);
assert.strictEqual(res.ContentEncoding, 'gzip,');
assert.strictEqual(res.ContentEncoding, 'gzip');
assert.strictEqual(res.Expires.toGMTString(), newExpires.toGMTString());
});

Expand Down Expand Up @@ -361,7 +361,7 @@ describe('Object Version Copy', () => {
const res = await s3.send(new GetObjectCommand({ Bucket: destBucketName, Key: destObjName }));
assert.strictEqual(res.CacheControl, originalCacheControl);
assert.strictEqual(res.ContentDisposition, originalContentDisposition);
assert.strictEqual(res.ContentEncoding, 'base64,');
assert.strictEqual(res.ContentEncoding, 'base64');
assert.strictEqual(res.Expires.toGMTString(), originalExpires.toGMTString());
});

Expand Down
9 changes: 8 additions & 1 deletion tests/unit/api/multipartUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async function _uploadMpuObject(params = {}) {
const _completeMultipartUpload = (...params) => util.promisify(cb =>
completeMultipartUpload(...params, (err, xml, headers) => cb(err, { xml, headers })))();

const headers = { ...initiateRequest.headers };
const headers = { ...initiateRequest.headers, ...params.headers };
if (params.location) {
headers[constants.objectLocationConstraintHeader] = params.location;
}
Expand Down Expand Up @@ -737,6 +737,13 @@ describe('Multipart Upload API', () => {
});
});

it('should store Content-Encoding without aws-chunked or a leftover separator', async () => {
await _bucketPut(authInfo, bucketPutRequest, log);
await _uploadMpuObject({ headers: { 'content-encoding': 'gzip,aws-chunked' } });
const md = metadata.keyMaps.get(bucketName).get(objectKey);
assert.strictEqual(md['content-encoding'], 'gzip');
});

it('should return an error if a complete multipart upload' +
' request contains malformed xml', done => {
async.waterfall([
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/api/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,59 @@ describe('objectCopy overheadField', () => {
});
});

describe('objectCopy Content-Encoding', () => {
before(done => {
cleanup();
// a value with a leftover separator, as stored before aws-chunked
// removal was fixed
const testPutObjectRequest = versioningTestUtils.createPutObjectRequest(
sourceBucketName, objectKey, objData[0]);
testPutObjectRequest.headers['content-encoding'] = 'gzip,';
async.series(
[
callback => bucketPut(authInfo, putDestBucketRequest, log, callback),
callback => bucketPut(authInfo, putSourceBucketRequest, log, callback),
callback => objectPut(authInfo, testPutObjectRequest, undefined, log, callback),
],
done,
);
});

after(() => {
cleanup();
});

[
{
desc: 'remove the leftover separator of the source with the COPY directive',
headers: {},
expected: 'gzip',
},
{
desc: 'remove aws-chunked from the request value with the REPLACE directive',
headers: { 'x-amz-metadata-directive': 'REPLACE', 'content-encoding': 'br,aws-chunked' },
expected: 'br',
},
{
desc: 'remove a leftover separator from the request value with the REPLACE directive',
headers: { 'x-amz-metadata-directive': 'REPLACE', 'content-encoding': 'br,' },
expected: 'br',
},
].forEach(({ desc, headers, expected }) => {
it(`should ${desc}`, done => {
const testObjectCopyRequest = _createObjectCopyRequest(destBucketName, headers);
objectCopy(authInfo, testObjectCopyRequest, sourceBucketName, objectKey, undefined, log, err => {
assert.ifError(err);
metadata.getObjectMD(destBucketName, objectKey, {}, log, (err, md) => {
assert.ifError(err);
assert.strictEqual(md['content-encoding'], expected);
done();
});
});
});
});
});

describe('objectCopy in ingestion bucket', () => {
const dataClient = data.client;
const prevDataImplName = data.implName;
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/api/objectPut.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,34 @@ describe('objectPut API', () => {
});
});

[
{ sent: 'gzip,aws-chunked', stored: 'gzip' },
{ sent: 'aws-chunked,gzip', stored: 'gzip' },
{ sent: 'aws-chunked', stored: '' },
].forEach(({ sent, stored }) => {
it(`should store Content-Encoding ${JSON.stringify(sent)} as ${JSON.stringify(stored)}`, done => {
const testPutObjectRequest = new DummyRequest({
bucketName,
namespace,
objectKey: objectName,
headers: { 'content-encoding': sent },
url: `/${bucketName}/${objectName}`,
calculatedHash: 'vnR+tLdVF79rPPfF+7YvOg==',
}, postBody);

bucketPut(authInfo, testPutBucketRequest, log, () => {
objectPut(authInfo, testPutObjectRequest, undefined, log, err => {
assert.ifError(err);
metadata.getObjectMD(bucketName, objectName, {}, log, (err, md) => {
assert.ifError(err);
assert.strictEqual(md['content-encoding'], stored);
done();
});
});
});
});
});

it('should successfully put an object with legal hold ON', done => {
const request = new DummyRequest({
bucketName,
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/utils/collectResponseHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,21 @@ describe('Middleware: Collect Response Headers', () => {
assert.strictEqual(headers['x-amz-scal-transition-in-progress'], undefined);
assert.strictEqual(headers['x-amz-meta-scal-s3-transition-in-progress'], true);
});

[
{ stored: 'gzip', expected: 'gzip' },
{ stored: 'gzip, br', expected: 'gzip, br' },
{ stored: 'gzip,', expected: 'gzip' },
{ stored: 'base64, ', expected: 'base64' },
{ stored: ' gzip', expected: 'gzip' },
{ stored: ',', expected: undefined },
{ stored: '', expected: undefined },
{ stored: undefined, expected: undefined },
].forEach(({ stored, expected }) => {
it(`should return Content-Encoding ${JSON.stringify(expected)} ` +
`when ${JSON.stringify(stored)} is stored`, () => {
const headers = collectResponseHeaders({ 'content-encoding': stored });
assert.strictEqual(headers['Content-Encoding'], expected);
});
});
});
Loading
Loading