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