chiark / gitweb /
Testing: Fix up $url management
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 27 Oct 2015 18:51:03 +0000 (18:51 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 27 Oct 2015 18:51:03 +0000 (18:51 +0000)
We need to handle the incoming URL more subtly in tests/cgi so that
the tail of the path is preserved; the existing approach squashes it
for the purposes of the CAF get_url callback, but fails to sanitise
the URL at all for the purposes of tests/cgi's form generation.

It would be best if there were a way in the CGI specification for w3m
to tell the script that its own url is actually file:///something, so
that CGI(3pm)'s url method would DTRT.  But there isn't.

In the absence of any useful information provided by w3m, CGI makes up
`http://localhost', which is fair enough.  We can simply replace that
with our own URL prefix.

So we replace the CAFTEST_URL variable with CAFTEST_URLBASE, which
contains the start of the URL (not including the path part, which
tests/cgi can get out of $q->url, and which we would have difficulty
dismantling and reassembling anyway).

In tests/cgi, we apply this to $url if CAFTEST_URLBASE is set, and
then we can unconditionally supply a get_url hook (which hook is
equivalent to the default one if $url wasn't modified).

Adjusting $url in tests/cgi makes the form field come out with the
right URL.  And the new adjustment scheme means that invocations with
a nonempty PATH_INFO do not lose the PATH_INFO.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
tests/cgi
tests/wrap

index 6af24138ed4ab2f4d33f92c801d8056ffd284001..b73e6aae57a0f4a7dcdc51e12df9c28ae5b19b71 100755 (executable)
--- a/tests/cgi
+++ b/tests/cgi
@@ -12,6 +12,13 @@ $SIG{__DIE__} = sub { Carp::confess(@_) };
 
 my $dump = "$ENV{'CAFTEST_CAF'}/tests/tmp";
 
+my $q = CGI->new;
+
+my $url = $q->url();
+
+$url =~ s{^\Qhttp://localhost/\E}{$ENV{CAFTEST_URLBASE}}
+    if $ENV{'CAFTEST_URLBASE'};
+
 my @verifier_params =(
     username_password_error => sub {
         my ($c,$r,$u,$p)=@_;
@@ -22,24 +29,18 @@ my @verifier_params =(
     dir => $dump,
     srcdump_filter_cwd => 0,
     debug => sub { print STDERR "DEBUG ", @_[2..@_-1]; },
-    );
-
-push @verifier_params, (
-    get_url => sub { return $ENV{'CAFTEST_URL'}; },
-    ) if $ENV{'CAFTEST_URL'};
+    get_url => sub { return $url },
+);
 
 my $verifier = CGI::Auth::Flexible->new_verifier(@verifier_params);
 
 END { $verifier->disconnect() if $verifier; }
 
-my $q = CGI->new;
-
 my $authreq = $verifier->new_request($q);
 
 $authreq->check_ok() or exit;
 
 my $cookie = $authreq->secret_cookie();
-my $url = $q->url();
 my $hiddenhtml = $authreq->secret_hidden_html();
 
 print <<END;
@@ -57,7 +58,8 @@ END
 my $newurl = $authreq->url_with_query_params($authreq->chain_params());
 my $newurl_esc = escapeHTML($newurl);
 
-my $txt = Data::Dumper->Dump([$authreq->get_username(), $authreq->mutate_ok(),
+my $txt = Data::Dumper->Dump([$authreq->get_username(),
+ $q->request_method eq 'POST' ? $authreq->check_mutate() : "(not POST)",
                               $q->path_info(),
                               $authreq->chain_params(),
                               scalar $q->Vars()],
index fefbef42c4bbd867a685fdc7349cf3730f334a32..c401f5738b5c8062637cb6a4543a288684922d77 100755 (executable)
@@ -3,7 +3,7 @@ set -e
 cd "$CAFTEST_CAF"
 exec 2>>tests/tmp/wrap.log
 export HTTP_COOKIE=$(cat "tests/tmp/cookie")
-export CAFTEST_URL=file:///cgi-bin/wrap
+export CAFTEST_URLBASE=file:///
 tests/cgi "$@" | perl -pe '
     next if m/^$/..0;
     next unless m/Set-Cookie: (\w+=[^; ]+)/;