# HG changeset patch # User Chris Cannam # Date 1504104678 -3600 # Node ID 2496b955f638073992adf042558deb38b1afc93d # Parent 89d3095ddc70ff3e0d6429edd4da97fed0bb6234 Fix auth handler for non-public repos, + add to smoke test diff -r 89d3095ddc70 -r 2496b955f638 deploy/test/smoketest.sh --- a/deploy/test/smoketest.sh Wed Aug 30 14:58:25 2017 +0100 +++ b/deploy/test/smoketest.sh Wed Aug 30 15:51:18 2017 +0100 @@ -30,6 +30,9 @@ # A project known to exist, be public, and have a bibliography project_with_biblio=sonic-visualiser +# A project known not to exist +nonexistent_project=nonexistent-project + tried=0 succeeded=0 @@ -41,6 +44,7 @@ cd "$mydir/output" path="$1" description="$2" + expected="$3" url="$uribase$path" echo echo "Trying \"$description\" [$url]..." @@ -49,19 +53,37 @@ echo "+++ Succeeded" succeeded=$(($succeeded + 1)) else - echo "--- FAILED" + returned="$?" + if [ "$returned" = "$expected" ]; then + echo "+++ Succeeded [returned expected code $expected]" + succeeded=$(($succeeded + 1)) + else + echo "--- FAILED with return code $returned" + fi fi tried=$(($tried + 1)) cd "$origin" } -try "/" "Front page" -try "/projects/$project_with_repo" "Project page" -try "/projects/$project_with_biblio" "Project page with bibliography" -try "/projects/$project_with_repo/repository" "Repository page" -try "/hg/$project_with_repo" "Mercurial repo" -try "/projects/$project_with_docs/embedded" "Project documentation page (from docgen cron script)" -try "/git/$project_with_repo/info/refs" "Git repo mirror" +assert() { + try "$1" "$2" 0 +} + +fail() { + try "$1" "$2" "$3" +} + +assert "/" "Front page" +assert "/projects/$project_with_repo" "Project page" +assert "/projects/$project_with_biblio" "Project page with bibliography" +assert "/projects/$project_with_repo/repository" "Repository page" +assert "/hg/$project_with_repo" "Mercurial repo" +assert "/projects/$project_with_docs/embedded" "Project documentation page (from docgen cron script)" +assert "/git/$project_with_repo/info/refs" "Git repo mirror" + +# we expect this to return an http auth requirement, not a 404 - the +# value 6 is wget's return code for auth failure +fail "/hg/$nonexistent_project" "Mercurial repo" 6 echo echo "Passed $succeeded of $tried" diff -r 89d3095ddc70 -r 2496b955f638 extra/soundsoftware/SoundSoftware.pm --- a/extra/soundsoftware/SoundSoftware.pm Wed Aug 30 14:58:25 2017 +0100 +++ b/extra/soundsoftware/SoundSoftware.pm Wed Aug 30 15:51:18 2017 +0100 @@ -177,11 +177,6 @@ return FORBIDDEN; } - if (!defined $r->user or $r->user eq '') { - $r->user('*anon*'); # Apache 2.4+ requires auth module to set - # user even if no auth was needed - } - my $method = $r->method; print STDERR "SoundSoftware.pm:$$: Method: $method, uri " . $r->uri . ", location " . $r->location . "\n"; @@ -254,6 +249,16 @@ # case we can decide for certain to accept in this function print STDERR "SoundSoftware.pm:$$: Method is read-only, no restriction here\n"; $r->set_handlers(PerlAuthenHandler => [\&OK]); + if (!defined $r->user or $r->user eq '') { + # Apache 2.4+ requires auth module to set user if no + # auth was needed. Note that this actually tells + # apache that user has been identified, so authen + # handler will never be called (i.e. we must not do + # this unless we are actually approving the auth-free + # access). If we don't do this, we get a 500 error + # here after the set_handlers call above + $r->user('*anon*'); + } return OK; }