Files
oddmuse/t/ban.t
2007-10-06 14:23:22 +00:00

88 lines
2.9 KiB
Perl
Executable File

# Copyright (C) 2006, 2007 Alex Schroeder <alex@emacswiki.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.
# 59 Temple Place, Suite 330
# Boston, MA 02111-1307 USA
require 't/test.pl';
package OddMuse;
use Test::More tests => 23;
clear_pages();
$localhost = 'confusibombus';
$ENV{'REMOTE_ADDR'} = $localhost;
## Edit banned hosts as a normal user should fail
test_page(update_page('BannedHosts', "# Foo\n#Bar\n$localhost\n", 'banning me'),
'This page is empty');
## Edit banned hosts as admin should succeed
test_page(update_page('BannedHosts', "#Foo\n#Bar\n$localhost\n", 'banning me', 0, 1),
"Foo",
$localhost);
## Edit banned hosts as a normal user should fail
test_page(update_page('BannedHosts', "Something else.", 'banning me'),
"Foo",
$localhost);
## Try to edit another page as a banned user
test_page(update_page('BannedUser', 'This is a test which should fail.', 'banning test'),
'This page is empty');
## Try to edit the same page as a banned user with admin password
test_page(update_page('BannedUser', 'This is a test.', 'banning test', 0, 1),
"This is a test");
## Unbann myself again, testing the regexp
test_page(update_page('BannedHosts', "#Foo\n#Bar\n", 'banning me', 0, 1), "Foo", "Bar");
## Banning content, including a malformed regexp
update_page('BannedContent', "# cosa\nma ?fia # 2007-01-14 crime\n#nostra\n(huh?\n", 'one banned word', 0, 1);
test_page(update_page('CriminalPage', 'This is about http://mafia.example.com'),
'This page is empty');
test_page($redirect,
'banned text',
'wiki administrator',
'matched',
'See .*BannedContent.* for more information',
'Reason: crime');
test_page(update_page('CriminalPage', 'This is about http://nafia.example.com'),
"This is about", "http://nafia.example.com");
test_page(update_page('CriminalPage', 'This is about the cosa nostra'),
'cosa nostra');
test_page(update_page('CriminalPage', 'This is about the mafia'),
'This is about the mafia'); # not in an url
add_module('strange-spam.pl');
update_page('StrangeBannedContent', "<?pom ?poko>? # 2007-01-14 tanuki power",
'', 0, 1);
test_page(update_page('TanukiPage', 'I was here!! <pompoko>'),
'This page is empty');
test_page($redirect, 'Reason: tanuki power',
'See .*StrangeBannedContent.* for more information',
'Rule "&lt;\?pom \?poko&gt;\?" matched "&lt;pompoko&gt;" on this page');