diff options
author | Jonas Smedegaard <dr@jones.dk> | 2010-08-27 10:01:58 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2010-08-27 10:01:58 +0200 |
commit | f398ad035b973608d380c9939ea845d8e2a0cdc2 (patch) | |
tree | 1ba1a0c94e375ab8ed609eaa57a542c6b87de5a8 /t/find_src_files.t | |
parent | 958e5735c946263a111420fe47abe58782581e8c (diff) | |
parent | 6d213a0c739d5b34357b01a616f99197eeba6ad9 (diff) |
Merge branch 'master' of git://git.ikiwiki.info
Diffstat (limited to 't/find_src_files.t')
-rwxr-xr-x | t/find_src_files.t | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/t/find_src_files.t b/t/find_src_files.t new file mode 100755 index 000000000..a3742db75 --- /dev/null +++ b/t/find_src_files.t @@ -0,0 +1,97 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 20; + +BEGIN { use_ok("IkiWiki"); } +BEGIN { use_ok("IkiWiki::Render"); } + +%config=IkiWiki::defaultconfig(); +$config{srcdir}="t/tmp/srcdir"; +$config{underlaydir}="t/tmp/underlaydir"; +IkiWiki::checkconfig(); + +sub cleanup { + ok(! system("rm -rf t/tmp")); +} + +sub setup_underlay { + foreach my $file (@_) { + writefile($file, $config{underlaydir}, "test content"); + } + return @_; +} + +sub setup_srcdir { + foreach my $file (@_) { + writefile($file, $config{srcdir}, "test content"); + } + return @_; +} + +sub test_src_files { + my %expected=map { $_ => 1 } @{shift()}; # the input list may have dups + my $desc=shift; + + close STDERR; # find_src_files prints warnings about bad files + + my ($files, $pages)=IkiWiki::find_src_files(); + is_deeply([sort @$files], [sort keys %expected], $desc); +} + +cleanup(); + +my @list=setup_underlay(qw{index.mdwn sandbox.mdwn smiley.png ikiwiki.mdwn ikiwiki/directive.mdwn ikiwiki/directive/foo.mdwn}); +push @list, setup_srcdir(qw{index.mdwn foo.mwdn icon.jpeg blog/archive/1/2/3/foo.mdwn blog/archive/1/2/4/bar.mdwn blog/archive.mdwn}); +test_src_files(\@list, "simple test"); + +setup_srcdir(".badfile"); +test_src_files(\@list, "srcdir dotfile is skipped"); + +setup_underlay(".badfile"); +test_src_files(\@list, "underlay dotfile is skipped"); + +setup_srcdir(".ikiwiki/index"); +test_src_files(\@list, "srcdir dotdir is skipped"); + +setup_underlay(".ikiwiki/index"); +test_src_files(\@list, "underlay dotdir is skipped"); + +setup_srcdir("foo>.mdwn"); +test_src_files(\@list, "illegal srcdir filename skipped"); + +setup_underlay("foo>.mdwn"); +test_src_files(\@list, "illegal underlay filename skipped"); + +system("mkdir -p $config{srcdir}/empty"); +test_src_files(\@list, "empty srcdir directory ignored"); + +system("mkdir -p $config{underlaydir}/empty"); +test_src_files(\@list, "empty underlay directory ignored"); + +setup_underlay("bad.mdwn"); +system("ln -sf /etc/passwd $config{srcdir}/bad.mdwn"); +test_src_files(\@list, "underlaydir override attack foiled"); + +system("ln -sf /etc/passwd $config{srcdir}/symlink.mdwn"); +test_src_files(\@list, "file symlink in srcdir skipped"); + +system("ln -sf /etc/passwd $config{underlaydir}/symlink.mdwn"); +test_src_files(\@list, "file symlink in underlaydir skipped"); + +system("ln -sf /etc/ $config{srcdir}/symdir"); +test_src_files(\@list, "dir symlink in srcdir skipped"); + +system("ln -sf /etc/ $config{underlaydir}/symdir"); +test_src_files(\@list, "dir symlink in underlaydir skipped"); + +system("ln -sf /etc/ $config{srcdir}/blog/symdir"); +test_src_files(\@list, "deep dir symlink in srcdir skipped"); + +system("ln -sf /etc/ $config{underlaydir}/ikiwiki/symdir"); +test_src_files(\@list, "deep dir symlink in underlaydir skipped"); + + + + +cleanup(); |