add Lua sandbox with timer system (milestones 1-5 complete)
This commit is contained in:
33
sandbox-test/scripts/test_metatable_protected.lua
Normal file
33
sandbox-test/scripts/test_metatable_protected.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
-- Test that metatables are protected from manipulation
|
||||
|
||||
-- Test 1: String metatable should return protection value, not actual metatable
|
||||
local mt = getmetatable("")
|
||||
if mt ~= "string" then
|
||||
error("FAIL: string metatable should return 'string', got " .. tostring(mt))
|
||||
end
|
||||
|
||||
-- Test 2: Cannot add new globals
|
||||
local ok, err = pcall(function()
|
||||
_G.my_new_global = "test"
|
||||
end)
|
||||
if ok then
|
||||
error("FAIL: Should not be able to add new globals")
|
||||
end
|
||||
|
||||
-- Test 3: Cannot modify existing globals
|
||||
local ok2, err2 = pcall(function()
|
||||
_G.print = nil
|
||||
end)
|
||||
if ok2 then
|
||||
error("FAIL: Should not be able to modify print")
|
||||
end
|
||||
|
||||
-- Test 4: Cannot replace math table
|
||||
local ok3, err3 = pcall(function()
|
||||
_G.math = {}
|
||||
end)
|
||||
if ok3 then
|
||||
error("FAIL: Should not be able to replace math")
|
||||
end
|
||||
|
||||
print("PASS: Metatables protected")
|
||||
Reference in New Issue
Block a user