Mercurial > hg > nginx-tests
comparison ssl_reject_handshake.t @ 1866:a797d7428fa5
Tests: simplified http SSL tests with IO::Socket::SSL.
The http SSL tests which previously used IO::Socket::SSL were converted
to use improved IO::Socket::SSL infrastructure in Test::Nginx.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 18 May 2023 18:07:19 +0300 |
parents | cdcd75657e52 |
children | c04134b0290b |
comparison
equal
deleted
inserted
replaced
1865:0e1865aa9b33 | 1866:a797d7428fa5 |
---|---|
134 | 134 |
135 ############################################################################### | 135 ############################################################################### |
136 | 136 |
137 sub get { | 137 sub get { |
138 my ($host, $port) = @_; | 138 my ($host, $port) = @_; |
139 my $s = get_ssl_socket($host, $port) or return $@; | 139 my $r = http( |
140 $host = 'localhost' if !defined $host; | 140 "GET / HTTP/1.0\nHost: " . ($host || 'localhost') . "\n\n", |
141 my $r = http(<<EOF, socket => $s); | 141 PeerAddr => '127.0.0.1:' . port($port), |
142 GET / HTTP/1.0 | 142 SSL => 1, |
143 Host: $host | 143 SSL_hostname => $host |
144 | 144 ) |
145 EOF | 145 or return "$@"; |
146 | |
147 $s->close(); | |
148 return $r; | 146 return $r; |
149 } | 147 } |
150 | 148 |
151 sub get_ssl_socket { | |
152 my ($host, $port) = @_; | |
153 my $s; | |
154 | |
155 eval { | |
156 local $SIG{ALRM} = sub { die "timeout\n" }; | |
157 local $SIG{PIPE} = sub { die "sigpipe\n" }; | |
158 alarm(8); | |
159 $s = IO::Socket::SSL->new( | |
160 Proto => 'tcp', | |
161 PeerAddr => '127.0.0.1', | |
162 PeerPort => port($port), | |
163 SSL_hostname => $host, | |
164 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(), | |
165 SSL_error_trap => sub { die $_[1] }, | |
166 ); | |
167 alarm(0); | |
168 }; | |
169 alarm(0); | |
170 | |
171 if ($@) { | |
172 log_in("died: $@"); | |
173 return undef; | |
174 } | |
175 | |
176 return $s; | |
177 } | |
178 | |
179 ############################################################################### | 149 ############################################################################### |