Be more flexible about paths to call the test suite
This commit is contained in:
parent
71804c4b3a
commit
9b18c0e162
28
test_cli.sh
28
test_cli.sh
|
@ -8,7 +8,33 @@ ORIGDIR="$(pwd)"
|
||||||
cd "$SCRIPTDIR"
|
cd "$SCRIPTDIR"
|
||||||
|
|
||||||
export FORGEHOOK="$(pwd)/tests/mock-forgehook.sh"
|
export FORGEHOOK="$(pwd)/tests/mock-forgehook.sh"
|
||||||
export WHCK="$ORIGDIR"/"$1"
|
|
||||||
|
source tests/helper.bash
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
output="$(findBin "$SCRIPTDIR"/../cli)"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
if [[ "$(echo "$output" | wc -l)" == "1" ]]; then
|
||||||
|
FIND_WHCK="$output"
|
||||||
|
else
|
||||||
|
# Some warnings, print but use result from last line
|
||||||
|
echo "$output" | head -n -1
|
||||||
|
FIND_WHCK="$(echo "$output" | tail -n 1)"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "ERROR: Could not find webhook validation program. Output:"
|
||||||
|
echo "$output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# cli script needs to be executed to get absolute path to the program
|
||||||
|
export WHCK="$("$FIND_WHCK")"
|
||||||
|
else
|
||||||
|
if WHCK="$(realpath "$ORIGDIR"/"$1")"; then
|
||||||
|
export WHCK
|
||||||
|
else
|
||||||
|
export WHCK="$(realpath "$1")"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
bats tests/cli/*.bats
|
bats tests/cli/*.bats
|
||||||
|
|
||||||
|
|
23
test_web.sh
23
test_web.sh
|
@ -2,28 +2,7 @@
|
||||||
|
|
||||||
SCRIPTDIR="$(dirname "$0")"
|
SCRIPTDIR="$(dirname "$0")"
|
||||||
|
|
||||||
# Used to find executable from several likely locations
|
source "$SCRIPTDIR"/tests/helper.bash
|
||||||
# Pass any number of arguments, returns the first one that's
|
|
||||||
# an executable file. If a file exists but is not executable,
|
|
||||||
# a warning is printed
|
|
||||||
# Output is in the form of "WARNING:\nresult" so if exit code is 0 you can safely fetch the last line to find the result
|
|
||||||
findBin () {
|
|
||||||
#if [ $# -eq 0 ]; exit; fi
|
|
||||||
while [ ! $# -eq 0 ]; do
|
|
||||||
# Resolve symlinks
|
|
||||||
f="$(readlink -m "$1")"
|
|
||||||
shift
|
|
||||||
if [ ! -f "$f" ]; then continue; fi
|
|
||||||
if [ ! -x "$f" ]; then
|
|
||||||
echo "WARNING: "$f" exists but is not executable" >&2
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
echo "$f"
|
|
||||||
return
|
|
||||||
done
|
|
||||||
# nothing found
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
output="$(findBin "$SCRIPTDIR"/server "$SCRIPTDIR"/../server)"
|
output="$(findBin "$SCRIPTDIR"/server "$SCRIPTDIR"/../server)"
|
||||||
|
|
|
@ -8,6 +8,7 @@ function setup {
|
||||||
|
|
||||||
# Which CLI validator to use?
|
# Which CLI validator to use?
|
||||||
if [ -z "$WHCK" ]; then WHCK="whck"; fi
|
if [ -z "$WHCK" ]; then WHCK="whck"; fi
|
||||||
|
echo "$WHCK"
|
||||||
|
|
||||||
export WHCK_DIR="$(mktemp -d)"
|
export WHCK_DIR="$(mktemp -d)"
|
||||||
}
|
}
|
||||||
|
@ -17,6 +18,7 @@ function teardown {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "correct signature works" {
|
@test "correct signature works" {
|
||||||
|
[ -x "$WHCK" ]
|
||||||
repo="https://tildegit.org/forge/hook.sh"
|
repo="https://tildegit.org/forge/hook.sh"
|
||||||
webhook="$(gen_webhook ../gitea.json "$repo")"
|
webhook="$(gen_webhook ../gitea.json "$repo")"
|
||||||
secret="$($FORGEHOOK secret $repo)"
|
secret="$($FORGEHOOK secret $repo)"
|
||||||
|
@ -30,6 +32,7 @@ function teardown {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "incorrect signature fails" {
|
@test "incorrect signature fails" {
|
||||||
|
[ -x "$WHCK" ]
|
||||||
repo="https://tildegit.org/forge/hook.sh"
|
repo="https://tildegit.org/forge/hook.sh"
|
||||||
webhook="$(gen_webhook ../gitea.json "$repo")"
|
webhook="$(gen_webhook ../gitea.json "$repo")"
|
||||||
secret="$($FORGEHOOK secret $repo)"
|
secret="$($FORGEHOOK secret $repo)"
|
||||||
|
|
|
@ -8,6 +8,7 @@ function setup {
|
||||||
|
|
||||||
# Which CLI validator to use?
|
# Which CLI validator to use?
|
||||||
if [ -z "$WHCK" ]; then WHCK="whck"; fi
|
if [ -z "$WHCK" ]; then WHCK="whck"; fi
|
||||||
|
echo "$WHCK"
|
||||||
|
|
||||||
export WHCK_DIR="$(mktemp -d)"
|
export WHCK_DIR="$(mktemp -d)"
|
||||||
}
|
}
|
||||||
|
@ -17,6 +18,7 @@ function teardown {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "correct signature works" {
|
@test "correct signature works" {
|
||||||
|
[ -x "$WHCK" ]
|
||||||
repo="https://tildegit.org/forge/hook.sh"
|
repo="https://tildegit.org/forge/hook.sh"
|
||||||
webhook="$(gen_webhook ../github.json "$repo")"
|
webhook="$(gen_webhook ../github.json "$repo")"
|
||||||
secret="$($FORGEHOOK secret $repo)"
|
secret="$($FORGEHOOK secret $repo)"
|
||||||
|
@ -30,6 +32,7 @@ function teardown {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "incorrect signature fails" {
|
@test "incorrect signature fails" {
|
||||||
|
[ -x "$WHCK" ]
|
||||||
repo="https://tildegit.org/forge/hook.sh"
|
repo="https://tildegit.org/forge/hook.sh"
|
||||||
webhook="$(gen_webhook ../gitea.json "$repo")"
|
webhook="$(gen_webhook ../gitea.json "$repo")"
|
||||||
secret="$($FORGEHOOK secret $repo)"
|
secret="$($FORGEHOOK secret $repo)"
|
||||||
|
|
|
@ -8,6 +8,7 @@ function setup {
|
||||||
|
|
||||||
# Which CLI validator to use?
|
# Which CLI validator to use?
|
||||||
if [ -z "$WHCK" ]; then WHCK="whck"; fi
|
if [ -z "$WHCK" ]; then WHCK="whck"; fi
|
||||||
|
echo "$WHCK"
|
||||||
|
|
||||||
export WHCK_DIR="$(mktemp -d)"
|
export WHCK_DIR="$(mktemp -d)"
|
||||||
}
|
}
|
||||||
|
@ -17,6 +18,7 @@ function teardown {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "correct signature works" {
|
@test "correct signature works" {
|
||||||
|
[ -x "$WHCK" ]
|
||||||
repo="https://tildegit.org/forge/hook.sh"
|
repo="https://tildegit.org/forge/hook.sh"
|
||||||
webhook="$(gen_webhook ../gitea.json "$repo")"
|
webhook="$(gen_webhook ../gitea.json "$repo")"
|
||||||
secret="$($FORGEHOOK secret $repo)"
|
secret="$($FORGEHOOK secret $repo)"
|
||||||
|
@ -29,6 +31,7 @@ function teardown {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "incorrect signature fails" {
|
@test "incorrect signature fails" {
|
||||||
|
[ -x "$WHCK" ]
|
||||||
repo="https://tildegit.org/forge/hook.sh"
|
repo="https://tildegit.org/forge/hook.sh"
|
||||||
webhook="$(gen_webhook ../gitea.json "$repo")"
|
webhook="$(gen_webhook ../gitea.json "$repo")"
|
||||||
secret="$($FORGEHOOK secret $repo)"
|
secret="$($FORGEHOOK secret $repo)"
|
||||||
|
|
|
@ -68,3 +68,26 @@ function hash_hmac {
|
||||||
# Don't print (stdin)= ...
|
# Don't print (stdin)= ...
|
||||||
echo -n "$data" | openssl dgst "-$digest" -hmac "$key" | awk '{print $2}'
|
echo -n "$data" | openssl dgst "-$digest" -hmac "$key" | awk '{print $2}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Used to find executable from several likely locations
|
||||||
|
# Pass any number of arguments, returns the first one that's
|
||||||
|
# an executable file. If a file exists but is not executable,
|
||||||
|
# a warning is printed
|
||||||
|
# Output is in the form of "WARNING:\nresult" so if exit code is 0 you can safely fetch the last line to find the result
|
||||||
|
findBin () {
|
||||||
|
#if [ $# -eq 0 ]; exit; fi
|
||||||
|
while [ ! $# -eq 0 ]; do
|
||||||
|
# Resolve symlinks
|
||||||
|
f="$(readlink -m "$1")"
|
||||||
|
shift
|
||||||
|
if [ ! -f "$f" ]; then continue; fi
|
||||||
|
if [ ! -x "$f" ]; then
|
||||||
|
echo "WARNING: "$f" exists but is not executable" >&2
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
echo "$f"
|
||||||
|
return
|
||||||
|
done
|
||||||
|
# nothing found
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue