Skip to content

Commit b4d2ecd

Browse files
committed
setup "dummy" OpenSSL::OPENSSL_LIBRARY_VERSION constant for compatibility
... this is now needed to run Ruby's 2.3 test suite due a check against the version
1 parent 126d868 commit b4d2ecd

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,31 +90,39 @@ public static void createOpenSSL(final Ruby runtime) {
9090
// OpenSSL::VERSION: "1.0.0"
9191
// OpenSSL::OPENSSL_VERSION: "OpenSSL 1.0.1c 10 May 2012"
9292
// OpenSSL::OPENSSL_VERSION_NUMBER: 268439615
93-
// MRI 1.9.3 / 2.1.2 :
93+
// MRI 1.9.3 / 2.2.3 :
9494
// OpenSSL::VERSION: "1.1.0"
9595
// OpenSSL::OPENSSL_VERSION: "OpenSSL 1.0.1f 6 Jan 2014"
9696
// OpenSSL::OPENSSL_VERSION_NUMBER: 268439663
97+
// OpenSSL::OPENSSL_LIBRARY_VERSION: ""OpenSSL 1.0.2d 9 Jul 2015"
98+
// OpenSSL::FIPS: false
9799

98100
final byte[] version = { '1','.','1','.','0' };
101+
final boolean ruby18 = runtime.getInstanceConfig().getCompatVersion() == CompatVersion.RUBY1_8;
102+
if ( ruby18 ) version[2] = '0'; // 1.0.0 compatible on 1.8
99103

100-
if ( runtime.getInstanceConfig().getCompatVersion() == CompatVersion.RUBY1_8 ) {
101-
version[2] = '0';
102-
} // 1.0.0 compatible on 1.8
103104
_OpenSSL.setConstant("VERSION", StringHelper.newString(runtime, version));
104105

105106
final RubyModule _Jopenssl = runtime.getModule("Jopenssl");
106107
final RubyModule _Version = (RubyModule) _Jopenssl.getConstantAt("Version");
107108
final RubyString jVERSION = _Version.getConstantAt("VERSION").asString();
108109

109110
final byte[] JRuby_OpenSSL_ = { 'J','R','u','b','y','-','O','p','e','n','S','S','L',' ' };
110-
final int OPENSSL_VERSION_NUMBER = 999999999; // 9469999 do smt useful with it ?
111+
final int OPENSSL_VERSION_NUMBER = 999999999; // NOTE: smt more useful?
111112

112113
ByteList OPENSSL_VERSION = new ByteList( jVERSION.getByteList().length() + JRuby_OpenSSL_.length );
113114
OPENSSL_VERSION.setEncoding( jVERSION.getEncoding() );
114115
OPENSSL_VERSION.append( JRuby_OpenSSL_ );
115116
OPENSSL_VERSION.append( jVERSION.getByteList() );
116-
_OpenSSL.setConstant("OPENSSL_VERSION", runtime.newString(OPENSSL_VERSION));
117+
118+
final RubyString VERSION;
119+
_OpenSSL.setConstant("OPENSSL_VERSION", VERSION = runtime.newString(OPENSSL_VERSION));
117120
_OpenSSL.setConstant("OPENSSL_VERSION_NUMBER", runtime.newFixnum(OPENSSL_VERSION_NUMBER));
121+
if ( ! ruby18 ) {
122+
// MRI 2.3 tests do: /\AOpenSSL +0\./ !~ OpenSSL::OPENSSL_LIBRARY_VERSION
123+
_OpenSSL.setConstant("OPENSSL_LIBRARY_VERSION", VERSION);
124+
_OpenSSL.setConstant("OPENSSL_FIPS", runtime.getFalse());
125+
}
118126
}
119127

120128
static RubyClass _OpenSSLError(final Ruby runtime) {

src/test/ruby/test_openssl.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def test_version
2323
assert_equal 0, OpenSSL::OPENSSL_VERSION.index('JRuby-OpenSSL ')
2424
end
2525
assert OpenSSL::OPENSSL_VERSION_NUMBER
26+
27+
if RUBY_VERSION > '2.0'
28+
# MRI 2.3 openssl/utils.rb does this (and we shall pass) :
29+
assert defined?(OpenSSL::OPENSSL_LIBRARY_VERSION)
30+
assert /\AOpenSSL +0\./ !~ OpenSSL::OPENSSL_LIBRARY_VERSION
31+
#puts "OpenSSL::OPENSSL_LIBRARY_VERSION = #{OpenSSL::OPENSSL_LIBRARY_VERSION.inspect}"
32+
end
2633
end
2734

2835
def test_debug

0 commit comments

Comments
 (0)