File: Reader-Anonymous-IP.t

package info (click to toggle)
libgeoip2-perl 2.006002-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,156 kB
  • sloc: perl: 2,275; makefile: 10
file content (80 lines) | stat: -rw-r--r-- 2,187 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use strict;
use warnings;

use Test::More;
use Test::Fatal;

use GeoIP2::Database::Reader;
use Path::Class qw( file );

{    # Anonymous IP
    my $reader
        = GeoIP2::Database::Reader->new(
        file => file(qw( maxmind-db test-data GeoIP2-Anonymous-IP-Test.mmdb))
        );

    my %tests = (
        '1.2.0.0' => {
            is_anonymous        => 1,
            is_anonymous_vpn    => 1,
            is_hosting_provider => 0,
            is_public_proxy     => 0,
            is_tor_exit_node    => 0,
        },
        '6.7.8.9' => {
            is_anonymous        => 0,
            is_anonymous_vpn    => 0,
            is_hosting_provider => 0,
            is_public_proxy     => 0,
            is_tor_exit_node    => 0,
        },
        '71.160.223.45' => {
            is_anonymous        => 1,
            is_anonymous_vpn    => 0,
            is_hosting_provider => 1,
            is_public_proxy     => 0,
            is_tor_exit_node    => 0,
        },
        '186.30.236.233' => {
            is_anonymous        => 1,
            is_anonymous_vpn    => 0,
            is_hosting_provider => 0,
            is_public_proxy     => 1,
            is_tor_exit_node    => 0,
        },
        '65.4.3.2' => {
            is_anonymous        => 1,
            is_anonymous_vpn    => 0,
            is_hosting_provider => 0,
            is_public_proxy     => 0,
            is_tor_exit_node    => 1,
        },
        'abcd:1000::1' => {
            is_anonymous        => 1,
            is_anonymous_vpn    => 0,
            is_hosting_provider => 0,
            is_public_proxy     => 1,
            is_tor_exit_node    => 0,
        },
    );

    for my $ip ( sort keys %tests ) {
        my $model = $reader->anonymous_ip( ip => $ip );
        for my $meth ( sort keys %{ $tests{$ip} } ) {
            if ( $tests{$ip}{$meth} ) {
                ok(
                    $model->$meth(),
                    "$meth is true for $ip"
                );
            }
            else {
                ok(
                    !$model->$meth(),
                    "$meth is false for $ip"
                );
            }
        }
    }
}

done_testing();