Skip to content

Commit 93a564d

Browse files
committed
ssl: prefer SSLContext#max_version= in tests
Avoid using the deprecated OpenSSL::SSL::SSLContext#ssl_version= outside the tests specifically written for it.
1 parent 637ba65 commit 93a564d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

test/openssl/test_ssl.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,15 @@ def test_sslctx_set_params
645645

646646
def test_post_connect_check_with_anon_ciphers
647647
ctx_proc = -> ctx {
648-
ctx.ssl_version = :TLSv1_2
648+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
649649
ctx.ciphers = "aNULL"
650650
ctx.tmp_dh = Fixtures.pkey("dh-1")
651651
ctx.security_level = 0
652652
}
653653

654654
start_server(ctx_proc: ctx_proc) { |port|
655655
ctx = OpenSSL::SSL::SSLContext.new
656-
ctx.ssl_version = :TLSv1_2
656+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
657657
ctx.ciphers = "aNULL"
658658
ctx.security_level = 0
659659
server_connect(port, ctx) { |ssl|
@@ -1688,12 +1688,12 @@ def test_sync_close_without_connect
16881688
def test_get_ephemeral_key
16891689
# kRSA
16901690
ctx_proc1 = proc { |ctx|
1691-
ctx.ssl_version = :TLSv1_2
1691+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
16921692
ctx.ciphers = "kRSA"
16931693
}
16941694
start_server(ctx_proc: ctx_proc1, ignore_listener_error: true) do |port|
16951695
ctx = OpenSSL::SSL::SSLContext.new
1696-
ctx.ssl_version = :TLSv1_2
1696+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
16971697
ctx.ciphers = "kRSA"
16981698
begin
16991699
server_connect(port, ctx) { |ssl| assert_nil ssl.tmp_key }
@@ -1704,15 +1704,15 @@ def test_get_ephemeral_key
17041704
end
17051705

17061706
# DHE
1707-
# TODO: How to test this with TLS 1.3?
1707+
# TODO: SSL_CTX_set1_groups() is required for testing this with TLS 1.3
17081708
ctx_proc2 = proc { |ctx|
1709-
ctx.ssl_version = :TLSv1_2
1709+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
17101710
ctx.ciphers = "EDH"
17111711
ctx.tmp_dh = Fixtures.pkey("dh-1")
17121712
}
17131713
start_server(ctx_proc: ctx_proc2) do |port|
17141714
ctx = OpenSSL::SSL::SSLContext.new
1715-
ctx.ssl_version = :TLSv1_2
1715+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
17161716
ctx.ciphers = "EDH"
17171717
server_connect(port, ctx) { |ssl|
17181718
assert_instance_of OpenSSL::PKey::DH, ssl.tmp_key

test/openssl/test_ssl_session.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
class OpenSSL::TestSSLSession < OpenSSL::SSLTestCase
77
def test_session
8-
ctx_proc = proc { |ctx| ctx.ssl_version = :TLSv1_2 }
8+
ctx_proc = proc { |ctx|
9+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
10+
}
911
start_server(ctx_proc: ctx_proc) do |port|
1012
server_connect_with_session(port, nil, nil) { |ssl|
1113
session = ssl.session
@@ -143,7 +145,7 @@ def test_resumption
143145

144146
def test_server_session_cache
145147
ctx_proc = Proc.new do |ctx|
146-
ctx.ssl_version = :TLSv1_2
148+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
147149
ctx.options |= OpenSSL::SSL::OP_NO_TICKET
148150
end
149151

@@ -197,7 +199,7 @@ def test_server_session_cache
197199
10.times do |i|
198200
connections = i
199201
cctx = OpenSSL::SSL::SSLContext.new
200-
cctx.ssl_version = :TLSv1_2
202+
cctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
201203
server_connect_with_session(port, cctx, first_session) { |ssl|
202204
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
203205
first_session ||= ssl.session
@@ -299,11 +301,11 @@ def test_ctx_server_session_cb
299301
connections = nil
300302
called = {}
301303
cctx = OpenSSL::SSL::SSLContext.new
302-
cctx.ssl_version = :TLSv1_2
304+
cctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
303305
sctx = nil
304306
ctx_proc = Proc.new { |ctx|
305307
sctx = ctx
306-
ctx.ssl_version = :TLSv1_2
308+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
307309
ctx.options |= OpenSSL::SSL::OP_NO_TICKET
308310

309311
# get_cb is called whenever a client proposed to resume a session but

0 commit comments

Comments
 (0)