2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const helpers = require('../../../core/frontend/helpers');
|
|
|
|
const proxy = require('../../../core/frontend/services/proxy');
|
|
|
|
const settingsCache = proxy.settingsCache;
|
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 () {
|
2018-04-18 07:33:31 -05:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2014-11-28 11:09:45 +00:00
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
const rendered = helpers.ghost_foot({data: {}});
|
|
|
|
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 () {
|
2018-04-18 07:33:31 -05:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2017-08-02 13:38:19 +04:00
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
const rendered = helpers.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 () {
|
2018-04-18 07:33:31 -05:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2017-08-02 13:38:19 +04:00
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
const rendered = helpers.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 () {
|
2018-04-18 07:33:31 -05:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2017-08-02 13:38:19 +04:00
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
const rendered = helpers.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 () {
|
2017-03-23 19:00:58 +00:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('');
|
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
const rendered = helpers.ghost_foot({data: {}});
|
|
|
|
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 () {
|
2017-03-23 19:00:58 +00:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns(undefined);
|
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
const rendered = helpers.ghost_foot({data: {}});
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.eql('');
|
2017-03-23 19:00:58 +00:00
|
|
|
});
|
2014-10-10 15:54:07 +01:00
|
|
|
});
|