File: 00_pmilter.t

package info (click to toggle)
libsendmail-pmilter-perl 1.00-1.1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 184 kB
  • sloc: perl: 1,046; makefile: 48
file content (136 lines) | stat: -rw-r--r-- 3,901 bytes parent folder | download | duplicates (7)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#   $Header: /cvsroot/pmilter/pmilter/t/00_pmilter.t,v 1.4 2004/02/26 22:28:58 tvierling Exp $

#   Copyright (c) 2002-2004 Todd Vierling <tv@duh.org> <tv@pobox.com>
#   Copyright (c) 2004 Robert Casey <rob.casey@bluebottle.com>
#
#   This file is covered by the terms in the file COPYRIGHT supplied with this
#   software distribution.


BEGIN {

    use Test::More 'tests' => 55;

    use_ok('Sendmail::PMilter');
}


#   Perform some basic tests of the module constructor and available methods

can_ok(
        'Sendmail::PMilter',
                'auto_getconn',
                'auto_setconn',
                'get_max_interpreters',
                'get_max_requests',
                'get_sendmail_cf',
                'get_sendmail_class',
                'main',
                'new',
                'register',
                'setconn',
                'set_dispatcher',
                'set_listen',
                'set_sendmail_cf',
                'set_socket'
);

ok( my $milter = Sendmail::PMilter->new );
isa_ok( $milter, 'Sendmail::PMilter' );


#   Perform some tests on namespace symbols which should be defined within the 
#   Sendmail::PMilter namespace.  Not tested yet is the export of these symbols 
#   into the caller's namespace - TODO.

my %CONSTANTS = (

        'SMFIS_CONTINUE'    =>  100,
        'SMFIS_REJECT'      =>  101,
        'SMFIS_DISCARD'     =>  102,
        'SMFIS_ACCEPT'      =>  103,
        'SMFIS_TEMPFAIL'    =>  104,

        'SMFIF_ADDHDRS'     =>  0x01,
        'SMFIF_CHGBODY'     =>  0x02,
        'SMFIF_ADDRCPT'     =>  0x04,
        'SMFIF_DELRCPT'     =>  0x08,
        'SMFIF_CHGHDRS'     =>  0x10,
        'SMFIF_MODBODY'     =>  0x02,

        'SMFI_V1_ACTS'      =>  0x0F,
        'SMFI_V2_ACTS'      =>  0x1F,
        'SMFI_CURR_ACTS'    =>  0x1F
);

foreach my $constant (keys %CONSTANTS) {

    no strict 'refs';
    my $symbol = "Sendmail::PMilter::$constant"->();
    ok( defined $symbol, "Sendmail::PMilter::$constant" );
    SKIP: {

        skip("- Sendmail::PMilter::$constant not defined", 1) unless defined $symbol;
        is( $symbol, $CONSTANTS{$constant} );
    }
}


#   Of the module methods, the get_sendmail_cf function is tested first given 
#   the number of other methods dependent upon this method.  By default, this 
#   method should return the Sendmail configuration file as - 
#   '/etc/mail/sendmail.cf'.

ok( my $cf = $milter->get_sendmail_cf );
ok( defined $cf );
is( $cf, '/etc/mail/sendmail.cf' );


#   Test the corresponding set_sendmail_cf function by setting a new value for 
#   this parameter and then testing the return value from get_sendmail_cf

ok( $milter->set_sendmail_cf('t/files/sendmail.cf') );
is( $milter->get_sendmail_cf, 't/files/sendmail.cf' );
ok( $milter->set_sendmail_cf() );
is( $milter->get_sendmail_cf, '/etc/mail/sendmail.cf' );


#   Test the auto_getconn function using our own set of test sendmail 
#   configuration files - The first test should fail as a result of the name 
#   parameter not having been defined.

eval { $milter->auto_getconn() };
ok( defined $@ );

my @sockets = (
        'local:/var/run/milter.sock',
        'unix:/var/run/milter.sock',
        'inet:3333@localhost',
        'inet6:3333@localhost'
);
foreach my $index (0 .. 4) {

    my $cf = sprintf('t/files/sendmail%d.cf', $index);
    SKIP: {

        skip("- Missing file $cf", 3) unless -e $cf;
        ok( $milter->set_sendmail_cf($cf), $cf );
        my $socket = shift @sockets;
        ok( 
                ( ! defined $socket ) or 
                ( my $milter_socket = $milter->auto_getconn('test-milter') ) 
        );
        is( $milter_socket, $socket, defined $socket ? $socket : '(undef)' );


        #   Test the creation of the milter connection socket with the setconn function 
        #   for each of the test sendmail configuration files parsed.

    }
}


1;


__END__