0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Fixed RoutingService checks for resource existence

We were incorrectly handling a "no resource found" return value from the
ResourceService, instead of an object with `null` values, we were expecting a
`null` value - so we were considering all URL's to be pointing toward a
resource.
This commit is contained in:
Fabien "egg" O'Carroll 2023-01-24 17:58:28 +07:00
parent 88979c852b
commit 169eb6046e
2 changed files with 6 additions and 6 deletions

View file

@ -50,7 +50,7 @@ module.exports = class RoutingService {
const resource = await this.#resourceService.getByURL(url);
if (resource) {
if (resource?.type !== null) {
return true;
}

View file

@ -65,7 +65,7 @@ describe('RoutingService', function () {
externalRequest: got
});
resourceService.getByURL.resolves({pe: 'post', id: new ObjectID});
resourceService.getByURL.resolves({type: 'post', id: new ObjectID});
const result = await routingService.pageExists(new URL('https://website.com/subdir/post'));
assert.equal(result, true);
@ -84,7 +84,7 @@ describe('RoutingService', function () {
externalRequest: got
});
resourceService.getByURL.resolves(null);
resourceService.getByURL.resolves({type: null, id: null});
nock('https://website.com').head('/subdir/should-exist').reply(200);
@ -103,7 +103,7 @@ describe('RoutingService', function () {
externalRequest: got
});
resourceService.getByURL.resolves(null);
resourceService.getByURL.resolves({type: null, id: null});
nock('https://website.com').head('/subdir/should-redirect').reply(301);
@ -122,7 +122,7 @@ describe('RoutingService', function () {
externalRequest: got
});
resourceService.getByURL.resolves(null);
resourceService.getByURL.resolves({type: null, id: null});
nock('https://website.com').head('/subdir/not-exist').reply(404);
@ -141,7 +141,7 @@ describe('RoutingService', function () {
externalRequest: got
});
resourceService.getByURL.resolves(null);
resourceService.getByURL.resolves({type: null, id: null});
nock('https://website.com').head('/subdir/big-error').reply(500);