2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
2021-10-06 10:52:46 +01:00
|
|
|
const ghost_foot = require('../../../../core/frontend/helpers/ghost_foot');
|
|
|
|
const {settingsCache} = require('../../../../core/frontend/services/proxy');
|
2014-11-28 11:09:45 +00:00
|
|
|
|
2017-03-21 08:24:11 +00:00
|
|
|
describe('{{ghost_foot}} helper', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
let settingsCacheStub;
|
2014-10-10 15:54:07 +01:00
|
|
|
|
2017-03-21 08:24:11 +00:00
|
|
|
afterEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
sinon.restore();
|
2014-10-10 15:54:07 +01:00
|
|
|
});
|
|
|
|
|
2017-03-23 19:00:58 +00:00
|
|
|
beforeEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
settingsCacheStub = sinon.stub(settingsCache, 'get');
|
2014-10-10 15:54:07 +01:00
|
|
|
});
|
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
it('outputs global injected code', function () {
|
2020-07-01 17:58:12 +01:00
|
|
|
settingsCacheStub.withArgs('codeinjection_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2014-11-28 11:09:45 +00:00
|
|
|
|
2021-10-04 16:30:54 +01:00
|
|
|
const rendered = ghost_foot({data: {}});
|
2019-04-15 16:15:32 +02:00
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
2015-08-18 09:08:52 -04:00
|
|
|
});
|
2017-03-23 19:00:58 +00:00
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
it('outputs post injected code', function () {
|
2020-07-01 17:58:12 +01:00
|
|
|
settingsCacheStub.withArgs('codeinjection_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2017-08-02 13:38:19 +04:00
|
|
|
|
2021-10-04 16:30:54 +01:00
|
|
|
const rendered = ghost_foot({
|
2017-08-02 13:38:19 +04:00
|
|
|
data: {
|
|
|
|
root: {
|
|
|
|
post: {
|
|
|
|
codeinjection_foot: 'post-codeinjection'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-15 16:15:32 +02:00
|
|
|
});
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
|
|
|
rendered.string.should.match(/post-codeinjection/);
|
2017-08-02 13:38:19 +04:00
|
|
|
});
|
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
it('handles post injected code being null', function () {
|
2020-07-01 17:58:12 +01:00
|
|
|
settingsCacheStub.withArgs('codeinjection_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2017-08-02 13:38:19 +04:00
|
|
|
|
2021-10-04 16:30:54 +01:00
|
|
|
const rendered = ghost_foot({
|
2017-08-02 13:38:19 +04:00
|
|
|
data: {
|
|
|
|
root: {
|
|
|
|
post: {
|
|
|
|
codeinjection_foot: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-15 16:15:32 +02:00
|
|
|
});
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
|
|
|
rendered.string.should.not.match(/post-codeinjection/);
|
2017-08-02 13:38:19 +04:00
|
|
|
});
|
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
it('handles post injected code being empty', function () {
|
2020-07-01 17:58:12 +01:00
|
|
|
settingsCacheStub.withArgs('codeinjection_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2017-08-02 13:38:19 +04:00
|
|
|
|
2021-10-04 16:30:54 +01:00
|
|
|
const rendered = ghost_foot({
|
2017-08-02 13:38:19 +04:00
|
|
|
data: {
|
|
|
|
root: {
|
|
|
|
post: {
|
|
|
|
codeinjection_foot: ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-15 16:15:32 +02:00
|
|
|
});
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
|
|
|
rendered.string.should.not.match(/post-codeinjection/);
|
2017-08-02 13:38:19 +04:00
|
|
|
});
|
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
it('handles global empty code injection', function () {
|
2020-07-01 17:58:12 +01:00
|
|
|
settingsCacheStub.withArgs('codeinjection_foot').returns('');
|
2017-03-23 19:00:58 +00:00
|
|
|
|
2021-10-04 16:30:54 +01:00
|
|
|
const rendered = ghost_foot({data: {}});
|
2019-04-15 16:15:32 +02:00
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.eql('');
|
2017-03-23 19:00:58 +00:00
|
|
|
});
|
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
it('handles global undefined code injection', function () {
|
2020-07-01 17:58:12 +01:00
|
|
|
settingsCacheStub.withArgs('codeinjection_foot').returns(undefined);
|
2017-03-23 19:00:58 +00:00
|
|
|
|
2021-10-04 16:30:54 +01:00
|
|
|
const rendered = ghost_foot({data: {}});
|
2019-04-15 16:15:32 +02:00
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.eql('');
|
2017-03-23 19:00:58 +00:00
|
|
|
});
|
2014-10-10 15:54:07 +01:00
|
|
|
});
|