Mercurial > hg > nginx-tests
annotate lib/Test/Nginx/POP3.pm @ 1911:2c5ae1e75db4
Tests: tests for TLSv1.3 ciphers in QUIC connections.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 13 Jun 2023 18:43:10 +0400 |
parents | 7b7b64569f55 |
children | 6d3a8f4eb9b2 |
rev | line source |
---|---|
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 package Test::Nginx::POP3; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Module for nginx pop3 tests. |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More qw//; |
1244
575d39cc0e35
Tests: worker_shutdown_timeout within the mail module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
969
diff
changeset
|
13 use IO::Select; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 use IO::Socket; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 use Socket qw/ CRLF /; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
540
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
19 sub new { |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
20 my $self = {}; |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
21 bless $self, shift @_; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
1861
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
23 my $port = {@_}->{'SSL'} ? 8995 : 8110; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
24 |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
25 eval { |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
26 local $SIG{ALRM} = sub { die "timeout\n" }; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
27 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
28 alarm(8); |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
29 |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
30 $self->{_socket} = IO::Socket::INET->new( |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
31 Proto => "tcp", |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
32 PeerAddr => "127.0.0.1:" . port($port), |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
33 @_ |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
34 ) |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
35 or die "Can't connect to nginx: $!\n"; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
1861
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
37 if ({@_}->{'SSL'}) { |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
38 require IO::Socket::SSL; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
39 IO::Socket::SSL->start_SSL( |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
40 $self->{_socket}, |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
41 SSL_verify_mode => |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
42 IO::Socket::SSL::SSL_VERIFY_NONE(), |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
43 @_ |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
44 ) |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
45 or die $IO::Socket::SSL::SSL_ERROR . "\n"; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
46 |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
47 my $s = $self->{_socket}; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
48 log_in("ssl cipher: " . $s->get_cipher()); |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
49 log_in("ssl cert: " . $s->peer_certificate('issuer')); |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
50 } |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
51 |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
52 alarm(0); |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
53 }; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
54 alarm(0); |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
55 if ($@) { |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
56 log_in("died: $@"); |
540
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
57 } |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
58 |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
59 $self->{_socket}->autoflush(1); |
1678
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
60 $self->{_read_buffer} = ''; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 return $self; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
1861
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
65 sub DESTROY { |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
66 my $self = shift; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
67 $self->{_socket}->close(); |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
68 } |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
69 |
540
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
70 sub eof { |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
71 my $self = shift; |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
72 return $self->{_socket}->eof(); |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
73 } |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
74 |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
75 sub print { |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
76 my ($self, $cmd) = @_; |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
77 log_out($cmd); |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
78 $self->{_socket}->print($cmd); |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
79 } |
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
80 |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 sub send { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 my ($self, $cmd) = @_; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 log_out($cmd); |
540
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
84 $self->{_socket}->print($cmd . CRLF); |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 |
1678
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
87 sub getline { |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
88 my ($self) = @_; |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
89 my $socket = $self->{_socket}; |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
90 |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
91 if ($self->{_read_buffer} =~ /^(.*?\x0a)(.*)/ms) { |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
92 $self->{_read_buffer} = $2; |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
93 return $1; |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
94 } |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
95 |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
96 while (IO::Select->new($socket)->can_read(8)) { |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
97 $socket->blocking(0); |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
98 my $n = $socket->sysread(my $buf, 1024); |
1825
3629eda94c1b
Tests: handling of EWOULDBLOCK from sysread() with IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1678
diff
changeset
|
99 my $again = !defined $n && $!{EWOULDBLOCK}; |
1678
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
100 $socket->blocking(1); |
1825
3629eda94c1b
Tests: handling of EWOULDBLOCK from sysread() with IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1678
diff
changeset
|
101 next if $again; |
1678
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
102 last unless $n; |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
103 |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
104 $self->{_read_buffer} .= $buf; |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
105 |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
106 if ($self->{_read_buffer} =~ /^(.*?\x0a)(.*)/ms) { |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
107 $self->{_read_buffer} = $2; |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
108 return $1; |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
109 } |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
110 }; |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
111 } |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
112 |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 sub read { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 my ($self) = @_; |
540
481d705b8610
Tests: SSL support in mail backends.
Sergey Kandaurov <pluknet@nginx.com>
parents:
539
diff
changeset
|
115 my $socket = $self->{_socket}; |
1678
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
116 |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
117 while (defined($_ = $self->getline())) { |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
118 log_in($_); |
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
119 last; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 } |
1678
d0025a0dead7
Tests: better timeout handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1423
diff
changeset
|
121 |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 return $_; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
123 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 sub check { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 my ($self, $regex, $name) = @_; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 Test::More->builder->like($self->read(), $regex, $name); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
130 sub ok { |
243
de7338227832
Tests: removed trailing spaces.
Homutov Vladimir <vl@nginx.com>
parents:
209
diff
changeset
|
131 my $self = shift; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
132 Test::More->builder->like($self->read(), qr/^\+OK/, @_); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
133 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
134 |
1244
575d39cc0e35
Tests: worker_shutdown_timeout within the mail module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
969
diff
changeset
|
135 sub can_read { |
575d39cc0e35
Tests: worker_shutdown_timeout within the mail module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
969
diff
changeset
|
136 my ($self, $timo) = @_; |
575d39cc0e35
Tests: worker_shutdown_timeout within the mail module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
969
diff
changeset
|
137 IO::Select->new($self->{_socket})->can_read($timo || 3); |
575d39cc0e35
Tests: worker_shutdown_timeout within the mail module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
969
diff
changeset
|
138 } |
575d39cc0e35
Tests: worker_shutdown_timeout within the mail module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
969
diff
changeset
|
139 |
1861
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
140 sub socket { |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
141 my ($self) = @_; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
142 $self->{_socket}; |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
143 } |
7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1825
diff
changeset
|
144 |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
145 ############################################################################### |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
146 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
147 sub pop3_test_daemon { |
951
9361c7eddfc1
Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
540
diff
changeset
|
148 my ($port) = @_; |
9361c7eddfc1
Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
540
diff
changeset
|
149 |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
150 my $server = IO::Socket::INET->new( |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
151 Proto => 'tcp', |
969
1edb092149e2
Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
951
diff
changeset
|
152 LocalAddr => '127.0.0.1:' . ($port || port(8111)), |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
153 Listen => 5, |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
154 Reuse => 1 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
155 ) |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
156 or die "Can't create listening socket: $!\n"; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
157 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
158 while (my $client = $server->accept()) { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
159 $client->autoflush(1); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
160 print $client "+OK fake pop3 server ready" . CRLF; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
161 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
162 while (<$client>) { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
163 if (/^quit/i) { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
164 print $client '+OK quit ok' . CRLF; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
165 } elsif (/^user test\@example.com/i) { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
166 print $client '+OK user ok' . CRLF; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
167 } elsif (/^pass secret/i) { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
168 print $client '+OK pass ok' . CRLF; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
169 } else { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
170 print $client "-ERR unknown command" . CRLF; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
171 } |
539
3fcad5e66735
Tests: whitespace fixes in mail modules.
Sergey Kandaurov <pluknet@nginx.com>
parents:
526
diff
changeset
|
172 } |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
173 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
174 close $client; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
175 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
176 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
177 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
178 ############################################################################### |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
180 1; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
182 ############################################################################### |