summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2017-07-31 14:39:54 -0400
committerDaniel Silverstone <dsilvers@digital-scurf.org>2017-07-31 16:58:58 -0400
commitab55ba5174097b25fe7227d1aa4e6559cc40b978 (patch)
treee7ea6061d364204760cd612b0ea4c7deb3a822ec /testing
parent5a3619ec799578f4aaf57e164a27648bf86ae077 (diff)
downloadgitano-ab55ba5174097b25fe7227d1aa4e6559cc40b978.tar.gz
Test suite properly runs gitano-command.cgi
In order to make this work, I had to rework password handling in the test suite, and also redo the http unwrapper to use wget instead of executing the cgi directly. All yarn IMPLEMENTs which use $GTT runcommand and don't pass the stdin, *MUST* explicitly use </dev/null to prevent hangs in http mode.
Diffstat (limited to 'testing')
-rw-r--r--testing/gitano-test-tool.in67
-rwxr-xr-xtesting/http-unwrap38
-rw-r--r--testing/library.yarn32
3 files changed, 82 insertions, 55 deletions
diff --git a/testing/gitano-test-tool.in b/testing/gitano-test-tool.in
index 78a6c0e..ae2ee4d 100644
--- a/testing/gitano-test-tool.in
+++ b/testing/gitano-test-tool.in
@@ -163,6 +163,19 @@ local function load_auth(fname)
return ret
end
+local function set_stored_password(user, pass)
+ local fh = assert(io.open(user_home(user) .. "/passwd", "w"))
+ fh:write(pass .. "\n")
+ fh:close()
+end
+
+local function load_stored_password(user)
+ local fh = assert(io.open(user_home(user) .. "/passwd", "r"))
+ local pass = fh:read("*l")
+ fh:close()
+ return pass
+end
+
local function generate_exturl(user, key, repo)
local authkeys = load_auth(ssh_key_file("testinstance", "authorized_keys"))
local pubkey = (sio.open(ssh_key_file(user, key) .. ".pub", "r")):read("*l")
@@ -179,7 +192,7 @@ local function generate_exturl(user, key, repo)
esc(authline.user), esc(authline.keyset))
end
-local function generate_httpurl(user, key, repo)
+local function generate_httpurl(user, key, path)
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])
@@ -189,7 +202,7 @@ local function generate_httpurl(user, key, repo)
local port = tonumber(fh:read())
fh:close()
- return ("http://%s:%s@localhost:%d/git/%s"):format(authline.user, authline.user, port, repo)
+ return ("http://%s:%s@localhost:%d/%s"):format(authline.user, load_stored_password(user), port, path)
end
function cmd_setgitconfig(username, key, value)
@@ -218,6 +231,15 @@ function cmd_createunixuser(username)
cmd_setgitconfig(username, "user.name", username)
cmd_setgitconfig(username, "user.email", username.."@example.com")
cmd_setgitconfig(username, "push.default", "simple")
+ set_stored_password(username, username)
+end
+
+function cmd_getpasswd(username)
+ print(load_stored_password(username))
+end
+
+function cmd_setpasswd(username, passwd)
+ set_stored_password(username, passwd)
end
function cmd_createsshkey(username, keyname, optionaltype)
@@ -283,7 +305,11 @@ function cmd_setupstandard(owning_user, master_key, bypass_key)
fh:write(('server.port = %d\n'):format(port))
fh:write('server.modules = ( "mod_auth", "mod_alias", "mod_cgi", "mod_setenv" )\n')
fh:write(([[
-$HTTP["url"] =~ ".*/gitano-command.cgi$" {
+$HTTP["url"] =~ "/gitano-command.cgi$" {
+ alias.url += ( "/gitano-command.cgi" => %q )
+
+ cgi.assign = ("" => "")
+
setenv.add-environment = (
"HOME" => %q,
"LUA_INIT" => %q,
@@ -325,7 +351,8 @@ $HTTP["url"] =~ "^/git/.*$" {
auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = %q
}
-]]):format(user_home(owning_user), lua_init, repo_path, htpasswd,
+]]):format(gitano.config.lib_bin_path() .. "/gitano-command.cgi",
+ user_home(owning_user), lua_init, repo_path, htpasswd,
gitano.config.lib_bin_path() .. "/gitano-smart-http.cgi", repo_path,
user_home(owning_user), lua_init, repo_path, htpasswd))
@@ -366,7 +393,7 @@ end
function cmd_clone(user, key, repo, localname, ...)
local url
if os.getenv("GTT_PROTO") == "http" then
- url = generate_httpurl(user, key, repo)
+ url = generate_httpurl(user, key, "git/" .. repo)
end
if os.getenv("GTT_PROTO") == "ssh" then
url = generate_exturl(user, key, repo)
@@ -380,7 +407,7 @@ end
function cmd_push(user, key, localname, repo, ...)
local url
if os.getenv("GTT_PROTO") == "http" then
- url = generate_httpurl(user, key, repo)
+ url = generate_httpurl(user, key, "git/" .. repo)
end
if os.getenv("GTT_PROTO") == "ssh" then
url = generate_exturl(user, key, repo)
@@ -433,30 +460,22 @@ function cmd_runcommand_ssh(user, key, ...)
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 httpurl = generate_httpurl(user, key, "gitano-command.cgi")
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, " ", "+")
+ 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, "+")
+ httpurl = httpurl .. "?cmd=" .. table.concat(elems, "+")
+ local cmdline = {
+ "testing/http-unwrap",
+ httpurl
+ }
run_program(cmdline)
end
diff --git a/testing/http-unwrap b/testing/http-unwrap
index 5c05544..22392d2 100755
--- a/testing/http-unwrap
+++ b/testing/http-unwrap
@@ -27,18 +27,26 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
-"$@" | (
- OIFS="$IFS";
- IFS="
-";
- read STATUSLINE;
- read BLANKLINE;
- IFS="$OIFS";
- OKLINE=${STATUSLINE##Status: 200}
- if test x"$OKLINE" = x"$STATUSLINE"; then
- cat >&2
- exit 1
- else
- cat
- fi
-)
+INFILE=$(mktemp -p "$DATADIR")
+OUTFILE=$(mktemp -p "$DATADIR")
+cleanup () {
+ rm -f "$OUTFILE"
+ rm -f "$INFILE"
+}
+trap cleanup 0
+
+cat > "$INFILE"
+
+if test $(stat -c %s "$INFILE") != "0"; then
+ wget -q -O- --content-on-error --auth-no-challenge --post-file="$INFILE" "$@" > "$OUTFILE" 2>&1
+else
+ wget -q -O- --content-on-error --auth-no-challenge "$@" > "$OUTFILE" 2>&1
+fi
+RES="$?"
+if test "$RES" = "0"; then
+ cat "$OUTFILE"
+ exit 0
+else
+ cat >&2 "$OUTFILE"
+ exit 1
+fi
diff --git a/testing/library.yarn b/testing/library.yarn
index a370bfe..88f6142 100644
--- a/testing/library.yarn
+++ b/testing/library.yarn
@@ -23,10 +23,10 @@ General instance management
$GTT createsshkey testinstance bypasskey
$GTT setupstandard testinstance adminkey bypasskey
if [ "$GTT_PROTO" = http ]; then
- printf "%s" admin | GTT_PROTO=ssh $GTT runcommand \
+ printf "%s" $($GTT getpasswd testinstance) | GTT_PROTO=ssh $GTT runcommand \
testinstance adminkey as admin passwd \
>> "$DATADIR/stdout" 2>> "$DATADIR/stderr"
- printf "%s" gitano-bypass | GTT_PROTO=ssh $GTT runcommand \
+ printf "%s" $($GTT getpasswd testinstance) | GTT_PROTO=ssh $GTT runcommand \
testinstance bypasskey as gitano-bypass passwd \
>> "$DATADIR/stdout" 2>> "$DATADIR/stderr"
fi
@@ -57,12 +57,12 @@ of the user inside Gitano.
$GTT createunixuser "$MATCH_3"
$GTT createsshkey "$MATCH_3" "$MATCH_4"
$GTT runcommand "$MATCH_1" "$MATCH_2" \
- user add "$MATCH_3" "$MATCH_3"@testinstance "$MATCH_3's real name" > "$DATADIR/stdout" 2> "$DATADIR/stderr"
+ user add "$MATCH_3" "$MATCH_3"@testinstance "$MATCH_3's real name" < "/dev/null" > "$DATADIR/stdout" 2> "$DATADIR/stderr"
$GTT runcommand "$MATCH_1" "$MATCH_2" \
as "$MATCH_3" sshkey add default < \
"$($GTT pubkeyfilename "$MATCH_3" "$MATCH_4")" >> "$DATADIR/stdout" 2>> "$DATADIR/stderr"
if [ "$GTT_PROTO" = http ]; then
- printf "%s" "$MATCH_3" | GTT_PROTO=ssh $GTT runcommand \
+ printf "%s" $($GTT getpasswd "$MATCH_3") | GTT_PROTO=ssh $GTT runcommand \
"$MATCH_1" "$MATCH_2" as "$MATCH_3" passwd \
>> "$DATADIR/stdout" 2>> "$DATADIR/stderr"
fi
@@ -84,7 +84,7 @@ Repository access
IMPLEMENTS WHEN ([a-z][a-z0-9]*),? using ([a-z][a-z0-9]*),? (expecting failure,? )?destroys ([^ ]+) using the (.+) token
if $GTT runcommand "$MATCH_1" "$MATCH_2" \
destroy "$MATCH_4" "$(cat "$DATADIR/saved-tokens/$MATCH_5")" \
- >"$DATADIR/stdout" 2>"$DATADIR/stderr"; then
+ < /dev/null >"$DATADIR/stdout" 2>"$DATADIR/stderr"; then
test "$MATCH_3" = ""
fi
@@ -146,19 +146,19 @@ Admin repo manipulation
IMPLEMENTS WHEN ([a-z][a-z0-9]*),? using ([a-z][a-z0-9]*),? adds user ([a-z][a-z0-9]*),? using ([a-z][a-z0-9]*) ([a-z][a-z0-9]*)
$GTT runcommand "$MATCH_1" "$MATCH_2" \
- user add "$MATCH_3" "$MATCH_3"@testinstance "$MATCH_3's real name" > "$DATADIR/stdout" 2> "$DATADIR/stderr"
+ user add "$MATCH_3" "$MATCH_3"@testinstance "$MATCH_3's real name" < "/dev/null" > "$DATADIR/stdout" 2> "$DATADIR/stderr"
$GTT runcommand "$MATCH_1" "$MATCH_2" \
as "$MATCH_3" sshkey add default < \
"$($GTT pubkeyfilename "$MATCH_4" "$MATCH_5")" >> "$DATADIR/stdout" 2>> "$DATADIR/stderr"
if [ "$GTT_PROTO" = http ]; then
- printf "%s" "$MATCH_3" | GTT_PROTO=ssh $GTT runcommand \
+ printf "%s" $($GTT getpasswd "$MATCH_4") | GTT_PROTO=ssh $GTT runcommand \
"$MATCH_1" "$MATCH_2" as "$MATCH_3" passwd \
>> "$DATADIR/stdout" 2>> "$DATADIR/stderr"
fi
IMPLEMENTS WHEN ([a-z][a-z0-9]*),? using ([a-z][a-z0-9]*),? deletes user ([a-z][a-z0-9]*)
- TOKEN="$($GTT runcommand "$MATCH_1" "$MATCH_2" user del "$MATCH_3" 2>&1 | $GTT findtoken)"
- $GTT runcommand "$MATCH_1" "$MATCH_2" user del "$MATCH_3" $TOKEN
+ TOKEN="$($GTT runcommand "$MATCH_1" "$MATCH_2" user del "$MATCH_3" 2>&1 < /dev/null | $GTT findtoken)"
+ $GTT runcommand "$MATCH_1" "$MATCH_2" user del "$MATCH_3" $TOKEN </dev/null >"$DATADIR/stdout" 2>"$DATADIR/stderr"
IMPLEMENTS GIVEN ([a-z][a-z0-9]*),? using ([a-z][a-z0-9]*),? has patched gitano-admin with (the reverse of )?([^ ]+)
$GTT clone "$MATCH_1" "$MATCH_2" gitano-admin.git tmp-adminpatch \
@@ -205,20 +205,20 @@ Specific commands
-----------------
IMPLEMENTS GIVEN ([a-z][a-z0-9]*) ([a-z][a-z0-9]*) has copied ([^ ]+) to ([^ ]+)
- $GTT runcommand "$MATCH_1" "$MATCH_2" copy "$MATCH_3" "$MATCH_4"
+ $GTT runcommand "$MATCH_1" "$MATCH_2" copy "$MATCH_3" "$MATCH_4" </dev/null >"$DATADIR/stdout" 2>"$DATADIR/stderr"
IMPLEMENTS GIVEN ([a-z][a-z0-9]*) ([a-z][a-z0-9]*) has set the owner of ([^ ]+) to ([a-z][a-z0-9]*)
- $GTT runcommand "$MATCH_1" "$MATCH_2" config "$MATCH_3" set project.owner "$MATCH_4"
+ $GTT runcommand "$MATCH_1" "$MATCH_2" config "$MATCH_3" set project.owner "$MATCH_4" </dev/null >"$DATADIR/stdout" 2>"$DATADIR/stderr"
IMPLEMENTS WHEN ([a-z][a-z0-9]*) ([a-z][a-z0-9]*) restores the latest deletion to (.+)
- $GTT runcommand "$MATCH_1" "$MATCH_2" graveyard list >"$DATADIR/stdout" 2>"$DATADIR/stderr"
+ $GTT runcommand "$MATCH_1" "$MATCH_2" graveyard list </dev/null >"$DATADIR/stdout" 2>"$DATADIR/stderr"
reponame="$(head -n1 "$DATADIR/stdout" | cut -d' ' -f2)"
- $GTT runcommand "$MATCH_1" "$MATCH_2" graveyard restore "$reponame" "$MATCH_3"
+ $GTT runcommand "$MATCH_1" "$MATCH_2" graveyard restore "$reponame" "$MATCH_3" </dev/null
IMPLEMENTS WHEN ([a-z][a-z0-9]*) ([a-z][a-z0-9]*) purges the latest deletion
- $GTT runcommand "$MATCH_1" "$MATCH_2" graveyard list >"$DATADIR/stdout" 2>"$DATADIR/stderr"
+ $GTT runcommand "$MATCH_1" "$MATCH_2" graveyard list </dev/null >"$DATADIR/stdout" 2>"$DATADIR/stderr"
reponame="$(head -n1 "$DATADIR/stderr" | cut -d' ' -f2)"
- $GTT runcommand "$MATCH_1" "$MATCH_2" graveyard purge "$reponame"
+ $GTT runcommand "$MATCH_1" "$MATCH_2" graveyard purge "$reponame" </dev/null
Generic utility methods
-----------------------
@@ -230,7 +230,7 @@ Generic utility methods
IMPLEMENTS WHEN ([a-z][a-z0-9]*) ([a-z][a-z0-9]*),? expecting failure,? runs ?(.*)
if ! test -e "$DATADIR/stdin"; then touch "$DATADIR/stdin"; fi
- if $GTT runcommand "$MATCH_1" "$MATCH_2" $MATCH_3 > "$DATADIR/stdout" 2> "$DATADIR/stderr"; then
+ if $GTT runcommand "$MATCH_1" "$MATCH_2" $MATCH_3 < "$DATADIR/stdin" > "$DATADIR/stdout" 2> "$DATADIR/stderr"; then
false
fi
rm -f "$DATADIR/stdin"