root/trunk/t/79_host_blacklist.t

Revision 1117, 1.2 kB (checked in by earle, 17 months ago)

Add support for IP blacklisting modules.

Line 
1use strict;
2
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6use Wiki::Toolkit::Setup::SQLite;
7
8eval { require DBD::SQLite; };
9if ( $@ ) {
10    my ($error) = $@ =~ /^(.*?)\n/;
11    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
12}
13
14plan tests => 1;
15
16# Clear out the database from any previous runs.
17unlink "t/node.db";
18unlink <t/indexes/*>;
19Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
20
21# Set up a guide which uses a spam detector module.
22my $config = OpenGuides::Test->make_basic_config;
23$config->host_checker_module( "OpenGuides::Local::HostBlacklist" );
24my $guide = OpenGuides->new( config => $config );
25
26# Ensure CGI tells us what we expect to hear.
27sub fake {'127.0.0.1'}
28
29use CGI;
30{
31    no warnings 'once';
32    *CGI::remote_host = \&fake;
33}
34
35my $output = $guide->display_node(
36                                     id            => "Nonesuch",
37                                     return_output => 1,
38                                 );
39
40like($output, qr/Access denied/, 'host blacklist picks up IP');
41
42package OpenGuides::Local::HostBlacklist;
43
44sub blacklisted_host {
45    my ( $class, $host ) = @_;
46
47        if ( $host =~ /^127/ ) {
48        return 1;
49    }
50
51    return 0;
52}
Note: See TracBrowser for help on using the browser.