chiark / gitweb /
71ff2fee27f0aa42f27a311dff6daef2ae8218f7
[cgi-auth-flexible.git] / test.cgi
1 #!/usr/bin/perl -w
2
3 use strict;
4 use warnings;
5 use CGI;
6 use CGI::Auth::Flexible;
7 use URI;
8 #use Carp::Always;
9 $SIG{__DIE__} = sub { Carp::confess(@_) };
10
11 my $dump = "$ENV{'CAHTEST_HOME'}/dump";
12
13 my $verifier = CGI::Auth::Flexible->new_verifier(
14     username_password_ok => sub { my ($c,$r,$u,$p)=@_; return $p eq 'sesame'; },
15     encrypted_only => 0,
16     dir => $dump,
17 );
18
19 END { $verifier->disconnect() if $verifier; }
20
21 my $q = CGI->new;
22
23 my $authreq = $verifier->new_request($q);
24
25 $authreq->check_ok() or exit;
26
27 my $cookie = $authreq->secret_cookie();
28 my $url = $q->url();
29 my $hiddenhtml = $authreq->secret_hidden_html();
30
31 print <<END;
32 Content-Type: text/html
33 Set-Cookie: $cookie
34
35 <html><head><title>TITLE</title></head>
36 <body><h1>H1</h1>
37 <h1>again</h1>
38
39 <form method="POST" action="$url">
40 $hiddenhtml
41 <input type="submit" name="test_cgi_submit" value="Make sponges">
42 <input type="submit" name="caf_logout" value="Logout">
43 </form>
44 END