Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bugfix/CLDSRV-493/fully-align-wi…
Browse files Browse the repository at this point in the history
…th-aws-on-lifecycle-configuration-dates' into w/7.70/bugfix/CLDSRV-493/fully-align-with-aws-on-lifecycle-configuration-dates
  • Loading branch information
fredmnl committed Jan 17, 2024
2 parents dea5173 + e3c093f commit acc5f74
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "s3",
"version": "7.70.42",
"version": "7.70.43",
"description": "S3 connector",
"main": "index.js",
"engines": {
Expand All @@ -20,7 +20,7 @@
"homepage": "https://github.com/scality/S3#readme",
"dependencies": {
"@hapi/joi": "^17.1.0",
"arsenal": "git+https://github.com/scality/arsenal#7.70.19",
"arsenal": "git+https://github.com/scality/arsenal#7.70.21",
"async": "~2.5.0",
"aws-sdk": "2.905.0",
"azure-storage": "^2.1.0",
Expand Down
133 changes: 133 additions & 0 deletions tests/functional/raw-node/test/lifecycle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
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 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();
});
});

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:00'),
}, (err, res) => {
assert.ifError(err);
assert.strictEqual(res.statusCode, 200);
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-08T06:00:00+06:00'),
}, (err, res) => {
assert.ifError(err);
assert.strictEqual(res.statusCode, 200);
return 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 reject a lifecycle policy with an illegal date', done => {
makeS3Request({
method: 'PUT',
authCredentials,
bucket,
queryObj: { lifecycle: '' },
requestBody: makeLifeCycleXML('2024-01-08T00:00:00+34:00'),
}, err => {
// This value is catched by AWS during XML parsing
assert(err.code === 'InvalidArgument' || err.code === 'MalformedXML');
assert.strictEqual(err.statusCode, 400);
return 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-08T00:00:00.123Z'),
}, err => {
assert.strictEqual(err.code, 'InvalidArgument');
assert.strictEqual(err.statusCode, 400);
return done();
});
});
});
3 changes: 2 additions & 1 deletion tests/functional/raw-node/utils/makeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,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,
Expand All @@ -153,6 +153,7 @@ function makeS3Request(params, callback) {
queryObj,
headers: headers || {},
path: bucket ? `/${bucket}/` : '/',
requestBody,
};
if (objectKey) {
options.path = `${options.path}${objectKey}`;
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ arraybuffer.slice@~0.0.7:
optionalDependencies:
ioctl "^2.0.2"

"arsenal@git+https://github.com/scality/arsenal#7.70.19":
version "7.70.19"
resolved "git+https://github.com/scality/arsenal#39f42d9cb4dd940b641d858a01ce63cd6569d278"
"arsenal@git+https://github.com/scality/arsenal#7.70.21":
version "7.70.21"
resolved "git+https://github.com/scality/arsenal#5734d11cf1e1ba5b7f485285a249fa7c748f0e47"
dependencies:
"@types/async" "^3.2.12"
"@types/utf8" "^3.0.1"
Expand Down

0 comments on commit acc5f74

Please sign in to comment.