ban.t 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Copyright (C) 2006-2018 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 => 27;
  17. $localhost = 'confusibombus';
  18. $ENV{'REMOTE_ADDR'} = $localhost;
  19. ## Edit banned hosts as a normal user should fail
  20. test_page(update_page('BannedHosts', "# Foo\n#Bar\n$localhost\n", 'banning me'),
  21. 'This page does not exist');
  22. ## Edit banned hosts as admin should succeed
  23. test_page(update_page('BannedHosts', "#Foo\n#Bar\n$localhost\n", 'banning me', 0, 1),
  24. "Foo",
  25. $localhost);
  26. ## Edit banned hosts as a normal user should fail
  27. test_page(update_page('BannedHosts', "Something else.", 'banning me'),
  28. "Foo",
  29. $localhost);
  30. ## Try to edit another page as a banned user
  31. test_page(update_page('BannedUser', 'This is a test which should fail.', 'banning test'),
  32. 'This page does not exist');
  33. ## Try to edit the same page as a banned user with admin password
  34. test_page(update_page('BannedUser', 'This is a test.', 'banning test', 0, 1),
  35. "This is a test");
  36. ## Unbann myself again, testing the regexp
  37. test_page(update_page('BannedHosts', "#Foo\n#Bar\n", 'banning me', 0, 1), "Foo", "Bar");
  38. ## Banning content, including a malformed regexp
  39. # mafia is banned
  40. update_page('BannedContent', "# cosa\nma ?fia # 2007-01-14 crime\n#nostra\n(huh?\n", 'one banned word', 0, 1);
  41. test_page(update_page('CriminalPage', 'This is about http://mafia.example.com'),
  42. 'This page does not exist');
  43. # error message is shown
  44. test_page($redirect,
  45. 'banned text',
  46. 'wiki administrator',
  47. 'matched',
  48. 'See .*BannedContent.* for more information',
  49. 'Reason: crime');
  50. # admin can override the ban
  51. test_page(update_page('CriminalPage', 'This is about http://mafia.example.com',
  52. undef, undef, 1),
  53. "http://mafia.example.com");
  54. sleep(1);
  55. OpenPage('CriminalPage');
  56. my $ts = $Page{ts};
  57. # other edits are ok
  58. test_page(update_page('CriminalPage', 'This is about http://nafia.example.com'),
  59. "http://nafia.example.com");
  60. # comments have no effect
  61. test_page(update_page('CriminalPage', 'This is the http://cosa.example.com'),
  62. "http://cosa.example.com");
  63. # only match in urls
  64. test_page(update_page('CriminalPage', 'This is about the mafia'),
  65. 'This is about the mafia');
  66. # rollback to banned content requires admin
  67. test_page(get_page("action=rollback to=$ts id=CriminalPage username=Alex"),
  68. 'Rolling back changes',
  69. 'Rollback of CriminalPage would restore banned content');
  70. # it works with the correct password
  71. test_page(get_page("action=rollback to=$ts id=CriminalPage pwd=foo"),
  72. 'Rolling back changes',
  73. 'CriminalPage</a> rolled back');
  74. # make sure it also doesn't work in the homepage field for comments
  75. AppendStringToFile($ConfigFile, "\$CommentsPrefix = 'Comments on ';\n");
  76. # mafia is still banned
  77. test_page(get_page(join(' ', 'title=Comments_on_CriminalPage',
  78. 'aftertext=Innocent',
  79. 'username=Alex',
  80. 'homepage=http://mafia.example.com')),
  81. 'Reason: crime');
  82. # but it still works!
  83. test_page(get_page(join(' ', 'title=Comments_on_CriminalPage',
  84. 'aftertext=Innocent',
  85. 'username=Alex',
  86. 'homepage=http://police.example.com')),
  87. 'Status: 302');
  88. test_page(get_page('Comments_on_CriminalPage'),
  89. 'Innocent',
  90. 'http://police.example.com');