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