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