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...
|
2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const supertest = require('supertest');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const testUtils = require('../../utils');
|
|
|
|
const configUtils = require('../../utils/configUtils');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../core/shared/config');
|
2022-01-14 19:55:48 +03:00
|
|
|
const settingsCache = require('../../../core/shared/settings-cache');
|
2020-04-29 18:44:27 +03:00
|
|
|
let 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();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-17 11:07:26 +03:00
|
|
|
function assertCorrectFrontendHeaders(res) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2022-01-04 14:53:07 +03:00
|
|
|
before(async function () {
|
|
|
|
await testUtils.startGhost({
|
|
|
|
copyThemes: true,
|
|
|
|
copySettings: true,
|
|
|
|
redirectsFile: true
|
|
|
|
});
|
|
|
|
|
|
|
|
request = supertest.agent(config.get('url'));
|
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 with invalid characters', function (done) {
|
|
|
|
request.get('/$pec+acular~/')
|
2022-09-20 12:47:59 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.noCache)
|
2017-11-29 14:48:05 +03:00
|
|
|
.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')
|
2022-09-20 12:47:59 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.noCache)
|
2017-11-29 14:48:05 +03:00
|
|
|
.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('/|/')
|
2022-09-20 12:47:59 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.noCache)
|
2017-11-29 14:48:05 +03:00
|
|
|
.expect(404)
|
|
|
|
.expect(/Page not found/)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2014-10-19 23:10:13 +04:00
|
|
|
});
|
|
|
|
|
2020-03-20 13:23:56 +03:00
|
|
|
describe('Default Redirects (clean URLS)', function () {
|
|
|
|
it('Single post 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));
|
|
|
|
});
|
|
|
|
|
2020-03-20 13:23:56 +03:00
|
|
|
it('Single post should redirect uppercase', function (done) {
|
2017-11-29 14:48:05 +03:00
|
|
|
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));
|
|
|
|
});
|
|
|
|
|
2020-03-20 13:23:56 +03:00
|
|
|
it('Single post should sanitize double slashes when redirecting uppercase', function (done) {
|
2017-11-29 14:48:05 +03:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2020-03-20 13:23:56 +03:00
|
|
|
it('AMP post should redirect without slash', function (done) {
|
2017-11-29 14:48:05 +03:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2020-03-20 13:23:56 +03:00
|
|
|
it('AMP post should redirect uppercase', function (done) {
|
2017-11-29 14:48:05 +03:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|
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) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const $ = cheerio.load(res.text);
|
2019-10-23 19:06:45 +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);
|
|
|
|
|
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 () {
|
2022-05-17 09:31:31 +03:00
|
|
|
it('should redirect without slash', async function () {
|
|
|
|
await request.get('/static-page-test/edit')
|
2019-02-05 04:20:16 +03:00
|
|
|
.expect('Location', '/static-page-test/edit/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
2022-05-17 11:07:26 +03:00
|
|
|
.expect(301)
|
|
|
|
.expect(assertCorrectFrontendHeaders);
|
2019-02-05 04:20:16 +03:00
|
|
|
});
|
2014-11-23 20:49:47 +03:00
|
|
|
|
2022-05-17 09:31:31 +03:00
|
|
|
it('should redirect to editor for post resource', async function () {
|
|
|
|
await request.get('//welcome/edit/')
|
|
|
|
.expect('Location', /ghost\/#\/editor\/post\/\w+/)
|
2019-02-05 04:20:16 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2022-05-17 11:07:26 +03:00
|
|
|
.expect(302)
|
|
|
|
.expect(assertCorrectFrontendHeaders);
|
2019-02-05 04:20:16 +03:00
|
|
|
});
|
|
|
|
|
2022-05-17 09:31:31 +03:00
|
|
|
it('should redirect to editor for page resource', async function () {
|
|
|
|
await request.get('/static-page-test/edit/')
|
|
|
|
.expect('Location', /ghost\/#\/editor\/page\/\w+/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2022-05-17 11:07:26 +03:00
|
|
|
.expect(302)
|
|
|
|
.expect(assertCorrectFrontendHeaders);
|
2022-05-17 09:31:31 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should 404 for non-edit parameter', async function () {
|
|
|
|
await request.get('/static-page-test/notedit/')
|
2022-09-20 12:47:59 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.noCache)
|
2019-02-05 04:20:16 +03:00
|
|
|
.expect(404)
|
2022-05-17 11:07:26 +03:00
|
|
|
.expect(/Page not found/)
|
|
|
|
.expect(assertCorrectFrontendHeaders);
|
2019-02-05 04:20:16 +03:00
|
|
|
});
|
🔥✨ 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);
|
|
|
|
|
2021-11-24 11:39:00 +03:00
|
|
|
testUtils.startGhost({forceStart: true})
|
2019-09-12 14:40:12 +03:00
|
|
|
.then(function () {
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
addPosts(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function (done) {
|
Fixed configUtils and adapter cache issues in E2E tests (#16167)
no issue
There are a couple of issues with resetting the Ghost instance between
E2E test files:
These issues came to the surface because of new tests written in
https://github.com/TryGhost/Ghost/pull/16117
**1. configUtils.restore does not work correctly**
`config.reset()` is a callback based method. On top of that, it doesn't
really work reliably (https://github.com/indexzero/nconf/issues/93)
What kinda happens, is that you first call `config.reset` but
immediately after you correcty reset the config using the `config.set`
calls afterwards. But since `config.reset` is async, that reset will
happen after all those sets, and the end result is that it isn't reset
correctly.
This mainly caused issues in the new updated images tests, which were
updating the config `imageOptimization.contentImageSizes`, which is a
deeply nested config value. Maybe some references to objects are reused
in nconf that cause this issue?
Wrapping `config.reset()` in a promise does fix the issue.
**2. Adapters cache not reset between tests**
At the start of each test, we set `paths:contentPath` to a nice new
temporary directory. But if a previous test already requests a
localStorage adapter, that adapter would have been created and in the
constructor `paths:contentPath` would have been passed. That same
instance will be reused in the next test run. So it won't read the new
config again. To fix this, we need to reset the adapter instances
between E2E tests.
How was this visible? Test uploads were stored in the actual git
repository, and not in a temporary directory. When writing the new image
upload tests, this also resulted in unreliable test runs because some
image names were already taken (from previous test runs).
**3. Old 2E2 test Ghost server not stopped**
Sometimes we still need access to the frontend test server using
`getAgentsWithFrontend`. But that does start a new Ghost server which is
actually listening for HTTP traffic. This could result in a fatal error
in tests because the port is already in use. The issue is that old E2E
tests also start a HTTP server, but they don't stop the server. When you
used the old `startGhost` util, it would check if a server was already
running and stop it first. The new `getAgentsWithFrontend` now also has
the same functionality to fix that issue.
2023-01-30 16:06:20 +03:00
|
|
|
configUtils.restore().then(() => {
|
|
|
|
return testUtils.startGhost({forceStart: true});
|
|
|
|
}).then(function () {
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
addPosts(done);
|
|
|
|
});
|
2019-09-12 14:40:12 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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)
|
2022-09-20 12:47:59 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.noCache)
|
2019-09-12 14:40:12 +03:00
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-05 04:20:16 +03:00
|
|
|
describe('amp', function () {
|
2022-01-14 19:55:48 +03:00
|
|
|
describe('amp enabled', function (){
|
|
|
|
beforeEach(function () {
|
|
|
|
sinon.stub(settingsCache, 'get').withArgs('amp').returns(true);
|
|
|
|
});
|
|
|
|
it('should 404 for amp parameter', function (done) {
|
|
|
|
// 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'
|
|
|
|
request.get('/static-page-test/amp/')
|
2022-09-20 12:47:59 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.noCache)
|
2022-01-14 19:55:48 +03:00
|
|
|
.expect(404)
|
|
|
|
.expect(/Post not found/)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('amp disabled', function (){
|
|
|
|
beforeEach(function () {
|
|
|
|
sinon.stub(settingsCache, 'get').withArgs('amp').returns(false);
|
|
|
|
});
|
|
|
|
it('should 301 for amp parameter', function (done) {
|
|
|
|
// 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'
|
|
|
|
request.get('/static-page-test/amp/')
|
|
|
|
.expect(301)
|
|
|
|
.end(doEnd(done));
|
|
|
|
});
|
2019-02-05 04:20:16 +03:00
|
|
|
});
|
🔥✨ 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 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
|
|
|
});
|
|
|
|
});
|
2013-12-31 21:09:49 +04:00
|
|
|
});
|