chiark / gitweb /
071586160634293bf78b1a171135bd12bb56c350
[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_ok => sub { my ($c,$r,$u,$p)=@_; return $p eq 'sesame'; },
17     encrypted_only => 0,
18     promise_check_mutate => 1,
19     dir => $dump,
20 );
21
22 END { $verifier->disconnect() if $verifier; }
23
24 my $q = CGI->new;
25
26 my $authreq = $verifier->new_request($q);
27
28 $authreq->check_ok() or exit;
29
30 my $cookie = $authreq->secret_cookie();
31 my $url = $q->url();
32 my $hiddenhtml = $authreq->secret_hidden_html();
33
34 print <<END;
35 Content-Type: text/html
36 Set-Cookie: $cookie
37
38 <html><head><title>TITLE</title></head>
39 <body><h1>H1</h1>
40 <h1>again</h1>
41
42 <h1>info<h1>
43 <pre>
44 END
45
46 my $newurl = $authreq->url_with_query_params($authreq->chain_params());
47 my $newurl_esc = escapeHTML($newurl);
48
49 my $txt = Data::Dumper->Dump([$authreq->get_username(), $authreq->mutate_ok(),
50                               $q->path_info(),
51                               $authreq->chain_params(),
52                               scalar $q->Vars()],
53                              [qw(username mutate_ok path
54                                  authreq->chain_params() cgi->params())]);
55 foreach my $l (split /\n/, $txt) {
56     print escapeHTML($l),"\n";
57 }
58
59 print <<END;
60 </pre>
61 <a href="$newurl_esc">$newurl_esc</a>
62 <form method="POST" action="$url">
63 $hiddenhtml
64 <input type="submit" name="test_cgi_sponges" value="Make sponges">
65 <input type="submit" name="test_cgi_worms" value="Make worms">
66 <input type="submit" name="caf_logout" value="Logout">
67 </form>
68 <form method="POST" action="$url/extra">
69 $hiddenhtml
70 <input type="submit" name="test_cgi_append" value="Append">
71 </form>
72 END