comparison ssl_certificate_chain.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 0b5ec15c62ed
comparison
equal deleted inserted replaced
1865:0e1865aa9b33 1866:a797d7428fa5
131 131
132 $t->run(); 132 $t->run();
133 133
134 ############################################################################### 134 ###############################################################################
135 135
136 is(get_ssl_socket(port(8080)), undef, 'incomplete chain'); 136 ok(!get_ssl_socket(8080), 'incomplete chain');
137 ok(get_ssl_socket(port(8081)), 'intermediate'); 137 ok(get_ssl_socket(8081), 'intermediate');
138 ok(get_ssl_socket(port(8082)), 'intermediate server'); 138 ok(get_ssl_socket(8082), 'intermediate server');
139 139
140 ############################################################################### 140 ###############################################################################
141 141
142 sub get_ssl_socket { 142 sub get_ssl_socket {
143 my ($port) = @_; 143 my ($port) = @_;
144 my ($s, $verify); 144 my ($verify);
145 145
146 eval { 146 http(
147 local $SIG{ALRM} = sub { die "timeout\n" }; 147 '', PeerAddr => '127.0.0.1:' . port($port), start => 1,
148 local $SIG{PIPE} = sub { die "sigpipe\n" }; 148 SSL => 1,
149 alarm(8); 149 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
150 $s = IO::Socket::SSL->new( 150 SSL_ca_file => "$d/root.crt",
151 Proto => 'tcp', 151 SSL_verify_callback => sub {
152 PeerAddr => '127.0.0.1', 152 my ($ok) = @_;
153 PeerPort => $port, 153 $verify = $ok;
154 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(), 154 return $ok;
155 SSL_ca_file => "$d/root.crt", 155 }
156 SSL_verify_callback => sub { 156 );
157 my ($ok) = @_;
158 $verify = $ok;
159 return $ok;
160 },
161 SSL_error_trap => sub { die $_[1] }
162 );
163 alarm(0);
164 };
165 alarm(0);
166
167 if ($@) {
168 log_in("died: $@");
169 return undef;
170 }
171 157
172 return $verify; 158 return $verify;
173 } 159 }
174 160
175 ############################################################################### 161 ###############################################################################