diff --git a/ghost/core/core/server/adapters/storage/LocalStorageBase.js b/ghost/core/core/server/adapters/storage/LocalStorageBase.js index 6a0e3372f8..274247fbfa 100644 --- a/ghost/core/core/server/adapters/storage/LocalStorageBase.js +++ b/ghost/core/core/server/adapters/storage/LocalStorageBase.js @@ -149,6 +149,10 @@ class LocalStorageBase extends StorageBase { return next(new errors.NoPermissionError({err: err})); } + if (err.name === 'RangeNotSatisfiableError') { + return next(new errors.RangeNotSatisfiableError({err})); + } + return next(new errors.InternalServerError({err: err})); } diff --git a/ghost/core/test/unit/server/adapters/storage/LocalBaseStorage.test.js b/ghost/core/test/unit/server/adapters/storage/LocalBaseStorage.test.js index dd0724ee24..b74f28b49f 100644 --- a/ghost/core/test/unit/server/adapters/storage/LocalBaseStorage.test.js +++ b/ghost/core/test/unit/server/adapters/storage/LocalBaseStorage.test.js @@ -1,7 +1,38 @@ +const assert = require('assert/strict'); +const path = require('path'); +const http = require('http'); +const express = require('express'); const should = require('should'); const LocalStorageBase = require('../../../../../core/server/adapters/storage/LocalStorageBase'); describe('Local Storage Base', function () { + describe('serve', function () { + it('returns a 416 RangeNotSatisfiableError if given an invalid range', function (done) { + const localStorageBase = new LocalStorageBase({ + storagePath: path.resolve(__dirname, 'media-storage'), + staticFileURLPrefix: 'content/media', + siteUrl: 'http://example.com/blog/' + }); + + const req = new http.IncomingMessage(); + const res = new http.ServerResponse(req); + + Object.setPrototypeOf(req, express.request); + Object.setPrototypeOf(res, express.response); + + req.method = 'GET'; + req.url = '/content/media/image.jpg'; + req.headers = { + range: 'bytes=1000-999' + }; + + localStorageBase.serve()(req, res, (err) => { + assert.equal(err.errorType, 'RangeNotSatisfiableError'); + done(); + }); + }); + }); + describe('urlToPath', function () { it('returns path from url', function () { let localStorageBase = new LocalStorageBase({ diff --git a/ghost/core/test/unit/server/adapters/storage/media-storage/content/media/image.jpg b/ghost/core/test/unit/server/adapters/storage/media-storage/content/media/image.jpg new file mode 100644 index 0000000000..8198c77f7a Binary files /dev/null and b/ghost/core/test/unit/server/adapters/storage/media-storage/content/media/image.jpg differ