Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
fixes #160
Browse files Browse the repository at this point in the history
  • Loading branch information
arafato committed Mar 2, 2018
1 parent 205b54f commit 353f4fe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/middleware/blob/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const BbPromise = require('bluebird'),
ContentLengthExistsVal = require('./../../validation/blob/ContentLengthExists'),
ContainerExistsVal = require('./../../validation/blob/ContainerExists'),
BlobExistsVal = require('./../../validation/blob/BlobExists'),
BlobNameVal = require('./../../validation/blob/BlobName'),
BlobCommittedVal = require('./../../validation/blob/BlobCommitted'),
IsOfBlobTypeVal = require('./../../validation/blob/IsOfBlobType'),
RangeVal = require('./../../validation/blob/Range'),
Expand Down Expand Up @@ -106,6 +107,7 @@ validations[Operations.Blob.PUT_BLOB] = (request, valContext) => {
.run(ServiceSignatureValidation, { sasOperation: SasOperation.Blob.WRITE })
.run(MD5Val)
.run(ContainerExistsVal)
.run(BlobNameVal)
.run(CompatibleBlobTypeVal)
.run(SupportedBlobTypeVal)
.run(PutBlobHeaderVal)
Expand Down
15 changes: 9 additions & 6 deletions lib/routes/blob/ContainerRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const ContainerRequest = require('./../../model/blob/AzuriteContainerRequest'),
Operations = require('./../../core/Constants').Operations;

// Possibly implicit call to blob in $root container
const REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE = (req) => {
const REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE = (req, next) => {
req.url = req.url.replace(req.params.container, `$root/${req.params.container}`);
next('route');
return;
}

/*
Expand All @@ -31,7 +30,8 @@ module.exports = (app) => {
} else if (req.query.restype === 'container') {
req.azuriteOperation = Operations.Container.GET_CONTAINER_PROPERTIES;
} else {
REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE(req);
REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE(req, next);
return;
}
req.azuriteRequest = new ContainerRequest({ req: req });
next();
Expand All @@ -45,7 +45,8 @@ module.exports = (app) => {
} else if (req.query.restype === 'container') {
req.azuriteOperation = Operations.Container.GET_CONTAINER_PROPERTIES;
} else {
REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE(req);
REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE(req, next);
return;
}
req.azuriteRequest = new ContainerRequest({ req: req });
next();
Expand All @@ -69,7 +70,8 @@ module.exports = (app) => {
else if (req.query.restype === 'container') {
req.azuriteOperation = Operations.Container.CREATE_CONTAINER;
} else {
REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE(req);
REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE(req, next);
return;
}
req.azuriteRequest = new ContainerRequest({ req: req });
next();
Expand All @@ -78,7 +80,8 @@ module.exports = (app) => {
if (req.query.restype === 'container') {
req.azuriteOperation = Operations.Container.DELETE_CONTAINER;
} else {
REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE(req);
REWRITE_URL_AND_FORWARD_TO_BLOB_ROUTE(req, next);
return;
}
req.azuriteRequest = new ContainerRequest({ req: req });
next();
Expand Down
25 changes: 25 additions & 0 deletions lib/validation/blob/BlobName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const AError = require('./../../core/AzuriteError'),
ErrorCodes = require('./../../core/ErrorCodes');

/*
* Checks whether the blob name adheres to the naming convention when being created within the $root container
* as specified at https://docs.microsoft.com/en-us/rest/api/storageservices/working-with-the-root-container
*/
class BlobName {
constructor() {
}

validate({ request = undefined }) {
const containerName = request.containerName,
blobName = request.blobName;
if (containerName === '$root') {
if (blobName && blobName.includes('/')) {
throw new AError(ErrorCodes.InvalidResourceName);
}
}
}
}

module.exports = new BlobName;
3 changes: 0 additions & 3 deletions lib/validation/blob/ContainerName.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class ContainerName {
validate({ request = undefined }) {
const name = request.containerName;
if (name === '$root') {
if (request.blobName.includes('/')) {
throw new AError(ErrorCodes.InvalidResourceName);
}
return;
}
if (name.length < 3 || name.length > 63) {
Expand Down

0 comments on commit 353f4fe

Please sign in to comment.