Diff options
Diffstat (limited to 'tests/extensions/harness.lua')
| -rw-r--r-- | tests/extensions/harness.lua | 33 |
1 file changed, 30 insertions, 3 deletions
diff --git a/tests/extensions/harness.lua b/tests/extensions/harness.lua index 86f09a6..1a669ff 100644 --- a/tests/extensions/harness.lua +++ b/tests/extensions/harness.lua @@ -263,15 +263,42 @@ local function fake_crypt(password, setting) return prefix .. password end --- The slices of luaossl and luaposix the auth checks reach. +-- The slices of luaossl and luaposix the auth checks reach. link refuses a +-- target that exists, as link(2) does, since that is how a script tells it +-- lost a race to make a file, and umask hands back the mask it replaces, so +-- a check can see the old one put back. function harness.stub_auth_modules() local rand_counter = 0 + local mask = 18 preload("posix.unistd", { crypt = fake_crypt, + link = function(from, to) + local existing = io.open(to, "rb") + if existing then + existing:close() + return nil, to .. ": File exists", 17 + end + local source = assert(io.open(from, "rb")) + local text = source:read("*a") + source:close() + local target = assert(io.open(to, "wb")) + target:write(text) + target:close() + return 0 + end, + unlink = function(path) + local removed, err = os.remove(path) + if not removed then + return nil, err, 2 + end + return 0 + end, }) preload("posix.sys.stat", { - umask = function() - return 18 + umask = function(new) + local old = mask + mask = new + return old end, }) preload("openssl.rand", { |
