chiark / gitweb /
Testing: Introduce CAFTEST_SRCDUMP_NEEDLOGIN
[cgi-auth-flexible.git] / tests / cgi
index 1610e8d9c46b6db690f5b6e32bd419f7fa16bed2..b7d81d5c11e1044a6e9d34724616a21fab9bb710 100755 (executable)
--- a/tests/cgi
+++ b/tests/cgi
@@ -1,5 +1,23 @@
 #!/usr/bin/perl -w
 
+# This is part of CGI::Auth::Flexible, a perl CGI authentication module.
+#
+# Copyright 2012,2013,2015 Ian Jackson.
+# Copyright 2012,2013,2015 Citrix.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version, with the "CAF Login Exception"
+# as published by Ian Jackson (version 1, or at your option any 
+# later version) as an Additional Permission.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+
+
 use strict;
 use warnings;
 use CGI qw/escapeHTML/;;
@@ -10,7 +28,7 @@ use Data::Dumper;
 #use Carp::Always;
 $SIG{__DIE__} = sub { Carp::confess(@_) };
 
-my $dump = "$ENV{'CAFTEST_CAF'}/tests/tmp";
+my $dump = $ENV{'CAFTEST_TMP'} // 'tests/tmp';
 
 my $q = CGI->new;
 
@@ -28,10 +46,16 @@ my @verifier_params =(
     promise_check_mutate => 1,
     dir => $dump,
     srcdump_filter_cwd => 0,
+    srcdump_needlogin => !!$ENV{CAFTEST_SRCDUMP_NEEDLOGIN},
     debug => sub { print STDERR "DEBUG ", @_[2..@_-1]; },
     get_url => sub { return $url },
 );
 
+push @verifier_params, (
+    srcdump_prepare => sub { },
+    )
+    if $ENV{'CAFTEST_NOSRCDUMP'};
+
 my $verifier = CGI::Auth::Flexible->new_verifier(@verifier_params);
 
 END { $verifier->disconnect() if $verifier; }
@@ -49,21 +73,37 @@ Set-Cookie: $cookie
 
 <html><head><title>TITLE</title></head>
 <body><h1>ACCESSGRANTED</h1>
-<h1>again</h1>
-
-<h1>info<h1>
-<pre>
 END
 
 my $newurl = $authreq->url_with_query_params($authreq->chain_params());
 my $newurl_esc = escapeHTML($newurl);
 
+my $incrurl = $authreq->url_with_query_params
+    ({ counter => [ ($q->param('counter')//0) + 1 ]});
+my $incrurl_esc = escapeHTML($incrurl);
+
+my @critters = qw(sponges worms);
+
+foreach my $make (@critters) {
+    my $param = $q->param("test_cgi_$make");
+    if (!$param) {
+        print "NO-$make\n";
+    } else {
+        $authreq->check_mutate();
+        print "MAKING-$make\n";
+    }
+}
+
+print <<END;
+<h1>info<h1>
+<pre>
+END
+
 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()],
-                             [qw(username mutate_ok path
+                             [qw(username path
                                  authreq->chain_params() cgi->params())]);
 foreach my $l (split /\n/, $txt) {
     print escapeHTML($l),"\n";
@@ -71,11 +111,17 @@ foreach my $l (split /\n/, $txt) {
 
 print <<END;
 </pre>
-<a href="$newurl_esc">$newurl_esc</a>
+self=<a href="$newurl_esc">$newurl_esc</a>
+increment=<a href="$incrurl_esc">$incrurl_esc</a>
 <form method="POST" action="$url">
 $hiddenhtml
-<input type="submit" name="test_cgi_sponges" value="Make sponges">
-<input type="submit" name="test_cgi_worms" value="Make worms">
+END
+
+print <<END foreach @critters;
+<input type="submit" name="test_cgi_$_" value="Make $_">
+END
+
+print <<END
 <input type="submit" name="caf_logout" value="Logout">
 </form>
 <form method="POST" action="$url/extra">