1 # Copyright (C) 2006, 2007, 2010 Alex Schroeder <alex@gnu.org>
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
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.
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/>.
17 use Test::More tests => 27;
21 $localhost = 'confusibombus';
22 $ENV{'REMOTE_ADDR'} = $localhost;
24 ## Edit banned hosts as a normal user should fail
26 test_page(update_page('BannedHosts', "# Foo\n#Bar\n$localhost\n", 'banning me'),
27 'This page is empty');
29 ## Edit banned hosts as admin should succeed
31 test_page(update_page('BannedHosts', "#Foo\n#Bar\n$localhost\n", 'banning me', 0, 1),
35 ## Edit banned hosts as a normal user should fail
37 test_page(update_page('BannedHosts', "Something else.", 'banning me'),
41 ## Try to edit another page as a banned user
43 test_page(update_page('BannedUser', 'This is a test which should fail.', 'banning test'),
44 'This page is empty');
46 ## Try to edit the same page as a banned user with admin password
48 test_page(update_page('BannedUser', 'This is a test.', 'banning test', 0, 1),
51 ## Unbann myself again, testing the regexp
53 test_page(update_page('BannedHosts', "#Foo\n#Bar\n", 'banning me', 0, 1), "Foo", "Bar");
55 ## Banning content, including a malformed regexp
58 update_page('BannedContent', "# cosa\nma ?fia # 2007-01-14 crime\n#nostra\n(huh?\n", 'one banned word', 0, 1);
59 test_page(update_page('CriminalPage', 'This is about http://mafia.example.com'),
60 'This page is empty');
62 # error message is shown
67 'See .*BannedContent.* for more information',
70 # admin can override the ban
71 test_page(update_page('CriminalPage', 'This is about http://mafia.example.com',
73 "http://mafia.example.com");
77 OpenPage('CriminalPage');
81 test_page(update_page('CriminalPage', 'This is about http://nafia.example.com'),
82 "http://nafia.example.com");
84 # comments have no effect
85 test_page(update_page('CriminalPage', 'This is the http://cosa.example.com'),
86 "http://cosa.example.com");
89 test_page(update_page('CriminalPage', 'This is about the mafia'),
90 'This is about the mafia');
92 # rollback to banned content requires admin
93 test_page(get_page("action=rollback to=$ts id=CriminalPage username=Alex"),
94 'Rolling back changes',
95 'Rollback of CriminalPage would restore banned content');
97 # it works with the correct password
98 test_page(get_page("action=rollback to=$ts id=CriminalPage pwd=foo"),
99 'Rolling back changes',
100 'CriminalPage</a> rolled back');
104 ## test strange-spam.pl
106 add_module('strange-spam.pl');
108 update_page('StrangeBannedContent', "<?pom ?poko>? # 2007-01-14 tanuki power",
110 test_page(update_page('TanukiPage', 'I was here!! <pompoko>'),
111 'This page is empty');
112 test_page($redirect, 'Reason: tanuki power',
113 'See .*StrangeBannedContent.* for more information',
114 'Rule "<\?pom \?poko>\?" matched "<pompoko>" on this page');