]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/wrapper-environ.t
Prepare release for stretch-security
[git.ikiwiki.info.git] / t / wrapper-environ.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
5 use Test::More;
6 plan(skip_all => "IPC::Run not available")
7         unless eval q{
8                 use IPC::Run qw(run);
9                 1;
10         };
12 use IkiWiki;
14 use Cwd qw(getcwd);
15 use Errno qw(ENOENT);
17 my $installed = $ENV{INSTALLED_TESTS};
19 my @command;
20 if ($installed) {
21         @command = qw(env PERL5LIB=t/tmp ikiwiki);
22 }
23 else {
24         ok(! system("make -s ikiwiki.out"));
25         @command = (qw(env PERL5LIB=t/tmp:blib/lib:blib/arch perl),
26                 "-I".getcwd, qw(./ikiwiki.out
27                 --underlaydir=underlays/basewiki
28                 --set underlaydirbase=underlays
29                 --templatedir=templates));
30 }
32 writefile("test.setup", "t/tmp", <<EOF
33 # IkiWiki::Setup::Yaml - YAML formatted setup file
34 wikiname: this is the name of my wiki
35 srcdir: t/tmp/in
36 destdir: t/tmp/out
37 url: http://localhost
38 cgiurl: http://localhost/ikiwiki.cgi
39 cgi_wrapper: t/tmp/ikiwiki.cgi
40 cgi_wrappermode: 0754
41 add_plugins:
42 - anonok
43 - excessiveenvironment
44 anonok_pagespec: "*"
45 ENV: { 'PERL5LIB': 't/tmp:blib/lib:blib/arch' }
46 EOF
47         );
49 writefile("index.mdwn", "t/tmp/in", "");
51 writefile("IkiWiki/Plugin/excessiveenvironment.pm", "t/tmp", <<'EOF'
52 #!/usr/bin/perl
53 package IkiWiki::Plugin::excessiveenvironment;
54 use warnings;
55 use strict;
56 use IkiWiki;
58 sub import {
59         hook(type => "getsetup", id => "excessiveenvironment", call => \&getsetup);
60         hook(type => "genwrapper", id => "excessiveenvironment", call => \&genwrapper);
61 }
63 sub getsetup {
64         return plugin => {
65                 safe => 0,
66                 rebuild => undef,
67                 section => "rcs",
68         };
69 }
71 sub genwrapper {
72         my @ret;
73         foreach my $j (1..4096) {
74                 push @ret, qq{addenv("VAR$j", "val$j");\n};
75         }
76         return join '', @ret;
77 }
79 1;
80 EOF
81         );
83 my $stdout;
84 ok(! system(@command, qw(--setup t/tmp/test.setup --rebuild --wrappers)), "run ikiwiki");
85 ok(run(["./t/tmp/ikiwiki.cgi"], '<&-', '>', \$stdout, init => sub {
86         $ENV{HTTP_HOST} = "localhost";
87         $ENV{QUERY_STRING} = "do=prefs";
88         $ENV{REQUEST_METHOD} = "GET";
89         $ENV{SCRIPT_NAME} = "/cgi-bin/ikiwiki.cgi";
90         $ENV{SERVER_PORT} = "80"
91 }), "run CGI");
93 done_testing();