@@ -5,7 +5,7 @@ using OpenSSL_jll
5
5
using Sockets
6
6
using Test
7
7
8
- include (" http_helpers.jl" )
8
+ include (joinpath ( dirname ( pathof (OpenSSL)), " ../test/ http_helpers.jl" ) )
9
9
10
10
macro catch_exception_object (code)
11
11
quote
@@ -15,7 +15,7 @@ macro catch_exception_object(code)
15
15
catch e
16
16
e
17
17
end
18
- if err == nothing
18
+ if err === nothing
19
19
error (" Expected exception, got $err ." )
20
20
end
21
21
err
177
177
@testset " HttpsConnect" begin
178
178
tcp_stream = connect (" www.nghttp2.org" , 443 )
179
179
180
- ssl_ctx = OpenSSL. SSLContext (OpenSSL. TLSv12ClientMethod ())
180
+ ssl_ctx = OpenSSL. SSLContext (OpenSSL. TLSClientMethod ())
181
181
result = OpenSSL. ssl_set_options (ssl_ctx, OpenSSL. SSL_OP_NO_COMPRESSION)
182
182
183
183
# Create SSL stream.
@@ -195,20 +195,20 @@ end
195
195
196
196
written = write (ssl, request_str)
197
197
198
+ @test ! eof (ssl)
198
199
io = IOBuffer ()
199
- while ! eof (ssl)
200
- write (io, readavailable (ssl))
201
- end
200
+ sleep (2 )
201
+ write (io, readavailable (ssl))
202
202
response = String (take! (io))
203
-
203
+ @test startswith (response, " HTTP/1.1 200 OK \r\n " )
204
204
close (ssl)
205
205
finalize (ssl_ctx)
206
206
end
207
207
208
208
@testset " ClosedStream" begin
209
209
tcp_stream = connect (" www.nghttp2.org" , 443 )
210
210
211
- ssl_ctx = OpenSSL. SSLContext (OpenSSL. TLSv12ClientMethod ())
211
+ ssl_ctx = OpenSSL. SSLContext (OpenSSL. TLSClientMethod ())
212
212
result = OpenSSL. ssl_set_options (ssl_ctx, OpenSSL. SSL_OP_NO_COMPRESSION)
213
213
OpenSSL. ssl_set_ciphersuites (ssl_ctx, " TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256" )
214
214
@@ -221,14 +221,12 @@ end
221
221
222
222
request_str = " GET / HTTP/1.1\r\n Host: www.nghttp2.org\r\n User-Agent: curl\r\n Accept: */*\r\n\r\n "
223
223
224
- err = @catch_exception_object unsafe_write (ssl, pointer (request_str), length (request_str))
225
- @test typeof (err) == Base. IOError
226
-
224
+ @test_throws ArgumentError unsafe_write (ssl, pointer (request_str), length (request_str))
227
225
finalize (ssl_ctx)
228
226
end
229
227
230
228
@testset " NoCloseStream" begin
231
- ssl_ctx = OpenSSL. SSLContext (OpenSSL. TLSv12ClientMethod ())
229
+ ssl_ctx = OpenSSL. SSLContext (OpenSSL. TLSClientMethod ())
232
230
result = OpenSSL. ssl_set_options (ssl_ctx, OpenSSL. SSL_OP_NO_COMPRESSION)
233
231
234
232
# Create SSL stream.
@@ -239,29 +237,18 @@ end
239
237
request_str = " GET / HTTP/1.1\r\n Host: www.nghttp2.org\r\n User-Agent: curl\r\n Accept: */*\r\n\r\n "
240
238
unsafe_write (ssl, pointer (request_str), length (request_str))
241
239
242
- response = read (ssl)
243
- @test contains (String (response), " HTTP/1.1 200 OK" )
240
+ @test ! eof (ssl)
241
+ io = IOBuffer ()
242
+ sleep (2 )
243
+ write (io, readavailable (ssl))
244
+ response = String (take! (io))
245
+ @test startswith (response, " HTTP/1.1 200 OK\r\n " )
244
246
245
247
# Do not close SSLStream, leave it to the finalizer.
246
248
# close(ssl)
247
249
# finalize(ssl_ctx)
248
250
end
249
251
250
- @testset " InvalidStream" begin
251
- ssl_ctx = OpenSSL. SSLContext (OpenSSL. TLSv12ClientMethod ())
252
- result = OpenSSL. ssl_set_options (ssl_ctx, OpenSSL. SSL_OP_NO_COMPRESSION)
253
-
254
- # Create SSL stream.
255
- tcp_stream = connect (" www.nghttp2.org" , 443 )
256
- ssl = SSLStream (ssl_ctx, tcp_stream, tcp_stream)
257
-
258
- err = @catch_exception_object read (ssl)
259
- @test typeof (err) == OpenSSL. OpenSSLError
260
-
261
- close (ssl)
262
- free (ssl_ctx)
263
- end
264
-
265
252
@testset " Hash" begin
266
253
res = digest (EvpMD5 (), IOBuffer (" The quick brown fox jumps over the lazy dog" ))
267
254
@test res == UInt8[0x9e , 0x10 , 0x7d , 0x9d , 0x37 , 0x2b , 0xb6 , 0x82 , 0x6b , 0xd8 , 0x1d , 0x35 , 0x42 , 0xa4 , 0x19 , 0xd6 ]
389
376
err_msg = OpenSSL. get_error ()
390
377
@test err_msg == " "
391
378
392
- ssl_ctx = OpenSSL. SSLContext (OpenSSL. TLSv12ServerMethod ())
379
+ ssl_ctx = OpenSSL. SSLContext (OpenSSL. TLSServerMethod ())
393
380
394
381
# Make direct invalid call to OpenSSL
395
382
invalid_cipher_suites = " TLS_AES_356_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256"
0 commit comments