Skip to content

Commit 488d1d3

Browse files
committed
Tests: simplified using IO::Socket::SSL in h3_server_name.t.
See a797d7428fa5 for further details.
1 parent 791bcd0 commit 488d1d3

File tree

1 file changed

+10
-38
lines changed

1 file changed

+10
-38
lines changed

h3_server_name.t

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ http {
4747
ssl_certificate localhost.crt;
4848
4949
server {
50-
listen 127.0.0.1:8080 ssl http2;
50+
listen 127.0.0.1:8443 ssl http2;
5151
listen 127.0.0.1:%%PORT_8980_UDP%% quic;
5252
server_name ~^(?P<name>.+)\.example\.com$;
5353
@@ -97,19 +97,20 @@ is(get3('test.example.com', 'localhost'), 'test', 'http3 - sni not found');
9797

9898
sub get1 {
9999
my ($host, $sni) = @_;
100-
my $s = get_ssl_socket(sni => $sni || $host, alpn => ['http/1.1']);
101-
http(<<EOF, socket => $s) =~ /.*?\x0d\x0a?\x0d\x0a?(.*)/ms;
102-
GET / HTTP/1.1
103-
Host: $host
104-
Connection: close
105-
106-
EOF
100+
http("GET / HTTP/1.0\nHost: $host\n\n",
101+
SSL => 1,
102+
SSL_hostname => $sni || $host,
103+
SSL_alpn_protocols => ['http/1.1'])
104+
=~ /.*?\x0d\x0a?\x0d\x0a?(.*)/ms;
107105
return $1;
108106
}
109107

110108
sub get2 {
111109
my ($host, $sni) = @_;
112-
my $sock = get_ssl_socket(sni => $sni || $host, alpn => ['h2']);
110+
my $sock = http('', start => 1,
111+
SSL => 1,
112+
SSL_hostname => $sni || $host,
113+
SSL_alpn_protocols => ['h2']);
113114
my $s = Test::Nginx::HTTP2->new(undef, socket => $sock);
114115
my $sid = $s->new_stream({ host => $host });
115116
my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
@@ -128,33 +129,4 @@ sub get3 {
128129
return $frame->{data};
129130
}
130131

131-
sub get_ssl_socket {
132-
my (%extra) = @_;
133-
my $s;
134-
135-
eval {
136-
local $SIG{ALRM} = sub { die "timeout\n" };
137-
local $SIG{PIPE} = sub { die "sigpipe\n" };
138-
alarm(8);
139-
$s = IO::Socket::SSL->new(
140-
Proto => 'tcp',
141-
PeerAddr => '127.0.0.1',
142-
PeerPort => port(8080),
143-
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
144-
SSL_hostname => $extra{sni},
145-
SSL_alpn_protocols => $extra{alpn},
146-
SSL_error_trap => sub { die $_[1] }
147-
);
148-
alarm(0);
149-
};
150-
alarm(0);
151-
152-
if ($@) {
153-
log_in("died: $@");
154-
return undef;
155-
}
156-
157-
return $s;
158-
}
159-
160132
###############################################################################

0 commit comments

Comments
 (0)