Skip to content

Commit 335c961

Browse files
committed
Tests: simplified stream SSL tests with IO::Socket::SSL.
The stream SSL tests which previously used IO::Socket::SSL were converted to use infrastructure in Test::Nginx::Stream where appropriate.
1 parent c47e641 commit 335c961

File tree

3 files changed

+19
-58
lines changed

3 files changed

+19
-58
lines changed

stream_ssl_alpn.t

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,12 @@ like($t->read_file('test.log'), qr/500$/, 'alpn mismatch - log');
100100

101101
sub get_ssl {
102102
my (@alpn) = @_;
103-
my $s = stream('127.0.0.1:' . port(8080));
104-
105-
eval {
106-
local $SIG{ALRM} = sub { die "timeout\n" };
107-
local $SIG{PIPE} = sub { die "sigpipe\n" };
108-
alarm(8);
109-
IO::Socket::SSL->start_SSL($s->{_socket},
110-
SSL_alpn_protocols => [ @alpn ],
111-
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
112-
SSL_error_trap => sub { die $_[1] }
113-
);
114-
alarm(0);
115-
};
116-
alarm(0);
117-
118-
if ($@) {
119-
log_in("died: $@");
120-
return undef;
121-
}
103+
104+
my $s = stream(
105+
PeerAddr => '127.0.0.1:' . port(8080),
106+
SSL => 1,
107+
SSL_alpn_protocols => [ @alpn ]
108+
);
122109

123110
return $s->read();
124111
}

stream_ssl_preread.t

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ is(get_ssl('bar', 8081), $p2, 'sni 2 again');
142142

143143
is(get_ssl('', 8081), $p3, 'no sni');
144144
is(get_ssl('foo', 8082), $p3, 'preread off');
145-
is(get_ssl('foo', 8083), undef, 'preread buffer full');
145+
is(get_ssl('foo', 8083), '', 'preread buffer full');
146146
is(stream('127.0.0.1:' . port(8080))->io('x' x 1000), "127.0.0.1:$p3",
147147
'not a handshake');
148148

@@ -202,25 +202,12 @@ sub get_oldver {
202202

203203
sub get_ssl {
204204
my ($host, $port) = @_;
205-
my $s = stream('127.0.0.1:' . port($port));
206-
207-
eval {
208-
local $SIG{ALRM} = sub { die "timeout\n" };
209-
local $SIG{PIPE} = sub { die "sigpipe\n" };
210-
alarm(8);
211-
IO::Socket::SSL->start_SSL($s->{_socket},
212-
SSL_hostname => $host,
213-
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
214-
SSL_error_trap => sub { die $_[1] }
215-
);
216-
alarm(0);
217-
};
218-
alarm(0);
219-
220-
if ($@) {
221-
log_in("died: $@");
222-
return undef;
223-
}
205+
206+
my $s = stream(
207+
PeerAddr => '127.0.0.1:' . port($port),
208+
SSL => 1,
209+
SSL_hostname => $host
210+
);
224211

225212
return $s->read();
226213
}

stream_ssl_preread_alpn.t

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,12 @@ get_ssl(8081, '');
114114

115115
sub get_ssl {
116116
my ($port, @alpn) = @_;
117-
my $s = stream('127.0.0.1:' . port($port));
118-
119-
eval {
120-
local $SIG{ALRM} = sub { die "timeout\n" };
121-
local $SIG{PIPE} = sub { die "sigpipe\n" };
122-
alarm(8);
123-
IO::Socket::SSL->start_SSL($s->{_socket},
124-
SSL_alpn_protocols => [ @alpn ],
125-
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
126-
SSL_error_trap => sub { die $_[1] }
127-
);
128-
alarm(0);
129-
};
130-
alarm(0);
131-
132-
if ($@) {
133-
log_in("died: $@");
134-
return undef;
135-
}
117+
118+
my $s = stream(
119+
PeerAddr => '127.0.0.1:' . port($port),
120+
SSL => 1,
121+
SSL_alpn_protocols => [ @alpn ]
122+
);
136123

137124
return $s->read();
138125
}

0 commit comments

Comments
 (0)