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
7 changes: 5 additions & 2 deletions lib/api/bucketUpdateQuota.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@francoisferrand I tried the curl command provided in the doc we gave to the client :
curl -X PUT "http://localhost:8000/testb/?quota=true" --user "accessKey1:verySecretKey1" --aws-sigv4 "aws:amz:us-east-1:s3" -d '{"quota" : 32}'

In that case, curl will not set the content-type header. So I think it's tricky to modify the logic around the body parsing by using content type, because clients can't be expected to set that header so no matter what we will have to use a fallback which is basically the code that we already have with the try/catch

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const monitoring = require('../utilities/monitoringHandler');
const { parseString } = require('xml2js');

function validateBucketQuotaProperty(requestBody, next) {
const quota = requestBody.quota;
let quota = requestBody.quota;
if (quota === undefined) {
quota = requestBody.QuotaConfiguration?.Quota;
}
const quotaValue = parseInt(quota, 10);
if (Number.isNaN(quotaValue)) {
return next(errorInstances.InvalidArgument.customizeDescription('Quota Value should be a number'));
Expand All @@ -27,7 +30,7 @@ function parseRequestBody(requestBody, next) {
}
return next(null, jsonData);
} catch {
return parseString(requestBody, (xmlError, xmlData) => {
return parseString(requestBody, { explicitArray: false }, (xmlError, xmlData) => {
if (xmlError) {
return next(errorInstances.InvalidArgument.customizeDescription('Request body must be a JSON object'));
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenko/cloudserver",
"version": "9.2.14",
"version": "9.3.0-preview.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanna do this now, because this change is for the cloudserver quota client feature, and I need an image with this new code to run in the test pipeline. Otherwise can't merge the new client

"description": "Zenko CloudServer, an open-source Node.js implementation of a server handling the Amazon S3 protocol",
"main": "index.js",
"engines": {
Expand Down
10 changes: 10 additions & 0 deletions tests/functional/aws-node-sdk/test/bucket/updateBucketQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ describe('Test update bucket quota', () => {
it('should update the quota', () => sendRequest('PUT',
'127.0.0.1:8000', `/${bucket}/?quota=true`, JSON.stringify(quota)));

it('should update quota with XML format', async () => {
try {
const xmlQuota = '<QuotaConfiguration><Quota>3000</Quota></QuotaConfiguration>';
await sendRequest('PUT', '127.0.0.1:8000', `/${bucket}/?quota=true`, xmlQuota);
assert.ok(true);
} catch (err) {
assert.fail(`Expected no error, but got ${err}`);
}
});

it('should return no such bucket error', async () => {
try {
await sendRequest('PUT', '127.0.0.1:8000', `/${nonExistantBucket}/?quota=true`, JSON.stringify(quota));
Expand Down
Loading