local granted = arg[1]
local function stable(message)
message = string.match(tostring(message), "^[^\n]*") or tostring(message)
local parts, from = {}, 1
while true do
local start, stop = string.find(message, granted, from, true)
if not start then
break
end
parts[#parts + 1] = string.sub(message, from, start - 1)
parts[#parts + 1] = "<granted>"
from = stop + 1
end
parts[#parts + 1] = string.sub(message, from)
return table.concat(parts)
end
local function refused(label, body)
local ok, err = pcall(body)
assert(not ok, label .. " was permitted, and should not have been")
print(label .. "\n " .. stable(err))
end
local installed = {
"json", "path", "fs", "env", "proc", "regex",
"hash", "time", "glob", "stdio", "hook", "ext",
}
for _, name in ipairs(installed) do
assert(type(airsstack[name]) == "table", name .. " is missing from the root table")
end
print("modules installed: " .. table.concat(installed, ", "))
print("path.join needs nothing: " .. airsstack.path.join("a", "b", "c.txt"))
print("json.encode needs nothing: " .. airsstack.json.encode({ ok = true }))
print("granted read works: " .. #airsstack.fs.read(airsstack.path.join(granted, "visible.txt")) .. " bytes")
print("")
refused("fs.read, outside the granted root", function()
airsstack.fs.read("/")
end)
refused("fs.write, into the read-only root", function()
airsstack.fs.write(airsstack.path.join(granted, "new.txt"), "x")
end)
refused("hash.hash_file, outside the granted root", function()
airsstack.hash.hash_file("/")
end)
refused("glob.walk, outside the granted root", function()
airsstack.glob.walk("/", "*")
end)
refused("env.get, a name that is not on the allowlist", function()
airsstack.env.get("AIRSL_EXAMPLE_SECRET")
end)
refused("proc.run, an executable that is not on the allowlist", function()
airsstack.proc.run({ "curl", "https://example.com" })
end)
print("")
print("every refusal named the grant it was measured against")