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