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