summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxxc3nsoredxx <xxc3ncoredxx@gmail.com>2021-05-10 18:54:48 -0500
committerRasmus Thomsen <oss@cogitri.dev>2021-06-01 14:25:32 +0200
commit40191adbb1a95eee4f5be29b7693103ea0c96049 (patch)
tree0c9da75fc4098294d40a6c1e261a7a44aefe53e4
parent5c2ccafc8c5ded392292aabe2bf31eb4f72a63b5 (diff)
downloadwgetpaste-40191adbb1a95eee4f5be29b7693103ea0c96049.tar.gz
Test for expected vs unexpected 401
AUTH_SKIPS is a list of services for which an HTTP 401 is an expected response if an auth token isn't given. 401 for a service outside of the list means a changed/broken API. Invert the `if ! diff then fail else success` for readability.
-rw-r--r--test/.test.sh.swpbin0 -> 16384 bytes
-rwxr-xr-xtest/test.sh22
2 files changed, 16 insertions, 6 deletions
diff --git a/test/.test.sh.swp b/test/.test.sh.swp
new file mode 100644
index 0000000..2a9895d
--- /dev/null
+++ b/test/.test.sh.swp
Binary files differ
diff --git a/test/test.sh b/test/test.sh
index 5aacdd4..536bc05 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -12,6 +12,8 @@ DL_DIR="$(mktemp -q -d /tmp/wgetpaste_test.XXXXX)"
# codepad: timing out
HARD_SKIPS=('codepad')
HARD_SKIP_COUNT=0
+# Services expected to require an authorization token
+AUTH_SKIPS=('gists' 'snippets')
AUTH_SKIP_COUNT=0
FAIL_SKIP_COUNT=0
DL_COUNT=0
@@ -47,9 +49,17 @@ for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do
# Skip failed posts (eg, not authorized for GitHub/GitLab, service error)
if [ "$STATUS" -ne 0 ]; then
if (grep -iq "HTTP.*401.*Unauthorized" "$ERROR_LOG"); then
- echo "SKIPPING, needs authorization..."
- AUTH_SKIP_COUNT=$((AUTH_SKIP_COUNT + 1))
- rm "$ERROR_LOG"
+ # Check if a 401 is expected behavior. If it isn't, mark as fail
+ for as in "${AUTH_SKIPS[@]}"; do
+ if [ "$serv" == "$as" ]; then
+ echo "SKIPPING, needs authorization..."
+ AUTH_SKIP_COUNT=$((AUTH_SKIP_COUNT + 1))
+ rm "$ERROR_LOG"
+ continue 2
+ fi
+ done
+ echo "UNEXPECTED 401, skipping..."
+ FAIL_SKIP_COUNT=$((FAIL_SKIP_COUNT + 1))
else
echo "SKIPPING, failed to post..."
FAIL_SKIP_COUNT=$((FAIL_SKIP_COUNT + 1))
@@ -81,11 +91,11 @@ fi
for dl_file in "$DL_DIR"/*.txt; do
echo -n "Testing file $dl_file: "
# Ignore missing trailing newline in downloaded file
- if ! (diff -q -Z "$TEST_FILE" "$dl_file" &>/dev/null); then
+ if (diff -q -Z "$TEST_FILE" "$dl_file" &>/dev/null); then
+ echo "SUCCESS!"
+ else
echo "FAILED!"
DL_MISMATCH=$((DL_MISMATCH + 1))
- else
- echo "SUCCESS!"
fi
done