2013-12-31 21:09:49 +04:00
|
|
|
// # Frontend Route tests
|
|
|
|
// As it stands, these tests depend on the database, and as such are integration tests.
|
|
|
|
// Mocking out the models to not touch the DB would turn these into unit tests, and should probably be done in future,
|
|
|
|
// But then again testing real code, rather than mock code, might be more useful...
|
2017-03-21 11:24:11 +03:00
|
|
|
var should = require('should'),
|
2017-02-03 16:15:11 +03:00
|
|
|
sinon = require('sinon'),
|
2017-03-21 11:24:11 +03:00
|
|
|
supertest = require('supertest'),
|
|
|
|
moment = require('moment'),
|
2016-09-13 21:23:22 +03:00
|
|
|
cheerio = require('cheerio'),
|
2017-02-27 18:53:04 +03:00
|
|
|
_ = require('lodash'),
|
2019-01-22 19:54:50 +03:00
|
|
|
testUtils = require('../../utils'),
|
|
|
|
configUtils = require('../../utils/configUtils'),
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils = require('../../utils/urlUtils'),
|
2019-01-22 19:54:50 +03:00
|
|
|
config = require('../../../server/config'),
|
|
|
|
settingsCache = require('../../../server/services/settings/cache'),
|
2017-02-27 18:53:04 +03:00
|
|
|
origCache = _.cloneDeep(settingsCache),
|
2017-03-21 11:24:11 +03:00
|
|
|
ghost = testUtils.startGhost,
|
2019-01-21 19:53:44 +03:00
|
|
|
request;
|
2013-12-31 21:09:49 +04:00
|
|
|
|
|
|
|
describe('Frontend Routing', function () {
|
|
|
|
function doEnd(done) {
|
|
|
|
return function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2013-12-31 03:13:25 +04:00
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
should.not.exist(res.headers['X-CSRF-Token']);
|
|
|
|
should.not.exist(res.headers['set-cookie']);
|
|
|
|
should.exist(res.headers.date);
|
|
|
|
|
2013-12-31 21:09:49 +04:00
|
|
|
done();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:40:32 +03:00
|
|
|
function addPosts(done) {
|
2017-03-09 22:38:20 +03:00
|
|
|
testUtils.clearData().then(function () {
|
|
|
|
return testUtils.initData();
|
|
|
|
}).then(function () {
|
2016-06-10 08:12:46 +03:00
|
|
|
return testUtils.fixtures.insertPostsAndTags();
|
2015-04-16 22:40:32 +03:00
|
|
|
}).then(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-03 16:15:11 +03:00
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2017-02-03 16:15:11 +03:00
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
request = supertest.agent(config.get('url'));
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2016-09-13 21:23:22 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('Test with Initial Fixtures', function () {
|
|
|
|
describe('Error', function () {
|
|
|
|
it('should 404 for unknown post', function (done) {
|
|
|
|
request.get('/spectacular/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.expect(/Page not found/)
|
|
|
|
.end(doEnd(done));
|
2015-09-27 22:14:09 +03:00
|
|
|
});
|
2014-10-19 23:10:13 +04:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should 404 for unknown post with invalid characters', function (done) {
|
|
|
|
request.get('/$pec+acular~/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.expect(/Page not found/)
|
|
|
|
.end(doEnd(done));
|
2016-08-23 14:47:59 +03:00
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should 404 for unknown frontend route', function (done) {
|
|
|
|
request.get('/spectacular/marvellous/')
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.expect(/Page not found/)
|
|
|
|
.end(doEnd(done));
|
2014-10-19 23:10:13 +04:00
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should 404 for encoded char not 301 from uncapitalise', function (done) {
|
|
|
|
request.get('/|/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.expect(/Page not found/)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should 404 for unknown file', function (done) {
|
|
|
|
request.get('/content/images/some/file/that/doesnt-exist.jpg')
|
2019-08-19 14:41:09 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2017-11-29 14:48:05 +03:00
|
|
|
.expect(404)
|
|
|
|
.expect(/404 Image not found/)
|
|
|
|
.end(doEnd(done));
|
2014-10-19 23:10:13 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('Single post', function () {
|
2014-10-19 23:10:13 +04:00
|
|
|
it('should redirect without slash', function (done) {
|
2017-11-29 14:48:05 +03:00
|
|
|
request.get('/welcome')
|
|
|
|
.expect('Location', '/welcome/')
|
2014-10-19 23:10:13 +04:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should redirect uppercase', function (done) {
|
|
|
|
request.get('/Welcome/')
|
|
|
|
.expect('Location', '/welcome/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
2014-10-19 23:10:13 +04:00
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should sanitize double slashes when redirecting uppercase', function (done) {
|
|
|
|
request.get('///Google.com/')
|
|
|
|
.expect('Location', '/google.com/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
});
|
|
|
|
|
2019-10-23 19:06:45 +03:00
|
|
|
it('should respond with html for valid post url', function (done) {
|
2017-11-29 14:48:05 +03:00
|
|
|
request.get('/welcome/')
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
.expect('Content-Type', /html/)
|
2017-11-29 14:48:05 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
var $ = cheerio.load(res.text);
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 20:02:20 +03:00
|
|
|
// NOTE: This is the title from the settings.
|
2017-11-29 14:48:05 +03:00
|
|
|
$('title').text().should.equal('Welcome to Ghost');
|
|
|
|
|
2019-10-23 19:06:45 +03:00
|
|
|
$('body.post-template').length.should.equal(1);
|
|
|
|
$('body.tag-getting-started').length.should.equal(1);
|
|
|
|
$('article.post').length.should.equal(2);
|
|
|
|
$('article.tag-getting-started').length.should.equal(2);
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
|
2019-10-23 19:06:45 +03:00
|
|
|
doEnd(done)(err, res);
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should not work with date permalinks', function (done) {
|
|
|
|
// get today's date
|
|
|
|
var date = moment().format('YYYY/MM/DD');
|
2017-01-17 18:40:06 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
request.get('/' + date + '/welcome/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2017-02-03 16:15:11 +03:00
|
|
|
.expect(404)
|
2017-11-29 14:48:05 +03:00
|
|
|
.expect(/Page not found/)
|
2017-02-03 16:15:11 +03:00
|
|
|
.end(doEnd(done));
|
2017-01-17 18:40:06 +03:00
|
|
|
});
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('Post edit', function () {
|
|
|
|
it('should redirect without slash', function (done) {
|
|
|
|
request.get('/welcome/edit')
|
|
|
|
.expect('Location', '/welcome/edit/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should redirect to editor', function (done) {
|
|
|
|
request.get('/welcome/edit/')
|
2018-05-21 17:26:32 +03:00
|
|
|
.expect('Location', /ghost\/editor\/\w+/)
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2017-11-29 14:48:05 +03:00
|
|
|
.expect(302)
|
2014-10-19 23:10:13 +04:00
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should 404 for non-edit parameter', function (done) {
|
|
|
|
request.get('/welcome/notedit/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.expect(/Page not found/)
|
|
|
|
.end(doEnd(done));
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2014-10-19 23:10:13 +04:00
|
|
|
|
2019-09-12 14:40:12 +03:00
|
|
|
describe('Post edit with admin redirects disabled', function () {
|
|
|
|
before(function () {
|
|
|
|
configUtils.set('admin:redirects', false);
|
|
|
|
|
|
|
|
return ghost({forceStart: true})
|
|
|
|
.then(function () {
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
|
|
|
|
return ghost({forceStart: true})
|
|
|
|
.then(function () {
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should redirect without slash', function (done) {
|
|
|
|
request.get('/welcome/edit')
|
|
|
|
.expect('Location', '/welcome/edit/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not redirect to editor', function (done) {
|
|
|
|
request.get('/welcome/edit/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('AMP post', function () {
|
|
|
|
it('should redirect without slash', function (done) {
|
|
|
|
request.get('/welcome/amp')
|
|
|
|
.expect('Location', '/welcome/amp/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should redirect uppercase', function (done) {
|
|
|
|
request.get('/Welcome/AMP/')
|
|
|
|
.expect('Location', '/welcome/amp/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
2014-10-19 23:10:13 +04:00
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should respond with html for valid url', function (done) {
|
|
|
|
request.get('/welcome/amp/')
|
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2014-10-19 23:10:13 +04:00
|
|
|
.expect(200)
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
.end(function (err, res) {
|
2017-11-29 14:48:05 +03:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2014-10-19 23:10:13 +04:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
var $ = cheerio.load(res.text);
|
2013-12-31 21:09:49 +04:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
should.not.exist(res.headers['X-CSRF-Token']);
|
|
|
|
should.not.exist(res.headers['set-cookie']);
|
|
|
|
should.exist(res.headers.date);
|
2017-03-21 11:24:11 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
$('title').text().should.equal('Welcome to Ghost');
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 20:02:20 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
$('.content .post').length.should.equal(1);
|
|
|
|
$('.poweredby').text().should.equal('Proudly published with Ghost');
|
|
|
|
$('body.amp-template').length.should.equal(1);
|
|
|
|
$('article.post').length.should.equal(1);
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
done();
|
|
|
|
});
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
});
|
2013-12-31 21:09:49 +04:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should not work with date permalinks', function (done) {
|
|
|
|
// get today's date
|
|
|
|
var date = moment().format('YYYY/MM/DD');
|
2016-08-08 10:42:04 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
request.get('/' + date + '/welcome/amp/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
.expect(404)
|
2017-11-29 14:48:05 +03:00
|
|
|
.expect(/Page not found/)
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
2018-03-19 12:11:48 +03:00
|
|
|
it('should redirect to regular post when AMP is disabled', function (done) {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
|
2017-11-29 14:48:05 +03:00
|
|
|
if (key === 'amp' && !options) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return origCache.get(key, options);
|
|
|
|
});
|
2016-08-08 10:42:04 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
request.get('/welcome/amp/')
|
2018-03-19 12:11:48 +03:00
|
|
|
.expect('Location', '/welcome/')
|
|
|
|
.expect(301)
|
2016-08-08 10:42:04 +03:00
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2019-07-08 19:29:41 +03:00
|
|
|
|
|
|
|
it('should redirect to regular post with query params when AMP is disabled', function (done) {
|
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
|
|
|
|
if (key === 'amp' && !options) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return origCache.get(key, options);
|
|
|
|
});
|
|
|
|
|
|
|
|
request.get('/welcome/amp/?q=a')
|
|
|
|
.expect('Location', '/welcome/?q=a')
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2016-08-08 10:42:04 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('Static assets', function () {
|
|
|
|
it('should retrieve theme assets', function (done) {
|
|
|
|
request.get('/assets/css/screen.css')
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(200)
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2014-07-01 03:26:08 +04:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should retrieve default robots.txt', function (done) {
|
|
|
|
request.get('/robots.txt')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
|
|
|
.expect('ETag', /[0-9a-f]{32}/i)
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2015-04-16 22:40:32 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should retrieve default favicon.ico', function (done) {
|
|
|
|
request.get('/favicon.ico')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.day)
|
|
|
|
.expect('ETag', /[0-9a-f]{32}/i)
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2015-04-16 22:40:32 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
// at the moment there is no image fixture to test
|
|
|
|
// it('should retrieve image assets', function (done) {
|
|
|
|
// request.get('/content/images/some.jpg')
|
|
|
|
// .expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
// .end(doEnd(done));
|
|
|
|
// });
|
|
|
|
});
|
|
|
|
});
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
describe('Test with added posts', function () {
|
2017-11-29 14:48:05 +03:00
|
|
|
before(addPosts);
|
2017-01-17 18:40:06 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
describe('Static page', function () {
|
|
|
|
it('should respond with html', function (done) {
|
|
|
|
request.get('/static-page-test/')
|
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.expect(200)
|
2019-10-23 19:06:45 +03:00
|
|
|
.end(function (err, res) {
|
|
|
|
var $ = cheerio.load(res.text);
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
should.not.exist(res.headers['X-CSRF-Token']);
|
|
|
|
should.not.exist(res.headers['set-cookie']);
|
|
|
|
should.exist(res.headers.date);
|
|
|
|
|
2019-11-08 13:28:07 +03:00
|
|
|
$('title').text().should.equal('This is a static page');
|
2019-10-23 19:06:45 +03:00
|
|
|
$('body.page-template').length.should.equal(1);
|
|
|
|
$('article.post').length.should.equal(1);
|
|
|
|
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
2019-02-05 04:20:16 +03:00
|
|
|
});
|
2014-11-23 20:49:47 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should redirect without slash', function (done) {
|
2019-02-05 04:20:16 +03:00
|
|
|
request.get('/static-page-test')
|
|
|
|
.expect('Location', '/static-page-test/')
|
2017-11-29 14:48:05 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2014-11-23 20:49:47 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
describe('edit', function () {
|
|
|
|
it('should redirect without slash', function (done) {
|
|
|
|
request.get('/static-page-test/edit')
|
|
|
|
.expect('Location', '/static-page-test/edit/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2014-11-23 20:49:47 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
it('should redirect to editor', function (done) {
|
|
|
|
request.get('/static-page-test/edit/')
|
|
|
|
.expect('Location', /ghost\/editor\/\w+/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.expect(302)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should 404 for non-edit parameter', function (done) {
|
|
|
|
request.get('/static-page-test/notedit/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.expect(/Page not found/)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
});
|
2014-11-23 20:49:47 +03:00
|
|
|
|
2019-09-12 14:40:12 +03:00
|
|
|
describe('edit with admin redirects disabled', function () {
|
|
|
|
before(function (done) {
|
|
|
|
configUtils.set('admin:redirects', false);
|
|
|
|
|
|
|
|
ghost({forceStart: true})
|
|
|
|
.then(function () {
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
addPosts(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
configUtils.restore();
|
|
|
|
|
|
|
|
ghost({forceStart: true})
|
|
|
|
.then(function () {
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
addPosts(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should redirect without slash', function (done) {
|
|
|
|
request.get('/static-page-test/edit')
|
|
|
|
.expect('Location', '/static-page-test/edit/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not redirect to editor', function (done) {
|
|
|
|
request.get('/static-page-test/edit/')
|
|
|
|
.expect(404)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
describe('amp', function () {
|
|
|
|
it('should 404 for amp parameter', function (done) {
|
2019-09-11 16:48:23 +03:00
|
|
|
// NOTE: only post pages are supported so the router doesn't have a way to distinguish if
|
|
|
|
// the request was done after AMP 'Page' or 'Post'
|
2019-02-05 04:20:16 +03:00
|
|
|
request.get('/static-page-test/amp/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
2019-09-11 16:48:23 +03:00
|
|
|
.expect(/Post not found/)
|
2019-02-05 04:20:16 +03:00
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2014-11-23 20:49:47 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
describe('Post preview', function () {
|
|
|
|
it('should display draft posts accessed via uuid', function (done) {
|
|
|
|
request.get('/p/d52c42ae-2755-455c-80ec-70b2ec55c903/')
|
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2014-11-23 20:49:47 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
var $ = cheerio.load(res.text);
|
2017-01-17 18:40:06 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
should.not.exist(res.headers['X-CSRF-Token']);
|
|
|
|
should.not.exist(res.headers['set-cookie']);
|
|
|
|
should.exist(res.headers.date);
|
2017-11-29 14:48:05 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
$('title').text().should.equal('Not finished yet');
|
|
|
|
// @TODO: use theme from fixtures and don't rely on content/themes/casper
|
|
|
|
// $('.content .post').length.should.equal(1);
|
|
|
|
// $('.poweredby').text().should.equal('Proudly published with Ghost');
|
|
|
|
// $('body.post-template').length.should.equal(1);
|
|
|
|
// $('article.post').length.should.equal(1);
|
2017-11-29 14:48:05 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-09-14 14:47:25 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
it('should redirect published posts to their live url', function (done) {
|
|
|
|
request.get('/p/2ac6b4f6-e1f3-406c-9247-c94a0496d39d/')
|
|
|
|
.expect(301)
|
|
|
|
.expect('Location', '/short-and-sweet/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2016-07-15 19:22:41 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
it('404s unknown uuids', function (done) {
|
|
|
|
request.get('/p/aac6b4f6-e1f3-406c-9247-c94a0496d39f/')
|
|
|
|
.expect(404)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2014-10-28 03:41:18 +03:00
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
describe('Post with Ghost in the url', function () {
|
|
|
|
// All of Ghost's admin depends on the /ghost/ in the url to work properly
|
|
|
|
// Badly formed regexs can cause breakage if a post slug starts with the 5 letters ghost
|
|
|
|
it('should retrieve a blog post with ghost at the start of the url', function (done) {
|
|
|
|
request.get('/ghostly-kitchen-sink/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Site Map', function () {
|
|
|
|
before(function (done) {
|
|
|
|
testUtils.clearData().then(function () {
|
|
|
|
return testUtils.initData();
|
|
|
|
}).then(function () {
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
2014-10-28 03:41:18 +03:00
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should serve sitemap.xml', function (done) {
|
|
|
|
request.get('/sitemap.xml')
|
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8')
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.text.should.match(/sitemapindex/);
|
|
|
|
doEnd(done)(err, res);
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should serve sitemap-posts.xml', function (done) {
|
|
|
|
request.get('/sitemap-posts.xml')
|
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8')
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.text.should.match(/urlset/);
|
|
|
|
doEnd(done)(err, res);
|
2017-09-11 15:20:29 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2017-09-11 15:20:29 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('should serve sitemap-pages.xml', function (done) {
|
2019-01-08 12:48:53 +03:00
|
|
|
request.get('/sitemap-pages.xml')
|
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8')
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.text.should.match(/urlset/);
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should serve sitemap-tags.xml', function (done) {
|
|
|
|
request.get('/sitemap-tags.xml')
|
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8')
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.text.should.match(/urlset/);
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should serve sitemap-users.xml', function (done) {
|
|
|
|
request.get('/sitemap-users.xml')
|
2017-11-29 14:48:05 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8')
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.text.should.match(/urlset/);
|
|
|
|
doEnd(done)(err, res);
|
2017-09-11 15:20:29 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
// TODO: Other pages and verify content
|
|
|
|
});
|
2017-09-11 15:20:29 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('Subdirectory (no slash)', function () {
|
|
|
|
var ghostServer;
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
before(function () {
|
|
|
|
configUtils.set('url', 'http://localhost/blog');
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
2017-11-29 14:48:05 +03:00
|
|
|
|
|
|
|
return ghost({forceStart: true, subdir: true})
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
|
|
|
|
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils.restore();
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('http://localhost should 404', function (done) {
|
|
|
|
request.get('/')
|
|
|
|
.expect(404)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('http://localhost/ should 404', function (done) {
|
|
|
|
request.get('/')
|
|
|
|
.expect(404)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('http://localhost/blog should 301 to http://localhost/blog/', function (done) {
|
|
|
|
request.get('/blog')
|
|
|
|
.expect(301)
|
|
|
|
.expect('Location', '/blog/')
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('http://localhost/blog/ should 200', function (done) {
|
|
|
|
request.get('/blog/')
|
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('http://localhost/blog/welcome should 301 to http://localhost/blog/welcome/', function (done) {
|
|
|
|
request.get('/blog/welcome')
|
|
|
|
.expect(301)
|
|
|
|
.expect('Location', '/blog/welcome/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('http://localhost/blog/welcome/ should 200', function (done) {
|
|
|
|
request.get('/blog/welcome/')
|
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('/blog/tag/getting-started should 301 to /blog/tag/getting-started/', function (done) {
|
|
|
|
request.get('/blog/tag/getting-started')
|
|
|
|
.expect(301)
|
|
|
|
.expect('Location', '/blog/tag/getting-started/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('/blog/tag/getting-started/ should 200', function (done) {
|
|
|
|
request.get('/blog/tag/getting-started/')
|
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('/blog/welcome/amp/ should 200', function (done) {
|
|
|
|
request.get('/blog/welcome/amp/')
|
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('Subdirectory (with slash)', function () {
|
|
|
|
var ghostServer;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
configUtils.set('url', 'http://localhost/blog/');
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
2017-11-29 14:48:05 +03:00
|
|
|
|
|
|
|
return ghost({forceStart: true, subdir: true})
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils.restore();
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('http://localhost should 404', function (done) {
|
|
|
|
request.get('/')
|
|
|
|
.expect(404)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('http://localhost/ should 404', function (done) {
|
|
|
|
request.get('/')
|
|
|
|
.expect(404)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('/blog should 301 to /blog/', function (done) {
|
|
|
|
request.get('/blog')
|
|
|
|
.expect(301)
|
|
|
|
.expect('Location', '/blog/')
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('/blog/ should 200', function (done) {
|
|
|
|
request.get('/blog/')
|
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('/blog/welcome should 301 to /blog/welcome/', function (done) {
|
|
|
|
request.get('/blog/welcome')
|
|
|
|
.expect(301)
|
|
|
|
.expect('Location', '/blog/welcome/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('/blog/welcome/ should 200', function (done) {
|
|
|
|
request.get('/blog/welcome/')
|
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('/blog/tag/getting-started should 301 to /blog/tag/getting-started/', function (done) {
|
|
|
|
request.get('/blog/tag/getting-started')
|
|
|
|
.expect(301)
|
|
|
|
.expect('Location', '/blog/tag/getting-started/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('/blog/tag/getting-started/ should 200', function (done) {
|
|
|
|
request.get('/blog/tag/getting-started/')
|
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('/blog/welcome/amp/ should 200', function (done) {
|
|
|
|
request.get('/blog/welcome/amp/')
|
|
|
|
.expect(200)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should uncapitalise correctly with 301 to subdir', function (done) {
|
|
|
|
request.get('/blog/AAA/')
|
|
|
|
.expect('Location', '/blog/aaa/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// we'll use X-Forwarded-Proto: https to simulate an 'https://' request behind a proxy
|
|
|
|
describe('HTTPS', function () {
|
|
|
|
var ghostServer;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
configUtils.set('url', 'http://localhost:2370/');
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
2017-11-29 14:48:05 +03:00
|
|
|
|
|
|
|
return ghost({forceStart: true})
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils.restore();
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set links to url over non-HTTPS', function (done) {
|
|
|
|
request.get('/')
|
|
|
|
.expect(200)
|
|
|
|
.expect(/<link rel="canonical" href="http:\/\/localhost:2370\/" \/\>/)
|
|
|
|
.expect(/<a href="http:\/\/localhost:2370">Ghost<\/a\>/)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set links over HTTPS besides canonical', function (done) {
|
|
|
|
request.get('/')
|
|
|
|
.set('X-Forwarded-Proto', 'https')
|
|
|
|
.expect(200)
|
|
|
|
.expect(/<link rel="canonical" href="http:\/\/localhost:2370\/" \/\>/)
|
|
|
|
.expect(/<a href="https:\/\/localhost:2370">Ghost<\/a\>/)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-01 07:11:04 +03:00
|
|
|
// TODO: convert to unit tests
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('Redirects (use redirects.json from test/utils/fixtures/data)', function () {
|
|
|
|
var ghostServer;
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
before(function () {
|
|
|
|
configUtils.set('url', 'http://localhost:2370/');
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
2017-11-29 14:48:05 +03:00
|
|
|
|
|
|
|
return ghost({forceStart: true})
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils.restore();
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('1 case', function () {
|
|
|
|
it('with trailing slash', function (done) {
|
|
|
|
request.get('/post/10/a-nice-blog-post')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/a-nice-blog-post');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('without trailing slash', function (done) {
|
|
|
|
request.get('/post/10/a-nice-blog-post/')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/a-nice-blog-post');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('with query params', function (done) {
|
|
|
|
request.get('/topic?something=good')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/?something=good');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('with query params', function (done) {
|
|
|
|
request.get('/post/10/a-nice-blog-post?a=b')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/a-nice-blog-post?a=b');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2018-09-24 19:57:05 +03:00
|
|
|
it('with case insensitive', function (done) {
|
|
|
|
request.get('/CaSe-InSeNsItIvE')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/redirected-insensitive');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('with case sensitive', function (done) {
|
|
|
|
request.get('/Case-Sensitive')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/redirected-sensitive');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('defaults to case sensitive', function (done) {
|
|
|
|
request.get('/Default-Sensitive')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/redirected-default');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not redirect with case sensitive', function (done) {
|
|
|
|
request.get('/casE-sensitivE')
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.not.eql('/redirected-sensitive');
|
|
|
|
res.statusCode.should.not.eql(302);
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not redirect with default case sensitive', function (done) {
|
|
|
|
request.get('/defaulT-sensitivE')
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.not.eql('/redirected-default');
|
|
|
|
res.statusCode.should.not.eql(302);
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('2 case', function () {
|
|
|
|
it('with trailing slash', function (done) {
|
|
|
|
request.get('/my-old-blog-post/')
|
|
|
|
.expect(301)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/revamped-url/');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('without trailing slash', function (done) {
|
|
|
|
request.get('/my-old-blog-post')
|
|
|
|
.expect(301)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/revamped-url/');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('3 case', function () {
|
|
|
|
it('with trailing slash', function (done) {
|
|
|
|
request.get('/what/')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/what-does-god-say');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('without trailing slash', function (done) {
|
|
|
|
request.get('/what')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/what-does-god-say');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
2017-11-29 14:48:05 +03:00
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
describe('4 case', function () {
|
|
|
|
it('with trailing slash', function (done) {
|
|
|
|
request.get('/search/label/&&&/')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/tag/&&&/');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
|
2017-11-29 14:48:05 +03:00
|
|
|
it('without trailing slash', function (done) {
|
|
|
|
request.get('/search/label/&&&/')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/tag/&&&/');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('5 case', function () {
|
|
|
|
it('with trailing slash', function (done) {
|
|
|
|
request.get('/topic/')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('without trailing slash', function (done) {
|
|
|
|
request.get('/topic')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('6 case', function () {
|
|
|
|
it('with trailing slash', function (done) {
|
|
|
|
request.get('/resources/download/')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/shubal-stearns');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('without trailing slash', function (done) {
|
|
|
|
request.get('/resources/download')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/shubal-stearns');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('7 case', function () {
|
|
|
|
it('with trailing slash', function (done) {
|
|
|
|
request.get('/2016/11/welcome.html')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/welcome');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('last case', function () {
|
|
|
|
it('default', function (done) {
|
|
|
|
request.get('/prefix/')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/blog/');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('with a custom path', function (done) {
|
|
|
|
request.get('/prefix/expect-redirect')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('/blog/expect-redirect');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
2017-02-06 17:32:40 +03:00
|
|
|
});
|
|
|
|
});
|
2019-04-01 07:11:04 +03:00
|
|
|
|
|
|
|
describe('external url redirect', function () {
|
|
|
|
it('with trailing slash', function (done) {
|
|
|
|
request.get('/external-url/')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('https://ghost.org/');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('without trailing slash', function (done) {
|
|
|
|
request.get('/external-url')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.end(function (err, res) {
|
|
|
|
res.headers.location.should.eql('https://ghost.org/');
|
|
|
|
doEnd(done)(err, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-10-28 03:41:18 +03:00
|
|
|
});
|
2013-12-31 21:09:49 +04:00
|
|
|
});
|