chiark / gitweb /
Testing: Increase timeout
[cgi-auth-flexible.git] / tests / 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{'CAFTEST_CAF'}/tests/tmp";
14
15 my $q = CGI->new;
16
17 my $url = $q->url();
18
19 $url =~ s{^\Qhttp://localhost/\E}{$ENV{CAFTEST_URLBASE}}
20     if $ENV{'CAFTEST_URLBASE'};
21
22 my @verifier_params =(
23     username_password_error => sub {
24         my ($c,$r,$u,$p)=@_;
25         return $p eq 'sesame' ? undef : 'wrong password'
26     },
27     encrypted_only => 0,
28     promise_check_mutate => 1,
29     dir => $dump,
30     srcdump_filter_cwd => 0,
31     debug => sub { print STDERR "DEBUG ", @_[2..@_-1]; },
32     get_url => sub { return $url },
33 );
34
35 push @verifier_params, (
36     srcdump_prepare => sub { },
37     )
38     if $ENV{'CAFTEST_NOSRCDUMP'};
39
40 my $verifier = CGI::Auth::Flexible->new_verifier(@verifier_params);
41
42 END { $verifier->disconnect() if $verifier; }
43
44 my $authreq = $verifier->new_request($q);
45
46 $authreq->check_ok() or exit;
47
48 my $cookie = $authreq->secret_cookie();
49 my $hiddenhtml = $authreq->secret_hidden_html();
50
51 print <<END;
52 Content-Type: text/html
53 Set-Cookie: $cookie
54
55 <html><head><title>TITLE</title></head>
56 <body><h1>ACCESSGRANTED</h1>
57 END
58
59 my $newurl = $authreq->url_with_query_params($authreq->chain_params());
60 my $newurl_esc = escapeHTML($newurl);
61
62 my $incrurl = $authreq->url_with_query_params
63     ({ counter => [ ($q->param('counter')//0) + 1 ]});
64 my $incrurl_esc = escapeHTML($incrurl);
65
66 my @critters = qw(sponges worms);
67
68 foreach my $make (@critters) {
69     my $param = $q->param("test_cgi_$make");
70     if (!$param) {
71         print "NO-$make\n";
72     } else {
73         $authreq->check_mutate();
74         print "MAKING-$make\n";
75     }
76 }
77
78 print <<END;
79 <h1>info<h1>
80 <pre>
81 END
82
83 my $txt = Data::Dumper->Dump([$authreq->get_username(),
84                               $q->path_info(),
85                               $authreq->chain_params(),
86                               scalar $q->Vars()],
87                              [qw(username path
88                                  authreq->chain_params() cgi->params())]);
89 foreach my $l (split /\n/, $txt) {
90     print escapeHTML($l),"\n";
91 }
92
93 print <<END;
94 </pre>
95 self=<a href="$newurl_esc">$newurl_esc</a>
96 increment=<a href="$incrurl_esc">$incrurl_esc</a>
97 <form method="POST" action="$url">
98 $hiddenhtml
99 END
100
101 print <<END foreach @critters;
102 <input type="submit" name="test_cgi_$_" value="Make $_">
103 END
104
105 print <<END
106 <input type="submit" name="caf_logout" value="Logout">
107 </form>
108 <form method="POST" action="$url/extra">
109 $hiddenhtml
110 <input type="submit" name="test_cgi_append" value="Append">
111 </form>
112 END