fix: log error for illegal property access only once per property

This commit is contained in:
Nils Knappmeier
2020-01-12 13:06:56 +01:00
parent 0d5c807017
commit 3c1e252169
3 changed files with 50 additions and 7 deletions
+21
View File
@@ -190,6 +190,10 @@ describe('security issues', function() {
return 'returnValue';
};
beforeEach(function() {
handlebarsEnv.resetLoggedPropertyAccesses();
});
afterEach(function() {
sinon.restore();
});
@@ -214,6 +218,23 @@ describe('security issues', function() {
expect(spy.args[0][0]).to.match(/Handlebars: Access has been denied/);
});
it('should only log the warning once', function() {
var spy = sinon.spy(console, 'error');
expectTemplate('{{aMethod}}')
.withInput(new TestClass())
.withCompileOptions(compileOptions)
.toCompileTo('');
expectTemplate('{{aMethod}}')
.withInput(new TestClass())
.withCompileOptions(compileOptions)
.toCompileTo('');
expect(spy.calledOnce).to.be.true();
expect(spy.args[0][0]).to.match(/Handlebars: Access has been denied/);
});
it('can be allowed, which disables the warning', function() {
var spy = sinon.spy(console, 'error');