Ghost/core/test/unit
Aileen Nowak a45a91c906 🐛 Fix invalid image URLs not being cached and causing timeouts (#8986)
refs #8868

* 📐  Use request util in image-size
- swapped the usage of `got` for requests with the request util

* 💄  Use catch predicates
- Uses catch predicates instead of conditionals in `getImageSizeFromUrl`
- Return `NotFoundError` if applicable in `getImageSizeFromFilePath` as the caller function `cachedImageSizeFromUrl` is differentiating those between this error and others.

* 🐛  Fixed ImageObject URL & simplify no protocol URL logic

- Using `ImageObject` as a global var resulted in having the `url` property being the same for all requests coming in.
- The logic that checked for an existing protocol (e. g. gravatar URLs) was overly complicated. Refactored it to be more simple.
- Passing the correct value to `fetchDimensionsFromBuffer` as the population of `imageObject.url` happens there. These are used in our structured data and need to be full URLs (in case of locally stored files) or the original URL (in case of URLs missing the protocol)
- Added two more debug logs in `getCachedImageSizeFromUrl` so it's logged when an image is added to the cache even tho it was returned as error.

* 👀  Differentiate error codes between request and storage

* 🔥  Remove not needed `Promise.resolve()`

We're always resolving the result in `getCachedImageSizeFromUrl`, so there's no need to return the values with a `Promise.resolve()`. The caller fn uses waits for the Promises to be fulfilled.

* ☂️  Wrap already rejected predicate errors in catch all

* Use errorDetails instead of context

* ☂️  Support /assets/ image paths

- adds a guard that checks the image URL for `/assets/` in the beginning and passes a completed URL to the request util to try and fetch the image size
- adds tests
2017-09-12 12:53:18 +01:00
..
adapters 🐛 Fixed post scheduling (#8976) 2017-09-05 19:23:11 +01:00
api 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
auth 🚑 Disable remote authentication (#8346) 2017-04-24 18:56:49 +01:00
config fix(config): cleanup absolute path config function (#8641) 2017-07-06 00:04:18 +02:00
controllers/frontend 🐛 Fixed channel context to be based on res.locals (#8910) 2017-08-16 11:06:30 +01:00
data/importer 🎨 Support LTS imports (#8498) 2017-06-04 11:53:00 +02:00
mail 🔥 fromaddress support (#8753) 2017-07-27 12:27:38 +04:00
metadata Refactor: fetch image dimensions from local file storage (#8900) 2017-09-05 14:13:22 +02:00
middleware Blog and Admin redirects with trailing slash (#8955) 2017-08-30 17:42:00 +01:00
models/base 🎨 change last_login to last_seen (#8259) 2017-04-05 20:45:55 +01:00
models_plugins 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
server_helpers Tests: Stub image request for dimensions (#8973) 2017-09-05 16:24:04 +01:00
settings 🐛 fix settings cache (#8506) 2017-06-04 17:52:22 +07:00
sitemap 🙀 Image field naming & new img_url helper (#8364) 2017-04-24 18:21:47 +01:00
themes 🐛 Remove trailing slash for {{@blog.url}} (#8596) 2017-06-19 16:11:53 +02:00
utils 🐛 Fix invalid image URLs not being cached and causing timeouts (#8986) 2017-09-12 12:53:18 +01:00
admin_spec.js 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
api_utils_spec.js 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
apps_filters_spec.js 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
apps_spec.js Helper Proxy & single express-hbs instance (#8225) 2017-04-04 18:07:35 +02:00
errors_spec.js 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
exporter_spec.js 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
filters_spec.js 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
ghost_sdk_spec.js 🛠 🙈 Rename ghost-url.js to ghost-sdk.js (#8767) 2017-07-28 18:23:32 +04:00
migration_fixture_utils_spec.js 📖 new default post content (#8548) 2017-06-08 16:36:14 +01:00
migration_spec.js Add ghost-backup client to trigger export (#8911) 2017-08-22 11:15:40 +01:00
permissions_spec.js 🐛 be able to serve locked users (#8711) 2017-07-20 12:45:13 +01:00
rss_spec.js 🦄 Channels: Stored config in res.locals not req (#8884) 2017-08-14 10:21:24 +07:00
server_helpers_index_spec.js 🙀 Image field naming & new img_url helper (#8364) 2017-04-24 18:21:47 +01:00
server_helpers_template_spec.js Helper Proxy & single express-hbs instance (#8225) 2017-04-04 18:07:35 +02:00
server_utils_spec.js 🎨 refactor the importer (#8473) 2017-05-23 17:18:13 +01:00
slack_spec.js 📖 new default post content (#8548) 2017-06-08 16:36:14 +01:00
social-urls_spec.js improvement: jshint/jscs 2016-06-17 22:59:47 +02:00
utils_pipeline_spec.js 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
validation_spec.js 💄 🐷 Test consistency (#8199) 2017-03-21 09:24:11 +01:00
xmlrpc_spec.js 📖 new default post content (#8548) 2017-06-08 16:36:14 +01:00