]> sipb.mit.edu Git - ikiwiki.git/blob - t/find_src_files.t
Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[ikiwiki.git] / t / find_src_files.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 20;
5
6 BEGIN { use_ok("IkiWiki"); }
7 BEGIN { use_ok("IkiWiki::Render"); }
8
9 %config=IkiWiki::defaultconfig();
10 $config{srcdir}="t/tmp/srcdir";
11 $config{underlaydir}="t/tmp/underlaydir";
12 IkiWiki::checkconfig();
13
14 sub cleanup {
15         ok(! system("rm -rf t/tmp"));
16 }
17
18 sub setup_underlay {
19         foreach my $file (@_) {
20                 writefile($file, $config{underlaydir}, "test content");
21         }
22         return @_;
23 }
24
25 sub setup_srcdir {
26         foreach my $file (@_) {
27                 writefile($file, $config{srcdir}, "test content");
28         }
29         return @_;
30 }
31
32 sub test_src_files {
33         my %expected=map { $_ => 1 } @{shift()}; # the input list may have dups
34         my $desc=shift;
35
36         close STDERR; # find_src_files prints warnings about bad files
37
38         my ($files, $pages)=IkiWiki::find_src_files();
39         is_deeply([sort @$files], [sort keys %expected], $desc);
40 }
41
42 cleanup();
43
44 my @list=setup_underlay(qw{index.mdwn sandbox.mdwn smiley.png ikiwiki.mdwn ikiwiki/directive.mdwn ikiwiki/directive/foo.mdwn});
45 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});
46 test_src_files(\@list, "simple test");
47
48 setup_srcdir(".badfile");
49 test_src_files(\@list, "srcdir dotfile is skipped");
50
51 setup_underlay(".badfile");
52 test_src_files(\@list, "underlay dotfile is skipped");
53
54 setup_srcdir(".ikiwiki/index");
55 test_src_files(\@list, "srcdir dotdir is skipped");
56
57 setup_underlay(".ikiwiki/index");
58 test_src_files(\@list, "underlay dotdir is skipped");
59
60 setup_srcdir("foo>.mdwn");
61 test_src_files(\@list, "illegal srcdir filename skipped");
62
63 setup_underlay("foo>.mdwn");
64 test_src_files(\@list, "illegal underlay filename skipped");
65
66 system("mkdir -p $config{srcdir}/empty");
67 test_src_files(\@list, "empty srcdir directory ignored");
68
69 system("mkdir -p $config{underlaydir}/empty");
70 test_src_files(\@list, "empty underlay directory ignored");
71
72 setup_underlay("bad.mdwn");
73 system("ln -sf /etc/passwd $config{srcdir}/bad.mdwn");
74 test_src_files(\@list, "underlaydir override attack foiled");
75
76 system("ln -sf /etc/passwd $config{srcdir}/symlink.mdwn");
77 test_src_files(\@list, "file symlink in srcdir skipped");
78
79 system("ln -sf /etc/passwd $config{underlaydir}/symlink.mdwn");
80 test_src_files(\@list, "file symlink in underlaydir skipped");
81
82 system("ln -sf /etc/ $config{srcdir}/symdir");
83 test_src_files(\@list, "dir symlink in srcdir skipped");
84
85 system("ln -sf /etc/ $config{underlaydir}/symdir");
86 test_src_files(\@list, "dir symlink in underlaydir skipped");
87
88 system("ln -sf /etc/ $config{srcdir}/blog/symdir");
89 test_src_files(\@list, "deep dir symlink in srcdir skipped");
90
91 system("ln -sf /etc/ $config{underlaydir}/ikiwiki/symdir");
92 test_src_files(\@list, "deep dir symlink in underlaydir skipped");
93
94
95
96
97 cleanup();