ban-contributors.t 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright (C) 2013-2016 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;
  17. add_module('ban-contributors.pl');
  18. is(BanContributors::get_regexp_ip('77.56.180.0', '77.57.70.255'),
  19. '^77\.(56\.(1[8-9][0-9]|2[0-4][0-9]|25[0-5])|5[7-9]|6[0-9]|70)\.',
  20. '77.56.180.0 - 77.57.70.255');
  21. $localhost = '127.0.0.1';
  22. $ENV{'REMOTE_ADDR'} = $localhost;
  23. update_page('Test', 'insults');
  24. test_page_negative(get_page('action=admin id=Test'), 'Ban contributors');
  25. test_page(get_page('action=admin id=Test pwd=foo'), 'Ban contributors');
  26. test_page(get_page('action=ban id=Test pwd=foo'), $localhost, 'Ban!');
  27. test_page(get_page("action=ban id=Test regexp=$localhost pwd=foo"),
  28. 'Location: http://localhost/wiki.pl/BannedHosts');
  29. test_page(get_page('BannedHosts'), $localhost, 'Test');
  30. clear_pages();
  31. add_module('ban-contributors.pl');
  32. update_page('Test', 'no spam');
  33. ok(get_page('action=browse id=Test raw=2')
  34. =~ /(\d+) # Do not delete this line/,
  35. 'raw=2 returns timestamp');
  36. $to = $1;
  37. ok($to, 'timestamp stored');
  38. sleep(1);
  39. update_page('Test', "http://spam/amoxil/ http://spam/doxycycline/");
  40. test_page(get_page("action=rollback id=Test to=$to pwd=foo"),
  41. 'Rolling back changes', 'These URLs were rolled back',
  42. 'amoxil', 'doxycycline', 'Consider banning the IP number');
  43. test_page(get_page("action=ban id=Test content=amoxil pwd=foo"),
  44. 'Location: http://localhost/wiki.pl/BannedContent');
  45. test_page(get_page('BannedContent'), 'amoxil', 'Test');
  46. update_page('Test', "http://spam/amoxil/ http://spam/doxycycline/");
  47. $page = get_page("action=rollback id=Test to=$to pwd=foo");
  48. test_page($page, 'Rolling back changes', 'These URLs were rolled back',
  49. 'doxycycline');
  50. test_page_negative($page, 'amoxil');
  51. # 127.0.0.1 has no inetnum
  52. test_page(get_page("action=ban id=Test"),
  53. 'Ban Contributors to Test',
  54. quotemeta('127.0.0.1 () [ - ]'));
  55. SKIP: {
  56. skip "Net::Whois::Parser doesn't always return the same result", 4;
  57. $ENV{'REMOTE_ADDR'} = '46.101.109.194';
  58. update_page('Test', "this is phone number spam");
  59. test_page(get_page("action=ban id=Test"),
  60. 'Ban Contributors to Test',
  61. quotemeta('^46\.101\.([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-7])'));
  62. test_page(get_page('action=ban id=Test regexp="^46\.101\.([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-7])" range="[46.101.0.0 - 46.101.127.255]" recent_edit=on pwd=foo'),
  63. 'Location: http://localhost/wiki.pl/BannedHosts');
  64. test_page(get_page('BannedHosts'),
  65. quotemeta('^46\.101\.([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-7]) # '
  66. . CalcDay($Now)
  67. . ' [46.101.0.0 - 46.101.127.255] Test'));
  68. }
  69. done_testing();