mirror of
https://github.com/TangentFoxy/lua-sandbox.git
synced 2025-07-28 02:52:22 +00:00
feat(sandbox) explicitly drop support of quotas on LuaJIT
The solution we use in PUC Rio Lua (with debug.sethook) simply does not work in LuaJIT. * We have added a `sandbox.quota_supported` field to signal this feature (or lack of thereof) * We explicitly return an error if `options.quota` is passed on a LuaJIT environment, in order to prevent LuaJIT users from believing that they are protected against infinite loops.
This commit is contained in:
committed by
Enrique García Cota
parent
50bfa4abca
commit
485a14697c
@@ -84,27 +84,31 @@ describe('sandbox.run', function()
|
||||
end)
|
||||
|
||||
|
||||
describe('when given infinite loops', function()
|
||||
if sandbox.quota_supported then
|
||||
describe('when given infinite loops', function()
|
||||
it('throws an error with infinite loops', function()
|
||||
assert.error(function() sandbox.run("while true do end") end)
|
||||
end)
|
||||
|
||||
it('throws an error with infinite loops', function()
|
||||
assert.error(function() sandbox.run("while true do end") end)
|
||||
it('restores string.rep even after a while true', function()
|
||||
assert.error(function() sandbox.run("while true do end") end)
|
||||
assert.equal('hellohello', string.rep('hello', 2))
|
||||
end)
|
||||
|
||||
it('accepts a quota param', function()
|
||||
assert.has_no.errors(function() sandbox.run("for i=1,100 do end") end)
|
||||
assert.error(function() sandbox.run("for i=1,100 do end", {quota = 20}) end)
|
||||
end)
|
||||
|
||||
it('does not use quotes if the quote param is false', function()
|
||||
assert.has_no.errors(function() sandbox.run("for i=1,1000000 do end", {quota = false}) end)
|
||||
end)
|
||||
end)
|
||||
|
||||
it('restores string.rep even after a while true', function()
|
||||
assert.error(function() sandbox.run("while true do end") end)
|
||||
assert.equal('hellohello', string.rep('hello', 2))
|
||||
else
|
||||
it('throws an error when trying to use the quota option in an unsupported environment (LuaJIT)', function()
|
||||
assert.error(function() sandbox.run("", {quota = 20}) end)
|
||||
end)
|
||||
|
||||
it('accepts a quota param', function()
|
||||
assert.has_no.errors(function() sandbox.run("for i=1,100 do end") end)
|
||||
assert.error(function() sandbox.run("for i=1,100 do end", {quota = 20}) end)
|
||||
end)
|
||||
|
||||
it('does not use quotes if the quote param is false', function()
|
||||
assert.has_no.errors(function() sandbox.run("for i=1,1000000 do end", {quota = false}) end)
|
||||
end)
|
||||
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
describe('when given an env option', function()
|
||||
|
Reference in New Issue
Block a user