diff options
author | Joey Hess <joey@kitenet.net> | 2010-05-04 23:20:47 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-05-04 23:20:47 -0400 |
commit | 34afaf1015d58f1313a392e3f5f514d484dc7efa (patch) | |
tree | a006891d301bce8622c0a759af773220245e700e /t | |
parent | 3ebd04a33b498d9ae4a1d8535b022704a687dfff (diff) |
add test suite for find_src_files
Diffstat (limited to '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..4a995c2d3 --- /dev/null +++ b/t/find_src_files.t @@ -0,0 +1,97 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 19; + +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(); |