diff --git a/lib/middleware/blob/validation.js b/lib/middleware/blob/validation.js index e4bc53d..9b7994e 100644 --- a/lib/middleware/blob/validation.js +++ b/lib/middleware/blob/validation.js @@ -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'), @@ -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) diff --git a/lib/routes/blob/ContainerRoute.js b/lib/routes/blob/ContainerRoute.js index 7882525..50fd5b5 100644 --- a/lib/routes/blob/ContainerRoute.js +++ b/lib/routes/blob/ContainerRoute.js @@ -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; } /* @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/lib/validation/blob/BlobName.js b/lib/validation/blob/BlobName.js new file mode 100644 index 0000000..dab7f8b --- /dev/null +++ b/lib/validation/blob/BlobName.js @@ -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; \ No newline at end of file diff --git a/lib/validation/blob/ContainerName.js b/lib/validation/blob/ContainerName.js index db90c68..a48c888 100644 --- a/lib/validation/blob/ContainerName.js +++ b/lib/validation/blob/ContainerName.js @@ -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) {