chiark / gitweb /
wip
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 11 Jan 2013 16:10:09 +0000 (16:10 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 11 Jan 2013 16:10:09 +0000 (16:10 +0000)
cgi-auth-flexible.pm
test.cgi

index 382b845ddc0c45016c9b004fac989b374659f2eb..0ea969d648f46d33b091531476eb40bdf132844a 100644 (file)
@@ -926,6 +926,12 @@ sub _assert_checked ($) {
     die "unchecked" unless exists $r->{Divert};
 }
 
+sub _is_post ($) {
+    my ($r) = @_;
+    my $meth = $r->_ch('get_method');
+    return $meth eq 'POST';
+}
+
 sub _must_be_post ($) {
     my ($r) = @_;
     my $meth = $r->_ch('get_method');
@@ -939,6 +945,13 @@ sub check_mutate ($) {
     $r->_must_be_post();
 }
 
+sub mutate_ok ($) {
+    my ($r) = @_;
+    $r->_assert_checked();
+    die if $r->{Divert};
+    return $r->_is_post();
+}
+
 #---------- output ----------
 
 sub secret_cookie_val ($) {
index 71ff2fee27f0aa42f27a311dff6daef2ae8218f7..289ac71cbcb3642e0ec822e1e95a53f1ec20b018 100755 (executable)
--- a/test.cgi
+++ b/test.cgi
@@ -2,9 +2,11 @@
 
 use strict;
 use warnings;
-use CGI;
+use CGI qw/escapeHTML/;;
 use CGI::Auth::Flexible;
 use URI;
+use Data::Dumper;
+
 #use Carp::Always;
 $SIG{__DIE__} = sub { Carp::confess(@_) };
 
@@ -13,6 +15,7 @@ my $dump = "$ENV{'CAHTEST_HOME'}/dump";
 my $verifier = CGI::Auth::Flexible->new_verifier(
     username_password_ok => sub { my ($c,$r,$u,$p)=@_; return $p eq 'sesame'; },
     encrypted_only => 0,
+    promise_check_mutate => 1,
     dir => $dump,
 );
 
@@ -36,9 +39,30 @@ Set-Cookie: $cookie
 <body><h1>H1</h1>
 <h1>again</h1>
 
+<h1>info<h1>
+<pre>
+END
+
+my %vars = $q->Vars();
+delete $vars{caf_assochash};
+
+my $txt = Data::Dumper->Dump([$authreq->get_username(), $authreq->mutate_ok(),
+                              $q->path_info(), \%vars],
+                             [qw(username mutate_ok path params)]);
+foreach my $l (split /\n/, $txt) {
+    print escapeHTML($l),"\n";
+}
+
+print <<END;
+</pre>
 <form method="POST" action="$url">
 $hiddenhtml
-<input type="submit" name="test_cgi_submit" value="Make sponges">
+<input type="submit" name="test_cgi_sponges" value="Make sponges">
+<input type="submit" name="test_cgi_worms" value="Make worms">
 <input type="submit" name="caf_logout" value="Logout">
 </form>
+<form method="POST" action="$url/extra">
+$hiddenhtml
+<input type="submit" name="test_cgi_append" value="Append">
+</form>
 END