banned-regexps.t 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (C) 2017-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 => 15;
  17. add_module('banned-regexps.pl');
  18. ## Edit banned regexps as a normal user should fail
  19. test_page(update_page('BannedRegexps', "Voldemort # he must not be named\n",
  20. 'no naming'),
  21. 'This page does not exist');
  22. ## Edit banned regexps as admin should succeed
  23. test_page(update_page('BannedRegexps', "Voldemort # he must not be named\n",
  24. 'no naming', 0, 1),
  25. "Voldemort");
  26. # Voldemort must not be named
  27. test_page(update_page('Test', 'Voldemort', 'one banned word'),
  28. 'This page does not exist');
  29. # error message is shown
  30. test_page($redirect,
  31. 'banned text',
  32. 'wiki administrator',
  33. 'matched',
  34. 'See .*BannedRegexps.* for more information',
  35. 'Reason: he must not be named');
  36. # Voldemort may be named by admins
  37. test_page(update_page('Test', 'Voldemort', 'one banned word', 0, 1),
  38. 'Voldemort');
  39. # Rename the page
  40. AppendStringToFile($ConfigFile, "\$BannedRegexps = 'Local_Banned_Regexps';\n");
  41. test_page(update_page('Local_Banned_Regexps', "Harry # he must not be named\n",
  42. 'no naming', 0, 1),
  43. "Harry");
  44. # Now Harry may not be named
  45. test_page(update_page('Test2', 'Harry', 'one banned word'),
  46. 'This page does not exist');
  47. # Voldemort may now be named
  48. test_page(update_page('Test2', 'Voldemort', 'one banned word'),
  49. 'Voldemort');
  50. # Make sure the underscores don't show up in the page link
  51. test_page(get_page('action=admin'), 'Local Banned Regexps');
  52. # Make sure it doesn't break BannedContent!
  53. # mafia is banned
  54. update_page('BannedContent', 'mafia', 'one banned word', 0, 1);
  55. test_page(update_page('CriminalPage', 'This is about http://mafia.example.com'),
  56. 'This page does not exist');
  57. # error message is shown
  58. test_page($redirect, 'Edit Denied');