Compare commits

...

2 Commits

Author SHA1 Message Date
Frédéric Meinnel b602364047 simplification 2024-01-10 18:23:26 +01:00
Frédéric Meinnel c41d909a8c S3C-8355: Trying out some lifecycle requests on cloudserver and AWS. 2024-01-10 18:23:26 +01:00
3 changed files with 86 additions and 10 deletions

View File

@ -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_management": "cd tests/functional/report && 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_gcp": "cd tests/functional/raw-node && yarn run test-gcp",
"ft_healthchecks": "cd tests/functional/healthchecks && yarn test",

View File

@ -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();
});
});
});

View File

@ -111,18 +111,14 @@ function makeRequest(params, callback) {
// decode path because signing code re-encodes it
req.path = _decodeURI(encodedPath);
if (authCredentials && !params.GCP) {
if (queryObj) {
auth.client.generateV4Headers(req, queryObj,
authCredentials.accessKey, authCredentials.secretKey, 's3');
// may update later if request may contain POST body
} else {
auth.client.generateV4Headers(req, '', authCredentials.accessKey,
authCredentials.secretKey, 's3');
}
auth.client.generateV4Headers(req, queryObj || '',
authCredentials.accessKey, authCredentials.secretKey, 's3');
}
// restore original URL-encoded path
req.path = encodedPath;
req.path = queryObj ? `${options.path}?${qs}` : req.path;
if (queryObj) {
req.path = `${options.path}?${qs}`;
}
if (requestBody) {
req.write(requestBody);
}
@ -143,7 +139,7 @@ function makeRequest(params, callback) {
* @return {undefined} - and call callback
*/
function makeS3Request(params, callback) {
const { method, queryObj, headers, bucket, objectKey, authCredentials }
const { method, queryObj, headers, bucket, objectKey, authCredentials, requestBody }
= params;
const options = {
authCredentials,
@ -153,6 +149,7 @@ function makeS3Request(params, callback) {
queryObj,
headers: headers || {},
path: bucket ? `/${bucket}/` : '/',
requestBody,
};
if (objectKey) {
options.path = `${options.path}${objectKey}`;