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