-
Notifications
You must be signed in to change notification settings - Fork 70
/
relaycountry_geoip2.t
executable file
·54 lines (41 loc) · 1.46 KB
/
relaycountry_geoip2.t
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
#!/usr/bin/perl -T
BEGIN {
if (-e 't/test_dir') { # if we are running "t/rule_tests.t", kluge around ...
chdir 't';
}
if (-e 'test_dir') { # running from test directory, not ..
unshift(@INC, '../blib/lib');
unshift(@INC, '../lib');
}
}
use lib '.'; use lib 't';
use SATest; sa_t_init("relaycountry");
use constant HAS_GEOIP2 => eval { require GeoIP2::Database::Reader; };
# TODO: get the list from RelayCountry.pm / geoip2_default_db_path
use constant HAS_GEOIP2_DB => eval {
-f "/usr/local/share/GeoIP/GeoIP2-Country.mmdb" or
-f "/usr/share/GeoIP/GeoIP2-Country.mmdb" or
-f "/var/lib/GeoIP/GeoIP2-Country.mmdb" or
-f "/usr/local/share/GeoIP/GeoLite2-Country.mmdb" or
-f "/usr/share/GeoIP/GeoLite2-Country.mmdb" or
-f "/var/lib/GeoIP/GeoLite2-Country.mmdb"
};
use Test::More;
plan skip_all => "GeoIP2::Database::Reader not installed" unless HAS_GEOIP2;
plan skip_all => "GeoIP2 database not found from default locations" unless HAS_GEOIP2_DB;
plan tests => 2;
# ---------------------------------------------------------------------------
tstpre ("
loadplugin Mail::SpamAssassin::Plugin::RelayCountry
");
tstprefs ("
dns_available no
country_db_type GeoIP2
add_header all Relay-Country _RELAYCOUNTRY_
");
# Check for country of gmail.com mail server
%patterns = (
q{ X-Spam-Relay-Country: US }, '',
);
ok sarun ("-L -t < data/spam/relayUS.eml", \&patterns_run_cb);
ok_all_patterns();