]> git.donarmstrong.com Git - debbugs.git/blob - t/18_libravatar_cgi.t
Use ETags; return timestamp not is_valid
[debbugs.git] / t / 18_libravatar_cgi.t
1 # -*- mode: cperl;-*-
2
3 use warnings;
4 use strict;
5
6 use Test::More;
7 # The test functions are placed here to make things easier
8 use lib qw(t/lib);
9 use DebbugsTest qw(:all);
10
11 plan tests => 3;
12
13 my $port = 11344;
14
15 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
16 $SIG{CHLD} = sub {};
17 our %config;
18 eval {
19     %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
20 };
21 if ($@) {
22      BAIL_OUT($@);
23  }
24 $ENV{DEBBUGS_CONFIG_FILE}  = "$config{config_dir}/debbugs_config";
25 END{
26      if ($ENV{DEBUG}) {
27           diag("spool_dir:   $config{spool_dir}\n");
28           diag("config_dir:   $config{config_dir}\n");
29           diag("sendmail_dir: $config{sendmail_dir}\n");
30      }
31 }
32
33 my $libravatar_cgi_handler = sub {
34     my $fh;
35     $ENV{DEBBUGS_CONFIG_FILE} = $config{config_dir}."/debbugs_config";
36     open($fh,'-|',-e './cgi/libravatar.cgi'? './cgi/libravatar.cgi'
37          : '../cgi/libravatar.cgi');
38     my $headers;
39     my $status = 200;
40     while (<$fh>) {
41         if (/^\s*$/ and $status) {
42             print "HTTP/1.1 $status OK\n";
43             print $headers;
44             $status = 0;
45             print $_;
46         } elsif ($status) {
47             $headers .= $_;
48             if (/^Status:\s*(\d+)/i) {
49                 $status = $1;
50             }
51         } else {
52             print $_;
53         }
54     }
55 };
56
57
58 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($libravatar_cgi_handler,$port),
59    'forked HTTP::Server::Simple successfully');
60
61 use LWP::UserAgent;
62 my $ua = LWP::UserAgent->new;
63 $ua->agent("DebbugsTesting/0.1 ");
64
65 # Create a request
66 my $req = HTTP::Request->new(GET => "http://localhost:$port/?avatar=no");
67
68 my $res = $ua->request($req);
69 ok($res->is_success(),'cgi/libravatar.cgi returns success');
70 my $etag = $res->header('Etag');
71
72 $req = HTTP::Request->new(GET => "http://localhost:$port/?avatar=no",
73                           ['If-None-Match',$etag]);
74 $res = $ua->request($req);
75 ok($res->code() eq '304','If-None-Match set gives us 304 not modified');
76
77
78