From 40191adbb1a95eee4f5be29b7693103ea0c96049 Mon Sep 17 00:00:00 2001 From: xxc3nsoredxx Date: Mon, 10 May 2021 18:54:48 -0500 Subject: 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. --- test/.test.sh.swp | Bin 0 -> 16384 bytes test/test.sh | 22 ++++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 test/.test.sh.swp diff --git a/test/.test.sh.swp b/test/.test.sh.swp new file mode 100644 index 0000000..2a9895d Binary files /dev/null and b/test/.test.sh.swp 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 -- cgit v1.2.3