2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
2021-10-06 12:52:46 +03:00
|
|
|
const ghost_foot = require('../../../../core/frontend/helpers/ghost_foot');
|
|
|
|
const {settingsCache} = require('../../../../core/frontend/services/proxy');
|
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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = ghost_foot({data: {}});
|
2019-04-15 17:15:32 +03:00
|
|
|
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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = 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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = 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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = 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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = ghost_foot({data: {}});
|
2019-04-15 17:15:32 +03:00
|
|
|
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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = ghost_foot({data: {}});
|
2019-04-15 17:15:32 +03:00
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.eql('');
|
2017-03-23 22:00:58 +03:00
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|