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