]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - t/relativity.t
Extract check_cgi_mode_bits(). No change intended.
[git.ikiwiki.info.git] / t / relativity.t
index 300c6e61da966ed8378d58f5054561248553fb36..5922ec9fa5bd9de4184c0189556daa026eb53b27 100755 (executable)
@@ -2,23 +2,18 @@
 use warnings;
 use strict;
 
-use Cwd qw(getcwd);
-use Errno qw(ENOENT);
-
-BEGIN {
-       if (!eval q{
+use Test::More;
+plan(skip_all => "IPC::Run not available")
+       unless eval q{
                use IPC::Run qw(run);
                1;
-       }) {
-               eval q{use Test::More skip_all => "IPC::Run not available"};
-       }
-       else {
-               eval q{use Test::More};
-       }
-       use_ok("IkiWiki");
-}
+       };
+
+use IkiWiki;
+
+use Cwd qw(getcwd);
+use Errno qw(ENOENT);
 
-my $PERL5LIB = 'blib/lib:blib/arch';
 my $pwd = getcwd();
 
 # Black-box (ish) test for relative linking between CGI and static content
@@ -64,36 +59,56 @@ write_old_file("a/b/c.mdwn",
 write_old_file("a/d.mdwn", "D");
 write_old_file("a/d/e.mdwn", "E");
 
-#######################################################################
-# site 1: a perfectly ordinary ikiwiki
+sub write_setup_file {
+       my (%args) = @_;
+       my $urlline = defined $args{url} ? "url: $args{url}" : "";
+       my $w3mmodeline = defined $args{w3mmode} ? "w3mmode: $args{w3mmode}" : "";
+       my $reverseproxyline = defined $args{reverse_proxy} ? "reverse_proxy: $args{reverse_proxy}" : "";
 
-writefile("test.setup", "t/tmp", <<EOF
+       writefile("test.setup", "t/tmp", <<EOF
 # IkiWiki::Setup::Yaml - YAML formatted setup file
 wikiname: this is the name of my wiki
 srcdir: t/tmp/in
 destdir: t/tmp/out
 templatedir: templates
-url: "http://example.com/wiki/"
-cgiurl: "http://example.com/cgi-bin/ikiwiki.cgi"
+$urlline
+cgiurl: $args{cgiurl}
+$w3mmodeline
 cgi_wrapper: t/tmp/ikiwiki.cgi
 cgi_wrappermode: 0754
-html5: 0
+html5: $args{html5}
 # make it easier to test previewing
 add_plugins:
 - anonok
 anonok_pagespec: "*"
-ENV: { 'PERL5LIB': '$PERL5LIB' }
+$reverseproxyline
+ENV: { 'PERL5LIB': 'blib/lib:blib/arch' }
 EOF
-);
+       );
+}
 
-ok(unlink("t/tmp/ikiwiki.cgi") || $!{ENOENT});
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
+sub thoroughly_rebuild {
+       ok(unlink("t/tmp/ikiwiki.cgi") || $!{ENOENT});
+       ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
+}
 
-# CGI wrapper should be exactly the requested mode
-my (undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+sub check_cgi_mode_bits {
+       my (undef, undef, $mode, undef, undef,
+               undef, undef, undef, undef, undef,
+               undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
+       is($mode & 07777, 0754);
+}
+
+#######################################################################
+# site 1: a perfectly ordinary ikiwiki
+
+write_setup_file(
+       html5   => 0,
+       url     => "http://example.com/wiki/",
+       cgiurl  => "http://example.com/cgi-bin/ikiwiki.cgi",
+);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");
@@ -165,33 +180,13 @@ like($bits{cgihref}, qr{^(?:(?:http:)?//example.com)?/cgi-bin/ikiwiki.cgi$});
 
 # in html5, the <base> is allowed to be relative, and we take full
 # advantage of that
-writefile("test.setup", "t/tmp", <<EOF
-# IkiWiki::Setup::Yaml - YAML formatted setup file
-wikiname: this is the name of my wiki
-srcdir: t/tmp/in
-destdir: t/tmp/out
-templatedir: templates
-url: "http://example.com/wiki/"
-cgiurl: "http://example.com/cgi-bin/ikiwiki.cgi"
-cgi_wrapper: t/tmp/ikiwiki.cgi
-cgi_wrappermode: 0754
-html5: 1
-# make it easier to test previewing
-add_plugins:
-- anonok
-anonok_pagespec: "*"
-ENV: { 'PERL5LIB': '$PERL5LIB' }
-EOF
+write_setup_file(
+       html5   => 1,
+       url     => "http://example.com/wiki/",
+       cgiurl  => "http://example.com/cgi-bin/ikiwiki.cgi",
 );
-
-ok(unlink("t/tmp/ikiwiki.cgi") || $!{ENOENT});
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
-
-# CGI wrapper should be exactly the requested mode
-(undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");
@@ -266,33 +261,13 @@ is($bits{cgihref}, "/cgi-bin/ikiwiki.cgi");
 #######################################################################
 # site 2: static content and CGI are on different servers
 
-writefile("test.setup", "t/tmp", <<EOF
-# IkiWiki::Setup::Yaml - YAML formatted setup file
-wikiname: this is the name of my wiki
-srcdir: t/tmp/in
-destdir: t/tmp/out
-templatedir: templates
-url: "http://static.example.com/"
-cgiurl: "http://cgi.example.com/ikiwiki.cgi"
-cgi_wrapper: t/tmp/ikiwiki.cgi
-cgi_wrappermode: 0754
-html5: 0
-# make it easier to test previewing
-add_plugins:
-- anonok
-anonok_pagespec: "*"
-ENV: { 'PERL5LIB': '$PERL5LIB' }
-EOF
+write_setup_file(
+       html5   => 0,
+       url     => "http://static.example.com/",
+       cgiurl  => "http://cgi.example.com/ikiwiki.cgi",
 );
-
-ok(unlink("t/tmp/ikiwiki.cgi"));
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
-
-# CGI wrapper should be exactly the requested mode
-(undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");
@@ -354,33 +329,13 @@ local $TODO = "use self-referential CGI URL?";
 like($bits{cgihref}, qr{^(?:(?:http:)?//staging.example.net)?/ikiwiki.cgi$});
 }
 
-writefile("test.setup", "t/tmp", <<EOF
-# IkiWiki::Setup::Yaml - YAML formatted setup file
-wikiname: this is the name of my wiki
-srcdir: t/tmp/in
-destdir: t/tmp/out
-templatedir: templates
-url: "http://static.example.com/"
-cgiurl: "http://cgi.example.com/ikiwiki.cgi"
-cgi_wrapper: t/tmp/ikiwiki.cgi
-cgi_wrappermode: 0754
-html5: 1
-# make it easier to test previewing
-add_plugins:
-- anonok
-anonok_pagespec: "*"
-ENV: { 'PERL5LIB': '$PERL5LIB' }
-EOF
+write_setup_file(
+       html5   => 1,
+       url     => "http://static.example.com/",
+       cgiurl  => "http://cgi.example.com/ikiwiki.cgi",
 );
-
-ok(unlink("t/tmp/ikiwiki.cgi"));
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
-
-# CGI wrapper should be exactly the requested mode
-(undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");
@@ -446,33 +401,13 @@ is($bits{cgihref}, "//staging.example.net/ikiwiki.cgi");
 #######################################################################
 # site 3: we specifically want everything to be secure
 
-writefile("test.setup", "t/tmp", <<EOF
-# IkiWiki::Setup::Yaml - YAML formatted setup file
-wikiname: this is the name of my wiki
-srcdir: t/tmp/in
-destdir: t/tmp/out
-templatedir: templates
-url: "https://example.com/wiki/"
-cgiurl: "https://example.com/cgi-bin/ikiwiki.cgi"
-cgi_wrapper: t/tmp/ikiwiki.cgi
-cgi_wrappermode: 0754
-html5: 0
-# make it easier to test previewing
-add_plugins:
-- anonok
-anonok_pagespec: "*"
-ENV: { 'PERL5LIB': '$PERL5LIB' }
-EOF
+write_setup_file(
+       html5   => 0,
+       url     => "https://example.com/wiki/",
+       cgiurl  => "https://example.com/cgi-bin/ikiwiki.cgi",
 );
-
-ok(unlink("t/tmp/ikiwiki.cgi"));
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
-
-# CGI wrapper should be exactly the requested mode
-(undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");
@@ -554,33 +489,13 @@ like($bits{cgihref}, qr{^(?:(?:https:)?//example.com)?/cgi-bin/ikiwiki.cgi$});
 #######################################################################
 # site 4 (NetBSD wiki): CGI is secure, static content doesn't have to be
 
-writefile("test.setup", "t/tmp", <<EOF
-# IkiWiki::Setup::Yaml - YAML formatted setup file
-wikiname: this is the name of my wiki
-srcdir: t/tmp/in
-destdir: t/tmp/out
-templatedir: templates
-url: "http://example.com/wiki/"
-cgiurl: "https://example.com/cgi-bin/ikiwiki.cgi"
-cgi_wrapper: t/tmp/ikiwiki.cgi
-cgi_wrappermode: 0754
-html5: 0
-# make it easier to test previewing
-add_plugins:
-- anonok
-anonok_pagespec: "*"
-ENV: { 'PERL5LIB': '$PERL5LIB' }
-EOF
+write_setup_file(
+       html5   => 0,
+       url     => "http://example.com/wiki/",
+       cgiurl  => "https://example.com/cgi-bin/ikiwiki.cgi",
 );
-
-ok(unlink("t/tmp/ikiwiki.cgi"));
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
-
-# CGI wrapper should be exactly the requested mode
-(undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");
@@ -659,33 +574,13 @@ like($bits{stylehref}, qr{^(?:(?:https:)?//example.com)?/wiki/style.css$});
 like($bits{tophref}, qr{^(?:/wiki|\.\./\.\./\.\.)/$});
 like($bits{cgihref}, qr{^(?:(?:https:)?//example.com)?/cgi-bin/ikiwiki.cgi$});
 
-writefile("test.setup", "t/tmp", <<EOF
-# IkiWiki::Setup::Yaml - YAML formatted setup file
-wikiname: this is the name of my wiki
-srcdir: t/tmp/in
-destdir: t/tmp/out
-templatedir: templates
-url: "http://example.com/wiki/"
-cgiurl: "https://example.com/cgi-bin/ikiwiki.cgi"
-cgi_wrapper: t/tmp/ikiwiki.cgi
-cgi_wrappermode: 0754
-html5: 1
-# make it easier to test previewing
-add_plugins:
-- anonok
-anonok_pagespec: "*"
-ENV: { 'PERL5LIB': '$PERL5LIB' }
-EOF
+write_setup_file(
+       html5   => 1,
+       url     => "http://example.com/wiki/",
+       cgiurl  => "https://example.com/cgi-bin/ikiwiki.cgi",
 );
-
-ok(unlink("t/tmp/ikiwiki.cgi"));
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
-
-# CGI wrapper should be exactly the requested mode
-(undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");
@@ -770,32 +665,14 @@ like($bits{cgihref}, qr{^(?:(?:https:)?//example.com)?/cgi-bin/ikiwiki.cgi$});
 #######################################################################
 # site 5: w3mmode, as documented in [[w3mmode]]
 
-writefile("test.setup", "t/tmp", <<EOF
-# IkiWiki::Setup::Yaml - YAML formatted setup file
-wikiname: this is the name of my wiki
-srcdir: t/tmp/in
-destdir: t/tmp/out
-templatedir: templates
-cgiurl: ikiwiki.cgi
-w3mmode: 1
-cgi_wrapper: t/tmp/ikiwiki.cgi
-cgi_wrappermode: 0754
-html5: 0
-add_plugins:
-- anonok
-anonok_pagespec: "*"
-ENV: { 'PERL5LIB': '$PERL5LIB' }
-EOF
+write_setup_file(
+       html5   => 0, 
+       url     => undef,
+       cgiurl  => "ikiwiki.cgi",
+       w3mmode => 1,
 );
-
-ok(unlink("t/tmp/ikiwiki.cgi"));
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
-
-# CGI wrapper should be exactly the requested mode
-(undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");
@@ -820,32 +697,14 @@ like($bits{cgihref}, qr{^(?:file://)?/\$LIB/ikiwiki-w3m.cgi/ikiwiki.cgi$});
 like($bits{basehref}, qr{^(?:(?:file:)?//)?\Q$pwd\E/t/tmp/out/$});
 like($bits{stylehref}, qr{^(?:(?:(?:file:)?//)?\Q$pwd\E/t/tmp/out|\.)/style.css$});
 
-writefile("test.setup", "t/tmp", <<EOF
-# IkiWiki::Setup::Yaml - YAML formatted setup file
-wikiname: this is the name of my wiki
-srcdir: t/tmp/in
-destdir: t/tmp/out
-templatedir: templates
-cgiurl: ikiwiki.cgi
-w3mmode: 1
-cgi_wrapper: t/tmp/ikiwiki.cgi
-cgi_wrappermode: 0754
-html5: 1
-add_plugins:
-- anonok
-anonok_pagespec: "*"
-ENV: { 'PERL5LIB': '$PERL5LIB' }
-EOF
+write_setup_file(
+       html5   => 1,
+       url     => undef,
+       cgiurl  => "ikiwiki.cgi",
+       w3mmode => 1,
 );
-
-ok(unlink("t/tmp/ikiwiki.cgi"));
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
-
-# CGI wrapper should be exactly the requested mode
-(undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");
@@ -873,34 +732,14 @@ like($bits{stylehref}, qr{^(?:(?:(?:file:)?//)?\Q$pwd\E/t/tmp/out|\.)/style.css$
 #######################################################################
 # site 6: we're behind a reverse-proxy
 
-writefile("test.setup", "t/tmp", <<EOF
-# IkiWiki::Setup::Yaml - YAML formatted setup file
-wikiname: this is the name of my wiki
-srcdir: t/tmp/in
-destdir: t/tmp/out
-templatedir: templates
-url: "https://example.com/wiki/"
-cgiurl: "https://example.com/cgi-bin/ikiwiki.cgi"
-cgi_wrapper: t/tmp/ikiwiki.cgi
-cgi_wrappermode: 0754
-html5: 0
-# make it easier to test previewing
-add_plugins:
-- anonok
-anonok_pagespec: "*"
-reverse_proxy: 1
-ENV: { 'PERL5LIB': '$PERL5LIB' }
-EOF
+write_setup_file(
+       html5   => 0,
+       url     => "https://example.com/wiki/",
+       cgiurl  => "https://example.com/cgi-bin/ikiwiki.cgi",
+       reverse_proxy => 1,
 );
-
-ok(unlink("t/tmp/ikiwiki.cgi"));
-ok(! system("./ikiwiki.out --setup t/tmp/test.setup --rebuild --wrappers"));
-
-# CGI wrapper should be exactly the requested mode
-(undef, undef, $mode, undef, undef,
-       undef, undef, undef, undef, undef,
-       undef, undef, undef) = stat("t/tmp/ikiwiki.cgi");
-is($mode & 07777, 0754);
+thoroughly_rebuild();
+check_cgi_mode_bits();
 
 ok(-e "t/tmp/out/a/b/c/index.html");
 $content = readfile("t/tmp/out/a/b/c/index.html");