@@ -219,11 +219,11 @@ def test_server_session_cache
219
219
# deadlock.
220
220
TEST_SESSION_REMOVE_CB = ENV [ "OSSL_TEST_ALL" ] == "1"
221
221
222
- def test_ctx_client_session_cb
223
- ctx_proc = proc { |ctx | ctx . ssl_version = :TLSv1_2 }
224
- start_server ( ctx_proc : ctx_proc ) do |port |
222
+ def test_ctx_client_session_cb_tls12
223
+ start_server do |port |
225
224
called = { }
226
225
ctx = OpenSSL ::SSL ::SSLContext . new
226
+ ctx . min_version = ctx . max_version = :TLS1_2
227
227
ctx . session_cache_mode = OpenSSL ::SSL ::SSLContext ::SESSION_CACHE_CLIENT
228
228
ctx . session_new_cb = lambda { |ary |
229
229
sock , sess = ary
@@ -233,23 +233,66 @@ def test_ctx_client_session_cb
233
233
ctx . session_remove_cb = lambda { |ary |
234
234
ctx , sess = ary
235
235
called [ :remove ] = [ ctx , sess ]
236
- # any resulting value is OK (ignored)
237
236
}
238
237
end
239
238
240
239
server_connect_with_session ( port , ctx , nil ) { |ssl |
241
240
assert_equal ( 1 , ctx . session_cache_stats [ :cache_num ] )
242
241
assert_equal ( 1 , ctx . session_cache_stats [ :connect_good ] )
243
242
assert_equal ( [ ssl , ssl . session ] , called [ :new ] )
244
- assert ( ctx . session_remove ( ssl . session ) )
245
- assert ( ! ctx . session_remove ( ssl . session ) )
243
+ assert_equal ( true , ctx . session_remove ( ssl . session ) )
244
+ assert_equal ( false , ctx . session_remove ( ssl . session ) )
246
245
if TEST_SESSION_REMOVE_CB
247
246
assert_equal ( [ ctx , ssl . session ] , called [ :remove ] )
248
247
end
249
248
}
250
249
end
251
250
end
252
251
252
+ def test_ctx_client_session_cb_tls13
253
+ omit "TLS 1.3 not supported" unless tls13_supported?
254
+ omit "LibreSSL does not call session_new_cb in TLS 1.3" if libressl?
255
+
256
+ start_server do |port |
257
+ called = { }
258
+ ctx = OpenSSL ::SSL ::SSLContext . new
259
+ ctx . min_version = :TLS1_3
260
+ ctx . session_cache_mode = OpenSSL ::SSL ::SSLContext ::SESSION_CACHE_CLIENT
261
+ ctx . session_new_cb = lambda { |ary |
262
+ sock , sess = ary
263
+ called [ :new ] = [ sock , sess ]
264
+ }
265
+
266
+ server_connect_with_session ( port , ctx , nil ) { |ssl |
267
+ ssl . puts ( "abc" ) ; assert_equal ( "abc\n " , ssl . gets )
268
+
269
+ assert_operator ( 1 , :<= , ctx . session_cache_stats [ :cache_num ] )
270
+ assert_operator ( 1 , :<= , ctx . session_cache_stats [ :connect_good ] )
271
+ assert_equal ( [ ssl , ssl . session ] , called [ :new ] )
272
+ }
273
+ end
274
+ end
275
+
276
+ def test_ctx_client_session_cb_tls13_exception
277
+ omit "TLS 1.3 not supported" unless tls13_supported?
278
+ omit "LibreSSL does not call session_new_cb in TLS 1.3" if libressl?
279
+
280
+ start_server do |port |
281
+ ctx = OpenSSL ::SSL ::SSLContext . new
282
+ ctx . min_version = :TLS1_3
283
+ ctx . session_cache_mode = OpenSSL ::SSL ::SSLContext ::SESSION_CACHE_CLIENT
284
+ ctx . session_new_cb = lambda { |ary |
285
+ raise "in session_new_cb"
286
+ }
287
+
288
+ server_connect_with_session ( port , ctx , nil ) { |ssl |
289
+ assert_raise_with_message ( RuntimeError , /in session_new_cb/ ) {
290
+ ssl . puts ( "abc" ) ; assert_equal ( "abc\n " , ssl . gets )
291
+ }
292
+ }
293
+ end
294
+ end
295
+
253
296
def test_ctx_server_session_cb
254
297
connections = nil
255
298
called = { }
0 commit comments