Compare commits
2 Commits
developmen
...
bugfix/S3C
Author | SHA1 | Date |
---|---|---|
Frédéric Meinnel | b602364047 | |
Frédéric Meinnel | c41d909a8c |
|
@ -66,6 +66,8 @@
|
||||||
"ft_awssdk_external_backends": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/multipleBackend",
|
"ft_awssdk_external_backends": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/multipleBackend",
|
||||||
"ft_management": "cd tests/functional/report && yarn test",
|
"ft_management": "cd tests/functional/report && yarn test",
|
||||||
"ft_node": "cd tests/functional/raw-node && yarn test",
|
"ft_node": "cd tests/functional/raw-node && yarn test",
|
||||||
|
"ft_node_lifecycle": "cd tests/functional/raw-node && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json -t 40000 test/lifecycle.js",
|
||||||
|
"ft_node_lifecycle_aws": "cd tests/functional/raw-node && AWS_ON_AIR=true mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json -t 40000 test/lifecycle.js",
|
||||||
"ft_node_routes": "cd tests/functional/raw-node && yarn run test-routes",
|
"ft_node_routes": "cd tests/functional/raw-node && yarn run test-routes",
|
||||||
"ft_gcp": "cd tests/functional/raw-node && yarn run test-gcp",
|
"ft_gcp": "cd tests/functional/raw-node && yarn run test-gcp",
|
||||||
"ft_healthchecks": "cd tests/functional/healthchecks && yarn test",
|
"ft_healthchecks": "cd tests/functional/healthchecks && yarn test",
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const { makeS3Request } = require('../utils/makeRequest');
|
||||||
|
const { randomUUID } = require('crypto');
|
||||||
|
|
||||||
|
const authCredentials = {
|
||||||
|
accessKey: process.env.AWS_ON_AIR ? 'awsAK' : 'accessKey1',
|
||||||
|
secretKey: process.env.AWS_ON_AIR ? 'awsSK' : 'verySecretKey1',
|
||||||
|
};
|
||||||
|
|
||||||
|
const bucket = `rawnodelifecyclebucket-${randomUUID()}`;
|
||||||
|
|
||||||
|
function makeLifeCycleXML(date) {
|
||||||
|
return `
|
||||||
|
<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
|
<Rule>
|
||||||
|
<Expiration>
|
||||||
|
<Date>${date}</Date>
|
||||||
|
</Expiration>
|
||||||
|
<ID>my-id</ID>
|
||||||
|
<Filter />
|
||||||
|
<Status>Enabled</Status>
|
||||||
|
</Rule>
|
||||||
|
</LifecycleConfiguration>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('api tests', () => {
|
||||||
|
before(done => {
|
||||||
|
makeS3Request({
|
||||||
|
method: 'PUT',
|
||||||
|
authCredentials,
|
||||||
|
bucket,
|
||||||
|
}, err => {
|
||||||
|
assert.ifError(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(done => {
|
||||||
|
makeS3Request({
|
||||||
|
method: 'DELETE',
|
||||||
|
authCredentials,
|
||||||
|
bucket,
|
||||||
|
}, err => {
|
||||||
|
assert.ifError(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject a lifecycle policy with a date not at midnight', done => {
|
||||||
|
makeS3Request({
|
||||||
|
method: 'PUT',
|
||||||
|
authCredentials,
|
||||||
|
bucket,
|
||||||
|
queryObj: { lifecycle: '' },
|
||||||
|
requestBody: makeLifeCycleXML('2024-01-08T12:34:56Z'),
|
||||||
|
}, (err) => {
|
||||||
|
assert.strictEqual(err.code, 'InvalidArgument');
|
||||||
|
assert.strictEqual(err.statusCode, 400);
|
||||||
|
return done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should accept a lifecycle policy with a date at midnight', done => {
|
||||||
|
makeS3Request({
|
||||||
|
method: 'PUT',
|
||||||
|
authCredentials,
|
||||||
|
bucket,
|
||||||
|
queryObj: { lifecycle: '' },
|
||||||
|
requestBody: makeLifeCycleXML('2024-01-08T00:00:00Z'),
|
||||||
|
}, (err, res) => {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.strictEqual(res.statusCode, 200);
|
||||||
|
return done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -111,18 +111,14 @@ function makeRequest(params, callback) {
|
||||||
// decode path because signing code re-encodes it
|
// decode path because signing code re-encodes it
|
||||||
req.path = _decodeURI(encodedPath);
|
req.path = _decodeURI(encodedPath);
|
||||||
if (authCredentials && !params.GCP) {
|
if (authCredentials && !params.GCP) {
|
||||||
if (queryObj) {
|
auth.client.generateV4Headers(req, queryObj || '',
|
||||||
auth.client.generateV4Headers(req, queryObj,
|
|
||||||
authCredentials.accessKey, authCredentials.secretKey, 's3');
|
authCredentials.accessKey, authCredentials.secretKey, 's3');
|
||||||
// may update later if request may contain POST body
|
|
||||||
} else {
|
|
||||||
auth.client.generateV4Headers(req, '', authCredentials.accessKey,
|
|
||||||
authCredentials.secretKey, 's3');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// restore original URL-encoded path
|
// restore original URL-encoded path
|
||||||
req.path = encodedPath;
|
req.path = encodedPath;
|
||||||
req.path = queryObj ? `${options.path}?${qs}` : req.path;
|
if (queryObj) {
|
||||||
|
req.path = `${options.path}?${qs}`;
|
||||||
|
}
|
||||||
if (requestBody) {
|
if (requestBody) {
|
||||||
req.write(requestBody);
|
req.write(requestBody);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +139,7 @@ function makeRequest(params, callback) {
|
||||||
* @return {undefined} - and call callback
|
* @return {undefined} - and call callback
|
||||||
*/
|
*/
|
||||||
function makeS3Request(params, callback) {
|
function makeS3Request(params, callback) {
|
||||||
const { method, queryObj, headers, bucket, objectKey, authCredentials }
|
const { method, queryObj, headers, bucket, objectKey, authCredentials, requestBody }
|
||||||
= params;
|
= params;
|
||||||
const options = {
|
const options = {
|
||||||
authCredentials,
|
authCredentials,
|
||||||
|
@ -153,6 +149,7 @@ function makeS3Request(params, callback) {
|
||||||
queryObj,
|
queryObj,
|
||||||
headers: headers || {},
|
headers: headers || {},
|
||||||
path: bucket ? `/${bucket}/` : '/',
|
path: bucket ? `/${bucket}/` : '/',
|
||||||
|
requestBody,
|
||||||
};
|
};
|
||||||
if (objectKey) {
|
if (objectKey) {
|
||||||
options.path = `${options.path}${objectKey}`;
|
options.path = `${options.path}${objectKey}`;
|
||||||
|
|
Loading…
Reference in New Issue