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