Skip to content

Commit 5b38625

Browse files
committed
more ssl_version= compatibility fixes that match MRI (closing jruby/jruby#1736)
1 parent 24d4b5b commit 5b38625

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/main/java/org/jruby/ext/openssl/SSLContext.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import org.jruby.RubyModule;
5757
import org.jruby.RubyNumeric;
5858
import org.jruby.RubyObject;
59-
import org.jruby.RubyString;
59+
import org.jruby.RubySymbol;
6060
import org.jruby.anno.JRubyMethod;
6161
import org.jruby.common.IRubyWarnings.ID;
6262
import org.jruby.runtime.Arity;
@@ -474,16 +474,16 @@ else if ( ciphers instanceof RubyArray ) {
474474
@JRubyMethod(name = "ssl_version=")
475475
public IRubyObject set_ssl_version(IRubyObject version) {
476476
final String versionStr;
477-
if ( version instanceof RubyString ) {
478-
versionStr = version.asString().toString();
479-
} else {
477+
if ( version instanceof RubySymbol ) {
480478
versionStr = version.toString();
479+
} else {
480+
versionStr = version.convertToString().toString();
481481
}
482-
final String mapped = SSL_VERSION_OSSL2JSSE.get(versionStr);
483-
if ( mapped == null ) {
484-
throw newSSLError(getRuntime(), String.format("unknown SSL method `%s'.", versionStr));
482+
final String protocol = SSL_VERSION_OSSL2JSSE.get(versionStr);
483+
if ( protocol == null ) {
484+
throw getRuntime().newArgumentError("unknown SSL method `"+ versionStr +"'");
485485
}
486-
protocol = mapped;
486+
this.protocol = protocol;
487487
protocolForServer = ! versionStr.endsWith("_client");
488488
protocolForClient = ! versionStr.endsWith("_server");
489489
return version;

src/test/ruby/ssl/test_context.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,32 @@ class TestSSLContext < TestCase
66

77
def test_context_set_ssl_version
88
context = OpenSSL::SSL::SSLContext.new
9-
context.ssl_version = :"TLSv1_1"
9+
context.ssl_version = "TLSv1"
10+
11+
context = OpenSSL::SSL::SSLContext.new
12+
context.ssl_version = :SSLv3
13+
14+
context = OpenSSL::SSL::SSLContext.new
15+
context.ssl_version = :"TLSv1_1" unless RUBY_VERSION < '2.0'
1016
#assert_equal :TLSv1_1, context.ssl_version
1117

1218
context = OpenSSL::SSL::SSLContext.new
13-
context.ssl_version = "TLSv1_1"
19+
context.ssl_version = "TLSv1_1" unless RUBY_VERSION < '2.0'
1420

1521
context = OpenSSL::SSL::SSLContext.new
1622
context.ssl_version = "TLSv1.1" if defined? JRUBY_VERSION
1723

1824
context = OpenSSL::SSL::SSLContext.new
19-
context.ssl_version = :TLSv1_2
25+
context.ssl_version = :TLSv1_2 unless RUBY_VERSION < '2.0'
2026

2127
context = OpenSSL::SSL::SSLContext.new
2228
context.ssl_version = "TLSv1.2" if defined? JRUBY_VERSION
29+
30+
context = OpenSSL::SSL::SSLContext.new
31+
assert_raises ArgumentError do
32+
context.ssl_version = "TLSv42" # ArgumentError: unknown SSL method `TLSv42'
33+
end
34+
assert_raises(TypeError) { context.ssl_version = 12 }
2335
end
2436

2537
end

0 commit comments

Comments
 (0)