From 8a56e4329da2137e82e91954d89cc336a9d4422c Mon Sep 17 00:00:00 2001 From: Mat Byczkowski Date: Mon, 25 Nov 2019 10:40:29 -0800 Subject: [PATCH] Bump supported Ruby versions - Bumped MRI Rubies to the ones that are still supported - Bumped JRuby to the last 2 releases. This required a change to how Java certificates are created in test (sun.security.x509.X509CertImpl can no longer be directly instantiated). --- .travis.yml | 16 ++++++++++------ lib/rails/auth/x509/filter/java.rb | 17 +++-------------- spec/rails/auth/x509/middleware_spec.rb | 5 +++-- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 47c466a..e220098 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,17 +5,21 @@ branches: - master before_install: - - gem install bundler + - gem uninstall bundler -a + - gem install bundler -v '~> 1.0' # pin to a 1.x release, otherwise 2.x is installed bundler_args: --without development rvm: - - 2.0.0 - - 2.1.10 - - 2.2.4 - - 2.3.0 + - 2.4 + - 2.5 + - 2.6 matrix: include: - - rvm: jruby-9.0.5.0 + - rvm: jruby-9.0 + env: JRUBY_OPTS="--debug" # for simplecov + - rvm: jruby-9.1 + env: JRUBY_OPTS="--debug" # for simplecov + - rvm: jruby env: JRUBY_OPTS="--debug" # for simplecov fast_finish: true diff --git a/lib/rails/auth/x509/filter/java.rb b/lib/rails/auth/x509/filter/java.rb index 0c017f9..c34235a 100644 --- a/lib/rails/auth/x509/filter/java.rb +++ b/lib/rails/auth/x509/filter/java.rb @@ -1,23 +1,12 @@ -require "java" -require "stringio" - module Rails module Auth module X509 module Filter - # Extract OpenSSL::X509::Certificates from Java's sun.security.x509.X509CertImpl + # Extract OpenSSL::X509::Certificates from java.security.cert.Certificate class Java def call(certs) - return unless certs - OpenSSL::X509::Certificate.new(extract_der(certs[0])).freeze - end - - private - - def extract_der(cert) - stringio = StringIO.new - cert.derEncode(stringio.to_outputstream) - stringio.string + return if certs.nil? || certs.empty? + OpenSSL::X509::Certificate.new(certs[0].get_encoded).freeze end end end diff --git a/spec/rails/auth/x509/middleware_spec.rb b/spec/rails/auth/x509/middleware_spec.rb index f73a614..4c0ae96 100644 --- a/spec/rails/auth/x509/middleware_spec.rb +++ b/spec/rails/auth/x509/middleware_spec.rb @@ -49,10 +49,11 @@ let(:java_cert) do ruby_cert = OpenSSL::X509::Certificate.new(valid_cert_pem) - Java::SunSecurityX509::X509CertImpl.new(ruby_cert.to_der.to_java_bytes) + java_cert_klass = java.security.cert::CertificateFactory.getInstance("X.509") + java_cert_klass.generateCertificate(java.io::ByteArrayInputStream.new(ruby_cert.to_der.to_java_bytes)) end - it "extracts Rails::Auth::Credential::X509 from a Java::SunSecurityX509::X509CertImpl" do + it "extracts Rails::Auth::Credential::X509 from a java.security.cert.Certificate" do skip "JRuby only" unless defined?(JRUBY_VERSION) _response, env = middleware.call(request.merge(example_key => [java_cert]))