diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2016-12-03 11:34:23 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2016-12-03 11:34:23 +0000 |
commit | a4e81dd07d2805b5ef494459c44c911698245933 (patch) | |
tree | b7f9539605e5d715e3bc3c86633b396c3424fed6 /testing/gitano-test-tool.in | |
parent | 4a6c94ec810fec91b70d94730170adf4ee0b322b (diff) | |
download | gitano-a4e81dd07d2805b5ef494459c44c911698245933.tar.gz |
Initial support for HTTP commands (no clones yet)
Diffstat (limited to 'testing/gitano-test-tool.in')
-rw-r--r-- | testing/gitano-test-tool.in | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/testing/gitano-test-tool.in b/testing/gitano-test-tool.in index 7f3e86f..35fe410 100644 --- a/testing/gitano-test-tool.in +++ b/testing/gitano-test-tool.in @@ -46,8 +46,30 @@ local function unix_assert(ret, errno) end local function run_program(t) + local f = io.open(basedir .. "last-program", "w") + local function print (...) + f:write(...) + f:write("\n") + end + local function tprint (tbl, indent) + if not indent then indent = 0 end + for k, v in pairs(tbl) do + formatting = string.rep(" ", indent) .. k .. ": " + if type(v) == "table" then + print(formatting) + tprint(v, indent+1) + elseif type(v) == 'boolean' then + print(formatting .. tostring(v)) + else + print(formatting .. v) + end + end + end + tprint(t) local proc = sp.spawn_simple(t) local how, why = proc:wait() + f:write(("proc:wait() -> (%s, %s)\n"):format(tostring(how), tostring(why))) + f:close() if how == -1 then unix_assert(how, why) end @@ -57,11 +79,15 @@ local function run_program(t) end end -local function esc_quote_all(t) +local function esc_quote_all_(t) local tt = {} for i = 1, #t do tt[i] = ("%q"):format(t[i]) end + return tt +end +local function esc_quote_all(t) + local tt = esc_quote_all_(t) return table.concat(tt, " ") end @@ -207,7 +233,7 @@ function cmd_pubkeyfilename(user, key) print(ssh_key_file(user, key) .. ".pub") end -function cmd_runcommand(user, key, ...) +function cmd_runcommand_ssh(user, key, ...) local authkeys = load_auth(ssh_key_file("testinstance", "authorized_keys")) local pubkey = (sio.open(ssh_key_file(user, key) .. ".pub", "r")):read("*l") local authline = assert(authkeys[pubkey]) @@ -220,6 +246,42 @@ function cmd_runcommand(user, key, ...) run_program(cmdline) end +function cmd_runcommand_http(user, key, ...) + local authkeys = load_auth(ssh_key_file("testinstance", "authorized_keys")) + local pubkey = (sio.open(ssh_key_file(user, key) .. ".pub", "r")):read("*l") + local authline = assert(authkeys[pubkey]) + local cmdline = { + "testing/http-unwrap", + gitano.config.lib_bin_path() .. "/gitano-command.cgi", + env = { + HOME = user_home("testinstance"), + REMOTE_USER = authline.user, + REMOTE_ADDR = "10.0.0.1", + GITANO_ROOT = authline.repopath, + } + } + local elems = esc_quote_all_({...}) + local function escape (str) + str = string.gsub (str, "([^0-9a-zA-Z !'()*._~-])", -- locale independent + function (c) return string.format ("%%%02X", string.byte(c)) end) + str = string.gsub (str, " ", "+") + return str + end + for i = 1, #elems do + elems[i] = escape(elems[i]) + end + cmdline.env.QUERY_STRING = "cmd=" .. table.concat(elems, "+") + run_program(cmdline) +end + +function cmd_runcommand(...) + if os.getenv("GTT_PROTO") == "SSH" then + return cmd_runcommand_ssh(...) + else + return cmd_runcommand_http(...) + end +end + function cmd_rsh(user, key, dummy, ...) return cmd_runcommand(user, key, ...) end |