@@ -11,35 +11,6 @@ use lib "$Bin/../lib";
1111
1212use TestBootstrap ();
1313
14- {
15- package Local::AbuseIPConfig ;
16-
17- sub new {
18- my ($class , $config ) = @_ ;
19- return bless { config => $config }, $class ;
20- }
21-
22- sub config {
23- my ($self ) = @_ ;
24- return %{ $self -> {config } };
25- }
26- }
27-
28- sub reload_abuseip_module {
29- my ($config ) = @_ ;
30-
31- require ConfigServer::Config;
32-
33- no warnings qw( redefine once) ;
34- local *ConfigServer::Config::loadconfig = sub {
35- return Local::AbuseIPConfig-> new($config );
36- };
37-
38- delete $INC {' ConfigServer/AbuseIP.pm' };
39- require ConfigServer::AbuseIP;
40- return 1;
41- }
42-
4314sub build_fake_host_binary {
4415 my ($dir , %opts ) = @_ ;
4516
@@ -85,7 +56,7 @@ subtest 'abuseip resolves an IPv4 abuse contact and builds the human message' =>
8556 output => qq{ $lookup has TXT record "abuse\@ example.test"\n } ,
8657 );
8758
88- reload_abuseip_module( { HOST => $host_bin });
59+ TestBootstrap::reload_module_with_config( ' ConfigServer::AbuseIP ' , { HOST => $host_bin });
8960 my ($contact , $message ) = ConfigServer::AbuseIP::abuseip(' 192.0.2.10' );
9061
9162 is($contact , ' abuse@example.test' , ' IPv4 lookup returns the TXT contact value' );
@@ -106,7 +77,7 @@ subtest 'abuseip resolves an IPv6 abuse contact' => sub {
10677 output => qq{ $lookup has TXT record "ipv6-contact\@ example.test"\n } ,
10778 );
10879
109- reload_abuseip_module( { HOST => $host_bin });
80+ TestBootstrap::reload_module_with_config( ' ConfigServer::AbuseIP ' , { HOST => $host_bin });
11081 my ($contact , $message ) = ConfigServer::AbuseIP::abuseip(' 2001:db8::20' );
11182
11283 is($contact , ' ipv6-contact@example.test' , ' IPv6 lookup returns the TXT contact value' );
@@ -125,7 +96,7 @@ subtest 'abuseip returns nothing for invalid input and skips the host lookup ent
12596 output => qq{ should not be used\n } ,
12697 );
12798
128- reload_abuseip_module( { HOST => $host_bin });
99+ TestBootstrap::reload_module_with_config( ' ConfigServer::AbuseIP ' , { HOST => $host_bin });
129100 my $result = ConfigServer::AbuseIP::abuseip(' not-an-ip' );
130101
131102 ok(!$result , ' invalid input returns a false value' );
@@ -140,7 +111,7 @@ subtest 'abuseip returns nothing when the lookup output contains no quoted conta
140111 output => qq{ $lookup lookup failed\n } ,
141112 );
142113
143- reload_abuseip_module( { HOST => $host_bin });
114+ TestBootstrap::reload_module_with_config( ' ConfigServer::AbuseIP ' , { HOST => $host_bin });
144115 my $result = ConfigServer::AbuseIP::abuseip(' 192.0.2.10' );
145116
146117 ok(!$result , ' missing TXT contact produces a false value' );
0 commit comments