chiark / gitweb /
9d6a7e20459e7af1d62f5d33519324c3bb21fb5e
[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'}/test-data";
14
15 my @verifier_params =(
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     srcdump_filter_cwd => 0,
24     );
25
26 my $verifier = CGI::Auth::Flexible->new_verifier(@verifier_params);
27
28 END { $verifier->disconnect() if $verifier; }
29
30 my $q = CGI->new;
31
32 my $authreq = $verifier->new_request($q);
33
34 $authreq->check_ok() or exit;
35
36 my $cookie = $authreq->secret_cookie();
37 my $url = $q->url();
38 my $hiddenhtml = $authreq->secret_hidden_html();
39
40 print <<END;
41 Content-Type: text/html
42 Set-Cookie: $cookie
43
44 <html><head><title>TITLE</title></head>
45 <body><h1>H1</h1>
46 <h1>again</h1>
47
48 <h1>info<h1>
49 <pre>
50 END
51
52 my $newurl = $authreq->url_with_query_params($authreq->chain_params());
53 my $newurl_esc = escapeHTML($newurl);
54
55 my $txt = Data::Dumper->Dump([$authreq->get_username(), $authreq->mutate_ok(),
56                               $q->path_info(),
57                               $authreq->chain_params(),
58                               scalar $q->Vars()],
59                              [qw(username mutate_ok path
60                                  authreq->chain_params() cgi->params())]);
61 foreach my $l (split /\n/, $txt) {
62     print escapeHTML($l),"\n";
63 }
64
65 print <<END;
66 </pre>
67 <a href="$newurl_esc">$newurl_esc</a>
68 <form method="POST" action="$url">
69 $hiddenhtml
70 <input type="submit" name="test_cgi_sponges" value="Make sponges">
71 <input type="submit" name="test_cgi_worms" value="Make worms">
72 <input type="submit" name="caf_logout" value="Logout">
73 </form>
74 <form method="POST" action="$url/extra">
75 $hiddenhtml
76 <input type="submit" name="test_cgi_append" value="Append">
77 </form>
78 END