2018-06-02 21:48:23 +02:00
|
|
|
var should = require('should'),
|
2017-03-21 09:24:11 +01:00
|
|
|
sinon = require('sinon'),
|
2014-10-10 16:54:07 +02:00
|
|
|
|
|
|
|
// Stuff we are testing
|
2017-03-23 20:00:58 +01:00
|
|
|
helpers = require('../../../server/helpers'),
|
2017-04-04 18:07:35 +02:00
|
|
|
proxy = require('../../../server/helpers/proxy'),
|
|
|
|
settingsCache = proxy.settingsCache,
|
2014-10-10 16:54:07 +02:00
|
|
|
|
2017-03-21 09:24:11 +01:00
|
|
|
sandbox = sinon.sandbox.create();
|
2014-11-28 12:09:45 +01:00
|
|
|
|
2017-03-21 09:24:11 +01:00
|
|
|
describe('{{ghost_foot}} helper', function () {
|
2017-03-23 20:00:58 +01:00
|
|
|
var settingsCacheStub;
|
2014-10-10 16:54:07 +02:00
|
|
|
|
2017-03-21 09:24:11 +01:00
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
2014-10-10 16:54:07 +02:00
|
|
|
});
|
|
|
|
|
2017-03-23 20:00:58 +01:00
|
|
|
beforeEach(function () {
|
|
|
|
settingsCacheStub = sandbox.stub(settingsCache, 'get');
|
2014-10-10 16:54:07 +02:00
|
|
|
});
|
|
|
|
|
2017-08-02 11:38:19 +02:00
|
|
|
it('outputs global injected code', function (done) {
|
2018-04-18 14:33:31 +02:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2014-11-28 12:09:45 +01:00
|
|
|
|
2017-08-02 11:38:19 +02:00
|
|
|
helpers.ghost_foot({data: {}}).then(function (rendered) {
|
2015-08-18 15:08:52 +02:00
|
|
|
should.exist(rendered);
|
2018-04-18 14:33:31 +02:00
|
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
2014-11-28 12:09:45 +01:00
|
|
|
|
2015-08-18 15:08:52 +02:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2017-03-23 20:00:58 +01:00
|
|
|
|
2017-08-02 11:38:19 +02:00
|
|
|
it('outputs post injected code', function (done) {
|
2018-04-18 14:33:31 +02:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2017-08-02 11:38:19 +02:00
|
|
|
|
|
|
|
helpers.ghost_foot({
|
|
|
|
data: {
|
|
|
|
root: {
|
|
|
|
post: {
|
|
|
|
codeinjection_foot: 'post-codeinjection'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).then(function (rendered) {
|
|
|
|
should.exist(rendered);
|
2018-04-18 14:33:31 +02:00
|
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
2017-08-02 11:38:19 +02:00
|
|
|
rendered.string.should.match(/post-codeinjection/);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles post injected code being null', function (done) {
|
2018-04-18 14:33:31 +02:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2017-08-02 11:38:19 +02:00
|
|
|
|
|
|
|
helpers.ghost_foot({
|
|
|
|
data: {
|
|
|
|
root: {
|
|
|
|
post: {
|
|
|
|
codeinjection_foot: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).then(function (rendered) {
|
|
|
|
should.exist(rendered);
|
2018-04-18 14:33:31 +02:00
|
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
2017-08-02 11:38:19 +02:00
|
|
|
rendered.string.should.not.match(/post-codeinjection/);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles post injected code being empty', function (done) {
|
2018-04-18 14:33:31 +02:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
2017-08-02 11:38:19 +02:00
|
|
|
|
|
|
|
helpers.ghost_foot({
|
|
|
|
data: {
|
|
|
|
root: {
|
|
|
|
post: {
|
|
|
|
codeinjection_foot: ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).then(function (rendered) {
|
|
|
|
should.exist(rendered);
|
2018-04-18 14:33:31 +02:00
|
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
2017-08-02 11:38:19 +02:00
|
|
|
rendered.string.should.not.match(/post-codeinjection/);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles global empty code injection', function (done) {
|
2017-03-23 20:00:58 +01:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns('');
|
|
|
|
|
2017-08-02 11:38:19 +02:00
|
|
|
helpers.ghost_foot({data: {}}).then(function (rendered) {
|
2017-03-23 20:00:58 +01:00
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.eql('');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2017-08-02 11:38:19 +02:00
|
|
|
it('handles global undefined code injection', function (done) {
|
2017-03-23 20:00:58 +01:00
|
|
|
settingsCacheStub.withArgs('ghost_foot').returns(undefined);
|
|
|
|
|
2017-08-02 11:38:19 +02:00
|
|
|
helpers.ghost_foot({data: {}}).then(function (rendered) {
|
2017-03-23 20:00:58 +01:00
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.eql('');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2014-10-10 16:54:07 +02:00
|
|
|
});
|