Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Apr 9, 2024
1 parent be486d3 commit d2eafe4
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 113 deletions.
8 changes: 4 additions & 4 deletions lib/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const bucketDeleteEncryption = require('./bucketDeleteEncryption');
const bucketDeleteWebsite = require('./bucketDeleteWebsite');
const bucketDeleteLifecycle = require('./bucketDeleteLifecycle');
const bucketDeletePolicy = require('./bucketDeletePolicy');
const deleteBucketQuota = require('./bucketDeleteQuota');
const bucketDeleteQuota = require('./bucketDeleteQuota');
const { bucketGet } = require('./bucketGet');
const bucketGetACL = require('./bucketGetACL');
const bucketGetCors = require('./bucketGetCors');
Expand Down Expand Up @@ -35,7 +35,7 @@ const bucketPutNotification = require('./bucketPutNotification');
const bucketPutEncryption = require('./bucketPutEncryption');
const bucketPutPolicy = require('./bucketPutPolicy');
const bucketPutObjectLock = require('./bucketPutObjectLock');
const updateBucketQuota = require('./bucketUpdateQuota');
const bucketUpdateQuota = require('./bucketUpdateQuota');
const bucketGetReplication = require('./bucketGetReplication');
const bucketDeleteReplication = require('./bucketDeleteReplication');
const corsPreflight = require('./corsPreflight');
Expand Down Expand Up @@ -319,9 +319,9 @@ const api = {
bucketPutReplication,
bucketGetReplication,
bucketDeleteReplication,
deleteBucketQuota,
bucketDeleteQuota,
bucketPutLifecycle,
updateBucketQuota,
bucketUpdateQuota,
bucketGetLifecycle,
bucketDeleteLifecycle,
bucketPutPolicy,
Expand Down
4 changes: 2 additions & 2 deletions lib/api/bucketDeleteQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const monitoring = require('../utilities/monitoringHandler');
* @param {function} callback - callback to server
* @return {undefined}
*/
function deleteBucketQuota(authInfo, request, log, callback) {
function bucketDeleteQuota(authInfo, request, log, callback) {
log.debug('processing request', { method: 'bucketDeleteQuota' });

const { bucketName } = request;
Expand Down Expand Up @@ -58,4 +58,4 @@ function deleteBucketQuota(authInfo, request, log, callback) {
});
}

module.exports = deleteBucketQuota;
module.exports = bucketDeleteQuota;
7 changes: 1 addition & 6 deletions lib/api/bucketGetQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ function bucketGetQuota(authInfo, request, log, callback) {
return callback(err, null, corsHeaders);
}
const bucketQuota = bucket.getQuota();
log.debug('Heres the quota', {
quota: bucketQuota,
method: 'bucketGetQuota',
});
if (!bucketQuota) {
log.debug('error processing request', {
error: errors.NoSuchBucketQuota,
log.debug('bucket has no quota', {
method: 'bucketGetQuota',
});
return callback(errors.NoSuchBucketQuota, null,
Expand Down
13 changes: 6 additions & 7 deletions lib/api/bucketUpdateQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const monitoring = require('../utilities/monitoringHandler');
* @param {function} callback - callback to server
* @return {undefined}
*/
function updateBucketQuota(authInfo, request, log, callback) {
function bucketUpdateQuota(authInfo, request, log, callback) {
log.debug('processing request', { method: 'bucketUpdateQuota' });

const { bucketName } = request;
Expand Down Expand Up @@ -42,16 +42,15 @@ function updateBucketQuota(authInfo, request, log, callback) {
return next(errors.InvalidArgument.customizeDescription('Request body must be a JSON object'));
}
const quota = parseInt(requestBody.quota, 10);
if (isNaN(quota)) {
if (Number.isNaN(quota)) {
return next(errors.InvalidArgument.customizeDescription('Quota Value should be a number'));
}
if (quota <= 0) {
return next(errors.InvalidArgument.customizeDescription('Quota Value should be a positive number'));
return next(errors.InvalidArgument.customizeDescription('Quota value must be a positive number'));
}
// Update the bucket quota
bucket.setQuota(quota);
return metadata.updateBucket(bucket.getName(), bucket, log, err =>
next(err));
return metadata.updateBucket(bucket.getName(), bucket, log, next);
},
], err => {
const corsHeaders = collectCorsHeaders(request.headers.origin,
Expand All @@ -72,8 +71,8 @@ function updateBucketQuota(authInfo, request, log, callback) {
bucket: bucketName,
});
}
return callback(null, 200, corsHeaders);
return callback(null, corsHeaders);
});
}

module.exports = updateBucketQuota;
module.exports = bucketUpdateQuota;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@azure/storage-blob": "^12.12.0",
"@hapi/joi": "^17.1.0",
"arsenal": "git+https://github.com/scality/arsenal#dd6955cff3cc2e1caa5279dd1d9885c93bcee12b",
"arsenal": "git+https://github.com/scality/arsenal#b5f6ac8d7cd452d04fe37b4a307806908c8823b8",
"async": "~2.5.0",
"aws-sdk": "2.905.0",
"bucketclient": "scality/bucketclient#8.1.9",
Expand Down Expand Up @@ -74,7 +74,7 @@
"cloudserver": "S3METADATA=mongodb npm-run-all --parallel start_dataserver start_s3server",
"ft_awssdk": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/",
"ft_awssdk_aws": "cd tests/functional/aws-node-sdk && AWS_ON_AIR=true mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/",
"ft_awssdk_buckets": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/bucket",
"ft_awssdk_buckets": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/bucket",
"ft_awssdk_objects_misc": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/legacy test/object test/service test/support",
"ft_awssdk_versioning": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/versioning/",
"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",
Expand Down
21 changes: 12 additions & 9 deletions tests/functional/aws-node-sdk/test/bucket/deleteBucketQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ describe('Test delete bucket quota', () => {

afterEach(done => s3.deleteBucket({ Bucket: bucket }, done));

it('should delete the bucket quota', done => {
sendRequest('DELETE', '127.0.0.1:8000', `/${bucket}/?quota=true`, '', err => {
assert.strictEqual(err, null);
done();
});
it('should delete the bucket quota', async () => {
try {
await sendRequest('DELETE', '127.0.0.1:8000', `/${bucket}/?quota=true`);
assert.ok(true);
} catch (err) {
assert.fail(`Expected no error, but got ${err}`);
}
});

it('should return no such bucket error', done => {
sendRequest('DELETE', '127.0.0.1:8000', `/${nonExistantBucket}/?quota=true`, '', err => {
it('should return no such bucket error', async () => {
try {
await sendRequest('DELETE', '127.0.0.1:8000', `/${nonExistantBucket}/?quota=true`);
} catch (err) {
assert.strictEqual(err.Error.Code[0], 'NoSuchBucket');
done();
});
}
});
});
75 changes: 46 additions & 29 deletions tests/functional/aws-node-sdk/test/bucket/getBucketQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,58 @@ describe('Test get bucket quota', () => {

afterEach(done => s3.deleteBucket({ Bucket: bucket }, done));

it('should return the quota', done => {
sendRequest('POST', '127.0.0.1:8000', `/${bucket}/?quota=true`, JSON.stringify(quota), error => {
if (error) {
done(error);
return;
it('should return the quota', async () => {
try {
await sendRequest('PUT', '127.0.0.1:8000', `/${bucket}/?quota=true`, JSON.stringify(quota));
const data = await sendRequest('GET', '127.0.0.1:8000', `/${bucket}/?quota=true`);
assert.strictEqual(data.GetBucketQuota.Name[0], bucket);
assert.strictEqual(data.GetBucketQuota.Quota[0], '1000');
} catch (err) {
assert.fail(`Expected no error, but got ${err}`);
}
});

it('should return no such bucket error', async () => {
try {
await sendRequest('GET', '127.0.0.1:8000', '/test/?quota=true');
} catch (err) {
assert.strictEqual(err.Error.Code[0], 'NoSuchBucket');
}
});

it('should return no such bucket quota', async () => {
try {
await sendRequest('DELETE', '127.0.0.1:8000', `/${bucket}/?quota=true`);
try {
await sendRequest('GET', '127.0.0.1:8000', `/${bucket}/?quota=true`);
assert.fail('Expected NoSuchBucketQuota error');
} catch (err) {
assert.strictEqual(err.Error.Code[0], 'NoSuchBucketQuota');
}
sendRequest('GET', '127.0.0.1:8000', `/${bucket}/?quota=true`, '', (error, data) => {
if (error) {
done(error);
return;
}
assert.strictEqual(data.GetBucketQuota.Name[0], bucket);
assert.strictEqual(data.GetBucketQuota.Quota[0], '1000');
done();
});
});
} catch (err) {
assert.fail(`Expected no error, but got ${err}`);
}
});

it('should return no such bucket error', done => {
sendRequest('GET', '127.0.0.1:8000', '/test/?quota=true', '', err => {
it('should return no such bucket error', async () => {
try {
await sendRequest('GET', '127.0.0.1:8000', '/test/?quota=true');
} catch (err) {
assert.strictEqual(err.Error.Code[0], 'NoSuchBucket');
done();
});
}
});

it('should return no such bucket quota', done => {
sendRequest('DELETE', '127.0.0.1:8000', `/${bucket}/?quota=true`, '', err => {
if (err) {
done(err);
return;
it('should return no such bucket quota', async () => {
try {
await sendRequest('DELETE', '127.0.0.1:8000', `/${bucket}/?quota=true`);
try {
await sendRequest('GET', '127.0.0.1:8000', `/${bucket}/?quota=true`);
assert.fail('Expected NoSuchBucketQuota error');
} catch (err) {
assert.strictEqual(err.Error.Code[0], 'NoSuchBucketQuota');
}
sendRequest('GET', '127.0.0.1:8000', `/${bucket}/?quota=true`, '', err => {
assert.strictEqual(err.Error.Code[0], 'NoSuchBucketQuota');
done();
});
});
} catch (err) {
assert.fail(`Expected no error, but got ${err}`);
}
});
});
41 changes: 23 additions & 18 deletions tests/functional/aws-node-sdk/test/bucket/updateBucketQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,38 @@ describe('Test update bucket quota', () => {

afterEach(done => s3.deleteBucket({ Bucket: bucket }, done));

it('should update the quota', done => {
sendRequest('POST', '127.0.0.1:8000', `/${bucket}/?quota=true`, JSON.stringify(quota), err => {
assert.strictEqual(err, null);
done();
});
it('should update the quota', async () => {
try {
await sendRequest('PUT', '127.0.0.1:8000', `/${bucket}/?quota=true`, JSON.stringify(quota));
assert.ok(true);
} catch (err) {
assert.fail(`Expected no error, but got ${err}`);
}
});

it('should return no such bucket error', done => {
sendRequest('POST', '127.0.0.1:8000', `/${nonExistantBucket}/?quota=true`, JSON.stringify(quota), err => {
it('should return no such bucket error', async () => {
try {
await sendRequest('PUT', '127.0.0.1:8000', `/${nonExistantBucket}/?quota=true`, JSON.stringify(quota));
} catch (err) {
assert.strictEqual(err.Error.Code[0], 'NoSuchBucket');
done();
});
}
});

it('should return error when quota is negative', done => {
sendRequest('POST', '127.0.0.1:8000', `/${bucket}/?quota=true`, JSON.stringify(negativeQuota), err => {
it('should return error when quota is negative', async () => {
try {
await sendRequest('PUT', '127.0.0.1:8000', `/${bucket}/?quota=true`, JSON.stringify(negativeQuota));
} catch (err) {
assert.strictEqual(err.Error.Code[0], 'InvalidArgument');
assert.strictEqual(err.Error.Message[0], 'Quota Value should be a positive number');
done();
});
assert.strictEqual(err.Error.Message[0], 'Quota value must be a positive number');
}
});

it('should return error when quota is not in correct format', done => {
sendRequest('POST', '127.0.0.1:8000', `/${bucket}/?quota=true`, wrongquotaFromat, err => {
it('should return error when quota is not in correct format', async () => {
try {
await sendRequest('PUT', '127.0.0.1:8000', `/${bucket}/?quota=true`, wrongquotaFromat);
} catch (err) {
assert.strictEqual(err.Error.Code[0], 'InvalidArgument');
assert.strictEqual(err.Error.Message[0], 'Request body must be a JSON object');
done();
});
}
});
});
69 changes: 35 additions & 34 deletions tests/functional/aws-node-sdk/test/quota/tooling.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,47 @@ const fetch = require('node-fetch');
const AWS = require('aws-sdk');
const xml2js = require('xml2js');

const sendRequest = async (method, host, path, body = '', callback) => {
const service = 's3';
const endpoint = new AWS.Endpoint(host);
const sendRequest = async (method, host, path, body = '') =>
new Promise(async (resolve, reject) => {
const service = 's3';
const endpoint = new AWS.Endpoint(host);

const request = new AWS.HttpRequest(endpoint);
request.method = method.toUpperCase();
request.path = path;
request.body = body;
request.headers.Host = host;
request.headers['X-Amz-Date'] = new Date().toISOString().replace(/[:\-]|\.\d{3}/g, '');
const sha256hash = AWS.util.crypto.sha256(request.body || '', 'hex');
request.headers['X-Amz-Content-SHA256'] = sha256hash;
request.region = 'us-east-1';
const request = new AWS.HttpRequest(endpoint);
request.method = method.toUpperCase();
request.path = path;
request.body = body;
request.headers.Host = host;
request.headers['X-Amz-Date'] = new Date().toISOString().replace(/[:\-]|\.\d{3}/g, '');
const sha256hash = AWS.util.crypto.sha256(request.body || '', 'hex');
request.headers['X-Amz-Content-SHA256'] = sha256hash;
request.region = 'us-east-1';

const signer = new AWS.Signers.V4(request, service);
signer.addAuthorization(AWS.config.credentials, new Date());
const signer = new AWS.Signers.V4(request, service);
signer.addAuthorization(AWS.config.credentials, new Date());

const url = `http://${host}${path}`;
const options = {
method: request.method,
headers: request.headers
};
const url = `http://${host}${path}`;
const options = {
method: request.method,
headers: request.headers,
};

if (method !== 'GET' && method !== 'HEAD') {
options.body = request.body;
}
if (method !== 'GET') {
options.body = request.body;
}

try {
const response = await fetch(url, options);
const text = await response.text();
const result = await xml2js.parseStringPromise(text);
if (result && result.Error) {
callback(result, null);
} else {
callback(null, result);
try {
const response = await fetch(url, options);
const text = await response.text();
const result = await xml2js.parseStringPromise(text);
if (result && result.Error) {
reject(result);
} else {
resolve(result);
}
} catch (error) {
reject(error);
}
} catch (error) {
callback(error, null);
}
};
});

module.exports = {
sendRequest,
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,9 @@ arraybuffer.slice@~0.0.7:
optionalDependencies:
ioctl "^2.0.2"

"arsenal@git+https://github.com/scality/arsenal#dd6955cff3cc2e1caa5279dd1d9885c93bcee12b":
"arsenal@git+https://github.com/scality/arsenal#b5f6ac8d7cd452d04fe37b4a307806908c8823b8":
version "8.1.127"
resolved "git+https://github.com/scality/arsenal#dd6955cff3cc2e1caa5279dd1d9885c93bcee12b"
resolved "git+https://github.com/scality/arsenal#b5f6ac8d7cd452d04fe37b4a307806908c8823b8"
dependencies:
"@azure/identity" "^3.1.1"
"@azure/storage-blob" "^12.12.0"
Expand Down

0 comments on commit d2eafe4

Please sign in to comment.