changeset 1612:2496b955f638 deploy

Fix auth handler for non-public repos, + add to smoke test
author Chris Cannam
date Wed, 30 Aug 2017 15:51:18 +0100
parents 89d3095ddc70
children 90bed4e10cc8
files deploy/test/smoketest.sh extra/soundsoftware/SoundSoftware.pm
diffstat 2 files changed, 40 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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"
--- 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;
 	}