]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/aggregate-file.t
revert spam
[git.ikiwiki.info.git] / t / aggregate-file.t
1 #!/usr/bin/perl
2 use utf8;
3 use warnings;
4 use strict;
6 use Encode;
7 use Test::More;
9 BEGIN {
10         plan(skip_all => "CGI not available")
11                 unless eval q{
12                         use CGI qw();
13                         1;
14                 };
16         plan(skip_all => "IPC::Run not available")
17                 unless eval q{
18                         use IPC::Run qw(run);
19                         1;
20                 };
22         use_ok('IkiWiki');
23         use_ok('YAML::XS');
24 }
26 # We check for English error messages
27 $ENV{LC_ALL} = 'C';
29 use Cwd qw(getcwd);
30 use Errno qw(ENOENT);
32 my $installed = $ENV{INSTALLED_TESTS};
34 my @command;
35 if ($installed) {
36         @command = qw(ikiwiki --plugin inline);
37 }
38 else {
39         ok(! system("make -s ikiwiki.out"));
40         @command = ("perl", "-I".getcwd."/blib/lib", './ikiwiki.out',
41                 '--underlaydir='.getcwd.'/underlays/basewiki',
42                 '--set', 'underlaydirbase='.getcwd.'/underlays',
43                 '--templatedir='.getcwd.'/templates');
44 }
46 sub write_old_file {
47         my $name = shift;
48         my $dir = shift;
49         my $content = shift;
50         writefile($name, $dir, $content);
51         ok(utime(333333333, 333333333, "$dir/$name"));
52 }
54 sub write_setup_file {
55         my %params = @_;
56         my %setup = (
57                 wikiname => 'this is the name of my wiki',
58                 srcdir => getcwd.'/t/tmp/in',
59                 destdir => getcwd.'/t/tmp/out',
60                 url => 'http://example.com',
61                 cgiurl => 'http://example.com/cgi-bin/ikiwiki.cgi',
62                 cgi_wrapper => getcwd.'/t/tmp/ikiwiki.cgi',
63                 cgi_wrappermode => '0751',
64                 add_plugins => [qw(aggregate)],
65                 disable_plugins => [qw(emailauth openid passwordauth)],
66                 aggregate_webtrigger => 1,
67         );
68         if ($params{without_paranoia}) {
69                 $setup{libdirs} = [getcwd.'/t/noparanoia'];
70         }
71         unless ($installed) {
72                 $setup{ENV} = { 'PERL5LIB' => getcwd.'/blib/lib' };
73         }
74         writefile("test.setup", "t/tmp",
75                 "# IkiWiki::Setup::Yaml - YAML formatted setup file\n" .
76                 Dump(\%setup));
77 }
79 sub thoroughly_rebuild {
80         ok(unlink("t/tmp/ikiwiki.cgi") || $!{ENOENT});
81         ok(! system(@command, qw(--setup t/tmp/test.setup --rebuild --wrappers)));
82 }
84 sub run_cgi {
85         my (%args) = @_;
86         my ($in, $out);
87         my $method = $args{method} || 'GET';
88         my $environ = $args{environ} || {};
89         my $params = $args{params} || { do => 'prefs' };
91         my %defaults = (
92                 SCRIPT_NAME     => '/cgi-bin/ikiwiki.cgi',
93                 HTTP_HOST       => 'example.com',
94         );
96         my $cgi = CGI->new($args{params});
97         my $query_string = $cgi->query_string();
98         diag $query_string;
100         if ($method eq 'POST') {
101                 $defaults{REQUEST_METHOD} = 'POST';
102                 $in = $query_string;
103                 $defaults{CONTENT_LENGTH} = length $in;
104         } else {
105                 $defaults{REQUEST_METHOD} = 'GET';
106                 $defaults{QUERY_STRING} = $query_string;
107         }
109         my %envvars = (
110                 %defaults,
111                 %$environ,
112         );
113         run(["./t/tmp/ikiwiki.cgi"], \$in, \$out, init => sub {
114                 map {
115                         $ENV{$_} = $envvars{$_}
116                 } keys(%envvars);
117         });
119         return decode_utf8($out);
122 sub test {
123         my $content;
125         ok(! system(qw(rm -rf t/tmp)));
126         ok(! system(qw(mkdir t/tmp)));
128         write_old_file('aggregator.mdwn', 't/tmp/in',
129                 '[[!aggregate name="ssrf" url="file://'.getcwd.'/t/secret.rss"]]'
130                 .'[[!inline pages="internal(aggregator/*)"]]');
132         write_setup_file();
133         thoroughly_rebuild();
135         $content = run_cgi(
136                 method => 'GET',
137                 params => {
138                         do => 'aggregate_webtrigger',
139                 },
140         );
141         unlike($content, qr{creating new page});
142         unlike($content, qr{Secrets});
143         ok(! -e 't/tmp/in/.ikiwiki/transient/aggregator/ssrf');
144         ok(! -e 't/tmp/in/.ikiwiki/transient/aggregator/ssrf/Secrets_go_here._aggregated');
146         thoroughly_rebuild();
147         $content = readfile('t/tmp/out/aggregator/index.html');
148         unlike($content, qr{Secrets});
150         diag('Trying test again with LWPx::ParanoidAgent disabled');
152         write_setup_file(without_paranoia => 1);
153         thoroughly_rebuild();
155         $content = run_cgi(
156                 method => 'GET',
157                 params => {
158                         do => 'aggregate_webtrigger',
159                 },
160         );
161         unlike($content, qr{creating new page});
162         unlike($content, qr{Secrets});
163         ok(! -e 't/tmp/in/.ikiwiki/transient/aggregator/ssrf');
164         ok(! -e 't/tmp/in/.ikiwiki/transient/aggregator/ssrf/Secrets_go_here._aggregated');
166         thoroughly_rebuild();
167         $content = readfile('t/tmp/out/aggregator/index.html');
168         unlike($content, qr{Secrets});
171 test();
173 done_testing();