File: 034-rfc1123.t

package info (click to toggle)
libsisimai-perl 5.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,408 kB
  • sloc: perl: 10,184; makefile: 78
file content (68 lines) | stat: -rw-r--r-- 2,849 bytes parent folder | download | duplicates (2)
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
use strict;
use Test::More;
use lib qw(./lib ./blib/lib);
use Sisimai::RFC1123;

my $Package = 'Sisimai::RFC1123';
my $Methods = { 'class'  => ['is_internethost', 'find'], 'object' => [] };

use_ok $Package;
can_ok $Package, @{ $Methods->{'class'} };

MAKETEST: {
    my $hostnames0 = [
        '',
        'localhost',
        '127.0.0.1',
        'cat',
        'neko',
        'nyaan.22',
        'mx0.example.22',
        'mx0.example.jp-',
        'mx--0.example.jp',
        'mx..0.example.jp',
        'mx0.example.jp/neko',
    ];
    my $hostnames1 = [
        'mx1.example.jp',
        'mx1.example.jp.',
        'a.jp',
    ];
    my $serversaid = [
        '<neko@example.jp>: host neko.example.jp[192.0.2.2] said: 550 5.7.1 This message was not accepted due to domain (libsisimai.org) owner DMARC policy',
        'neko.example.jp[192.0.2.232]: server refused to talk to me: 421 Service not available, closing transmission channel',
        '... while talking to neko.example.jp.: <<< 554 neko.example.jp ESMTP not accepting connections',
        'host neko.example.jp [192.0.2.222]: 500 Line limit exceeded',
        'Google tried to deliver your message, but it was rejected by the server for the recipient domain nyaan.jp by neko.example.jp. [192.0.2.2].',
        'Delivery failed for the following reason: Server neko.example.jp[192.0.2.222] failed with: 550 <kijitora@example.jp> No such user here',
        'Remote system: dns;neko.example.jp (TCP|17.111.174.65|48044|192.0.2.225|25) (neko.example.jp ESMTP SENDMAIL-VM)',
        'SMTP Server <neko.example.jp> rejected recipient <cat@libsisimai.org> (Error following RCPT command). It responded as follows: [550 5.1.1 User unknown]',
        'Reporting-MTA:      <neko.example.jp>',
        'cat@example.jp:000000:<cat@example.jp> : 192.0.2.250 : neko.example.jp:[192.0.2.153] : 550 5.1.1 <cat@example.jp>... User Unknown  in RCPT TO',
        'Generating server: neko.example.jp',
        'Server di generazione: neko.example.jp',
        'Serveur de génération : neko.example.jp',
        'Genererande server: neko.example.jp',
        'neko.example.jp [192.0.2.25] did not like our RCPT TO: 550 5.1.1 <cat@example.jp>: Recipient address rejected: User unknown',
        'neko.example.jp [192.0.2.79] did not like our final DATA: 554 5.7.9 Message not accepted for policy reasons',
    ];

    for my $e ( @$hostnames0 ) {
        # Invalid hostnames
        is $Package->is_internethost($e), 0, '->is_internethost('.$e.') = 0';
    }

    for my $e ( @$hostnames1 ) {
        # Valid hostnames
        is $Package->is_internethost($e), 1, '->is_internethost('.$e.') = 1';
    }

    for my $e ( @$serversaid ) {
        # find() returns "neko.example.jp"
        my $v = $Package->find($e);
        is $v, "neko.example.jp", '->find('.$e.') = '.$v;
    }
}

done_testing;