chiark / gitweb /
is_page: remove obsolete hook
[cgi-auth-flexible.git] / test.cgi
1 #!/usr/bin/perl -w
2
3 use strict;
4 use warnings;
5 use CGI qw/escapeHTML/;;
6 use CGI::Auth::Flexible;
7 use URI;
8 use Data::Dumper;
9
10 #use Carp::Always;
11 $SIG{__DIE__} = sub { Carp::confess(@_) };
12
13 my $dump = "$ENV{'CAHTEST_HOME'}/dump";
14
15 my $verifier = CGI::Auth::Flexible->new_verifier(
16     username_password_error => sub {
17         my ($c,$r,$u,$p)=@_;
18         return $p eq 'sesame' ? undef : 'wrong password'
19     },
20     encrypted_only => 0,
21     promise_check_mutate => 1,
22     dir => $dump,
23 );
24
25 END { $verifier->disconnect() if $verifier; }
26
27 my $q = CGI->new;
28
29 my $authreq = $verifier->new_request($q);
30
31 $authreq->check_ok() or exit;
32
33 my $cookie = $authreq->secret_cookie();
34 my $url = $q->url();
35 my $hiddenhtml = $authreq->secret_hidden_html();
36
37 print <<END;
38 Content-Type: text/html
39 Set-Cookie: $cookie
40
41 <html><head><title>TITLE</title></head>
42 <body><h1>H1</h1>
43 <h1>again</h1>
44
45 <h1>info<h1>
46 <pre>
47 END
48
49 my $newurl = $authreq->url_with_query_params($authreq->chain_params());
50 my $newurl_esc = escapeHTML($newurl);
51
52 my $txt = Data::Dumper->Dump([$authreq->get_username(), $authreq->mutate_ok(),
53                               $q->path_info(),
54                               $authreq->chain_params(),
55                               scalar $q->Vars()],
56                              [qw(username mutate_ok path
57                                  authreq->chain_params() cgi->params())]);
58 foreach my $l (split /\n/, $txt) {
59     print escapeHTML($l),"\n";
60 }
61
62 print <<END;
63 </pre>
64 <a href="$newurl_esc">$newurl_esc</a>
65 <form method="POST" action="$url">
66 $hiddenhtml
67 <input type="submit" name="test_cgi_sponges" value="Make sponges">
68 <input type="submit" name="test_cgi_worms" value="Make worms">
69 <input type="submit" name="caf_logout" value="Logout">
70 </form>
71 <form method="POST" action="$url/extra">
72 $hiddenhtml
73 <input type="submit" name="test_cgi_append" value="Append">
74 </form>
75 END