|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +. .github/jobs/ci_settings.sh |
| 4 | + |
| 5 | +DIR="$PWD" |
| 6 | + |
| 7 | +if [ "$#" -ne "2" ]; then |
| 8 | + exit 2 |
| 9 | +fi |
| 10 | + |
| 11 | +TEST="$1" |
| 12 | +ROLE="$2" |
| 13 | + |
| 14 | +cd /opt/domjudge/domserver |
| 15 | + |
| 16 | +section_start "Setup pa11y" |
| 17 | +pa11y --version |
| 18 | +section_end |
| 19 | + |
| 20 | +section_start "Setup the test user" |
| 21 | +ADMINPASS=$(cat etc/initial_admin_password.secret) |
| 22 | +export COOKIEJAR |
| 23 | +COOKIEJAR=$(mktemp --tmpdir) |
| 24 | +export CURLOPTS="--fail -sq -m 30 -b $COOKIEJAR" |
| 25 | +if [ "$ROLE" = "public" ]; then |
| 26 | + ADMINPASS="failedlogin" |
| 27 | +fi |
| 28 | + |
| 29 | +# Make an initial request which will get us a session id, and grab the csrf token from it |
| 30 | +CSRFTOKEN=$(curl $CURLOPTS -c $COOKIEJAR "http://localhost/domjudge/login" 2>/dev/null | sed -n 's/.*_csrf_token.*value="\(.*\)".*/\1/p') |
| 31 | +# Make a second request with our session + csrf token to actually log in |
| 32 | +# shellcheck disable=SC2086 |
| 33 | +curl $CURLOPTS -c "$COOKIEJAR" -F "_csrf_token=$CSRFTOKEN" -F "_username=admin" -F "_password=$ADMINPASS" "http://localhost/domjudge/login" |
| 34 | + |
| 35 | +# Move back to the default directory |
| 36 | +cd "$DIR" |
| 37 | + |
| 38 | +cp "$COOKIEJAR" cookies.txt |
| 39 | +sed -i 's/#HttpOnly_//g' cookies.txt |
| 40 | +sed -i 's/\t0\t/\t1999999999\t/g' cookies.txt |
| 41 | +section_end |
| 42 | + |
| 43 | +# Could try different entrypoints |
| 44 | +FOUNDERR=0 |
| 45 | +URL=public |
| 46 | +mkdir "$URL" |
| 47 | +cd "$URL" |
| 48 | +cp "$DIR"/cookies.txt ./ |
| 49 | +section_start "Scrape the site with the rebuild admin user" |
| 50 | +set +e |
| 51 | +wget \ |
| 52 | + --reject-regex logout \ |
| 53 | + --recursive \ |
| 54 | + --no-clobber \ |
| 55 | + --page-requisites \ |
| 56 | + --html-extension \ |
| 57 | + --convert-links \ |
| 58 | + --restrict-file-names=windows \ |
| 59 | + --domains localhost \ |
| 60 | + --no-parent \ |
| 61 | + --load-cookies cookies.txt \ |
| 62 | + http://localhost/domjudge/"$URL" |
| 63 | +set -e |
| 64 | +RET=$? |
| 65 | +section_end |
| 66 | + |
| 67 | +section_start "Archive downloaded site" |
| 68 | +cp -r localhost $ARTIFACTS/ |
| 69 | +section_end |
| 70 | + |
| 71 | +section_start "Analyse failures" |
| 72 | +#https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html |
| 73 | +# Exit code 4 is network error which we can ignore |
| 74 | +# Exit code 8 can also be because of HTTP404 or 400 |
| 75 | +if [ $RET -ne 4 ] && [ $RET -ne 0 ] && [ $RET -ne 8 ]; then |
| 76 | + exit $RET |
| 77 | +fi |
| 78 | + |
| 79 | +EXPECTED_HTTP_CODES="200\|302\|400\|404" |
| 80 | +if [ "$ROLE" = "public" ]; then |
| 81 | + # It's expected to encounter a 401 for the login page as we supply the wrong password |
| 82 | + EXPECTED_HTTP_CODES="$EXPECTED_HTTP_CODES\|401" |
| 83 | +fi |
| 84 | +set +e |
| 85 | +NUM_ERRORS=$(grep -v "HTTP/1.1\" \($EXPECTED_HTTP_CODES\)" /var/log/nginx/domjudge.log | grep -v "robots.txt" -c; if [ "$?" -gt 1 ]; then exit 127; fi) |
| 86 | +set -e |
| 87 | +echo "$NUM_ERRORS" |
| 88 | +
|
| 89 | +if [ "$NUM_ERRORS" -ne 0 ]; then |
| 90 | + echo "Entered the if" |
| 91 | + grep -v "HTTP/1.1\" \($EXPECTED_HTTP_CODES\)" /var/log/nginx/domjudge.log | grep -v "robots.txt" |
| 92 | + exit 1 |
| 93 | +fi |
| 94 | +section_end |
| 95 | +
|
| 96 | +if [ "$TEST" = "w3cval" ]; then |
| 97 | + section_start "Remove files from upstream with problems" |
| 98 | + rm -rf localhost/domjudge/doc |
| 99 | + rm -rf localhost/domjudge/css/fontawesome-all.min.css* |
| 100 | + rm -rf localhost/domjudge/bundles/nelmioapidoc* |
| 101 | + rm -f localhost/domjudge/css/bootstrap.min.css* |
| 102 | + rm -f localhost/domjudge/css/select2-bootstrap*.css* |
| 103 | + rm -f localhost/domjudge/css/dataTables*.css* |
| 104 | + rm -f localhost/domjudge/jury/config/check/phpinfo* |
| 105 | + section_end |
| 106 | +
|
| 107 | + section_start "Install testsuite" |
| 108 | + cd "$DIR" |
| 109 | + wget https://github.com/validator/validator/releases/latest/download/vnu.linux.zip |
| 110 | + unzip -q vnu.linux.zip |
| 111 | + section_end |
| 112 | +
|
| 113 | + FLTR='--filterpattern .*autocomplete.*|.*style.*|.*role=tab.*|.*descendant.*|.*Stray.*|.*attribute.*|.*Forbidden.*|.*stream.*' |
| 114 | + for typ in html css svg |
| 115 | + do |
| 116 | + section_start "Analyse with $typ" |
| 117 | + # shellcheck disable=SC2086 |
| 118 | + "$DIR"/vnu-runtime-image/bin/vnu --errors-only --exit-zero-always --skip-non-$typ --format json $FLTR "$URL" 2> result.json |
| 119 | + # shellcheck disable=SC2086 |
| 120 | + NEWFOUNDERRORS=$("$DIR"/vnu-runtime-image/bin/vnu --errors-only --exit-zero-always --skip-non-$typ --format gnu $FLTR "$URL" 2>&1 | wc -l) |
| 121 | + FOUNDERR=$((NEWFOUNDERRORS+FOUNDERR)) |
| 122 | + python3 -m "json.tool" < result.json > "$ARTIFACTS/w3c$typ$URL.json" |
| 123 | + trace_off; python3 gitlab/jsontogitlab.py "$ARTIFACTS/w3c$typ$URL.json"; trace_on |
| 124 | + section_end |
| 125 | + done |
| 126 | +else |
| 127 | + section_start "Remove files from upstream with problems" |
| 128 | + rm -rf localhost/domjudge/{doc,api} |
| 129 | + section_end |
| 130 | +
|
| 131 | + if [ "$TEST" == "axe" ]; then |
| 132 | + STAN="-e $TEST" |
| 133 | + FLTR="" |
| 134 | + else |
| 135 | + STAN="-s $TEST" |
| 136 | + FLTR="-E '#DataTables_Table_0 > tbody > tr > td > a','#menuDefault > a','#filter-card > div > div > div > span > span:nth-child(1) > span > ul > li > input',.problem-badge" |
| 137 | + fi |
| 138 | + chown -R domjudge:domjudge "$DIR" |
| 139 | + cd "$DIR" |
| 140 | + ACCEPTEDERR=5 |
| 141 | + # shellcheck disable=SC2044,SC2035 |
| 142 | + for file in $(find $URL -name "*.html") |
| 143 | + do |
| 144 | + section_start "$file" |
| 145 | + su domjudge -c "pa11y --config .github/jobs/pa11y_config.json $STAN -r json -T $ACCEPTEDERR $FLTR $file" | python3 -m json.tool |
| 146 | + ERR=$(su domjudge -c "pa11y --config .github/jobs/pa11y_config.json $STAN -r csv -T $ACCEPTEDERR $FLTR $file" | wc -l) |
| 147 | + FOUNDERR=$((ERR+FOUNDERR-1)) # Remove header row |
| 148 | + section_end |
| 149 | + done |
| 150 | +fi |
| 151 | +
|
| 152 | +echo "Found: " $FOUNDERR |
| 153 | +[ "$FOUNDERR" -eq 0 ] |
0 commit comments