private-pages.t 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright (C) 2012–2013 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation; either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. require './t/test.pl';
  15. package OddMuse;
  16. use Test::More tests => 29;
  17. add_module('private-pages.pl');
  18. # create password protected page: can't read it without password!
  19. test_page(update_page('Privat', "#PASSWORD foo\nSo many secrets remain untold.\n"),
  20. 'This page is password protected');
  21. # can't update password protected page
  22. update_page('Privat', "#PASSWORD foo\nCats have secrets.\n");
  23. test_page($redirect, 'Status: 403');
  24. # use password foo to update protected page: can't read it without password!
  25. test_page_negative(update_page('Privat', "#PASSWORD foo\nCats have secrets.\n", undef, undef, 1),
  26. 'Cats have secrets');
  27. test_page($redirect, 'Status: 302');
  28. # is not deleted by maintenance job
  29. my $page = get_page('action=maintain');
  30. test_page($page, 'Privat');
  31. # read it with password
  32. my $page = get_page('action=browse id=Privat pwd=foo');
  33. test_page_negative($page, 'This page is password protected');
  34. test_page($page, 'Cats have secrets');
  35. # a keep file was created as well
  36. ok(-f GetKeepFile('Privat', 1), 'Keep file exists');
  37. # can't read old revisions without a password
  38. test_page_negative(get_page('action=browse id=Privat revision=1'),
  39. 'Cats have secrets');
  40. # read old revisions with password
  41. test_page(get_page('action=browse id=Privat revision=1 pwd=foo'),
  42. 'So many secrets remain untold');
  43. # can't read old revisions without password
  44. test_page(get_page('action=browse id=Privat revision=1'),
  45. 'This page is password protected');
  46. # can't see secrets when printing raw pages
  47. my $page = get_page('action=browse raw=1 id=Privat pwd=foo');
  48. test_page_negative($page, 'This page is password protected');
  49. test_page($page, 'Cats have secrets');
  50. # can't see summaries with secrets
  51. my $page = get_page('action=rc raw=1 all=1');
  52. test_page($page, 'Privat');
  53. test_page_negative($page, 'secret');
  54. # can't search for secrets without a password
  55. my $page = get_page('search=cats');
  56. test_page($page, '0 pages found');
  57. test_page_negative($page, "Privat");
  58. # search finds secrets with password
  59. my $page = get_page('search=cats pwd=foo');
  60. test_page($page, '1 pages? found',
  61. 'Privat', '<strong>Cats</strong> have secrets');
  62. # can't edit a private page without a password
  63. my $page = get_page('action=edit id=Privat');
  64. test_page($page, 'Editing not allowed');
  65. test_page_negative($page, 'Cats have secrets');
  66. # can edit a private page with a password
  67. my $page = get_page('action=edit id=Privat pwd=foo');
  68. test_page_negative($page, 'This page is password protected');
  69. test_page($page, 'Cats have secrets');
  70. # can't edit an old revision of a private page without a password
  71. my $page = get_page('action=edit id=Privat revision=1');
  72. test_page($page, 'Editing not allowed');
  73. test_page_negative($page, 'secret');
  74. # can't just post changes to a private page without a password
  75. my $page = get_page('title=Privat text=YaddaYadda revision=1');
  76. test_page($page, 'Editing not allowed');
  77. test_page_negative($page, 'secret');
  78. # can't include them
  79. test_page_negative(update_page('Publik', '<include "Privat">'),
  80. 'Cats have secrets');