Mercurial > hg > nginx-tests
comparison lib/Test/Nginx/POP3.pm @ 1861:7b7b64569f55
Tests: reworked mail SSL tests to use IO::Socket::SSL.
Relevant infrastructure is provided in Test::Nginx::IMAP (and also POP3
and SMTP for completeness). This also ensures that SSL handshake and
various read operations are guarded with timeouts.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 18 May 2023 18:07:08 +0300 |
parents | 3629eda94c1b |
children | 6d3a8f4eb9b2 |
comparison
equal
deleted
inserted
replaced
1860:58951cf933e1 | 1861:7b7b64569f55 |
---|---|
18 | 18 |
19 sub new { | 19 sub new { |
20 my $self = {}; | 20 my $self = {}; |
21 bless $self, shift @_; | 21 bless $self, shift @_; |
22 | 22 |
23 $self->{_socket} = IO::Socket::INET->new( | 23 my $port = {@_}->{'SSL'} ? 8995 : 8110; |
24 Proto => "tcp", | |
25 PeerAddr => "127.0.0.1:" . port(8110), | |
26 @_ | |
27 ) | |
28 or die "Can't connect to nginx: $!\n"; | |
29 | 24 |
30 if ({@_}->{'SSL'}) { | 25 eval { |
31 require IO::Socket::SSL; | 26 local $SIG{ALRM} = sub { die "timeout\n" }; |
32 IO::Socket::SSL->start_SSL($self->{_socket}, @_) | 27 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
33 or die $IO::Socket::SSL::SSL_ERROR . "\n"; | 28 alarm(8); |
29 | |
30 $self->{_socket} = IO::Socket::INET->new( | |
31 Proto => "tcp", | |
32 PeerAddr => "127.0.0.1:" . port($port), | |
33 @_ | |
34 ) | |
35 or die "Can't connect to nginx: $!\n"; | |
36 | |
37 if ({@_}->{'SSL'}) { | |
38 require IO::Socket::SSL; | |
39 IO::Socket::SSL->start_SSL( | |
40 $self->{_socket}, | |
41 SSL_verify_mode => | |
42 IO::Socket::SSL::SSL_VERIFY_NONE(), | |
43 @_ | |
44 ) | |
45 or die $IO::Socket::SSL::SSL_ERROR . "\n"; | |
46 | |
47 my $s = $self->{_socket}; | |
48 log_in("ssl cipher: " . $s->get_cipher()); | |
49 log_in("ssl cert: " . $s->peer_certificate('issuer')); | |
50 } | |
51 | |
52 alarm(0); | |
53 }; | |
54 alarm(0); | |
55 if ($@) { | |
56 log_in("died: $@"); | |
34 } | 57 } |
35 | 58 |
36 $self->{_socket}->autoflush(1); | 59 $self->{_socket}->autoflush(1); |
37 $self->{_read_buffer} = ''; | 60 $self->{_read_buffer} = ''; |
38 | 61 |
39 return $self; | 62 return $self; |
63 } | |
64 | |
65 sub DESTROY { | |
66 my $self = shift; | |
67 $self->{_socket}->close(); | |
40 } | 68 } |
41 | 69 |
42 sub eof { | 70 sub eof { |
43 my $self = shift; | 71 my $self = shift; |
44 return $self->{_socket}->eof(); | 72 return $self->{_socket}->eof(); |
107 sub can_read { | 135 sub can_read { |
108 my ($self, $timo) = @_; | 136 my ($self, $timo) = @_; |
109 IO::Select->new($self->{_socket})->can_read($timo || 3); | 137 IO::Select->new($self->{_socket})->can_read($timo || 3); |
110 } | 138 } |
111 | 139 |
140 sub socket { | |
141 my ($self) = @_; | |
142 $self->{_socket}; | |
143 } | |
144 | |
112 ############################################################################### | 145 ############################################################################### |
113 | 146 |
114 sub pop3_test_daemon { | 147 sub pop3_test_daemon { |
115 my ($port) = @_; | 148 my ($port) = @_; |
116 | 149 |