Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby-openssl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dcf4bf328b5b
Choose a base ref
...
head repository: jruby/jruby-openssl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 42241cd0a80a
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Dec 21, 2015

  1. Copy the full SHA
    6a95403 View commit details
  2. Copy the full SHA
    42241cd View commit details
Showing with 48 additions and 7 deletions.
  1. +5 −7 src/main/java/org/jruby/ext/openssl/SSLSocket.java
  2. +14 −0 src/test/ruby/ssl/test_helper.rb
  3. +29 −0 src/test/ruby/ssl/test_socket.rb
12 changes: 5 additions & 7 deletions src/main/java/org/jruby/ext/openssl/SSLSocket.java
Original file line number Diff line number Diff line change
@@ -795,6 +795,7 @@ public IRubyObject sysread_nonblock(ThreadContext context, IRubyObject len) {
@JRubyMethod
public IRubyObject sysread_nonblock(ThreadContext context, IRubyObject len, IRubyObject arg) {
if ( arg instanceof RubyHash ) { // exception: false
// NOTE: on Ruby 2.3 this is expected to raise a TypeError (but not on 2.2)
return sysreadImpl(context, len, null, false, getExceptionOpt(context, arg));
}
return sysreadImpl(context, len, arg, false, true); // buffer arg
@@ -883,12 +884,11 @@ private void forceClose() {
close(true);
}

//private boolean closed;

private void close(boolean force) {
//closed = true;

if ( engine == null ) throw getRuntime().newEOFError();
if ( engine == null ) {
// if ( force ) throw getRuntime().newEOFError();
return;
}

engine.closeOutbound();

@@ -903,8 +903,6 @@ private void close(boolean force) {
}
}

//final boolean isClosed() { return closed; }

@JRubyMethod
public IRubyObject sysclose(final ThreadContext context) {
//if ( isClosed() ) return context.runtime.getNil();
14 changes: 14 additions & 0 deletions src/test/ruby/ssl/test_helper.rb
Original file line number Diff line number Diff line change
@@ -127,6 +127,20 @@ def server_loop(context, server, server_proc)
rescue Errno::EBADF, IOError, Errno::EINVAL, Errno::ECONNABORTED, Errno::ENOTSOCK, Errno::ECONNRESET
end

def server_connect(port, ctx = nil)
sock = TCPSocket.new('127.0.0.1', port)
ssl = ctx ? OpenSSL::SSL::SSLSocket.new(sock, ctx) : OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
ssl.connect
yield ssl if block_given?
ensure
if ssl
ssl.close
elsif sock
sock.close
end
end

def starttls(ssl)
ssl.puts("STARTTLS")
#sleep 1 # When this line is eliminated, process on Cygwin blocks
29 changes: 29 additions & 0 deletions src/test/ruby/ssl/test_socket.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: false
require File.expand_path('test_helper', File.dirname(__FILE__))

class TestSSLSocket < TestCase
@@ -42,4 +43,32 @@ def test_attr_methods
socket.inspect
end

def test_sync_close_without_connect
require 'socket'
Socket.open(:INET, :STREAM) do |socket|
assert ! socket.closed?
ssl = OpenSSL::SSL::SSLSocket.new(socket)
ssl.sync_close = true
assert ! ssl.closed?
ssl.close
assert socket.closed?
end
end

include SSLTestHelper

def test_ssl_sysread_blocking_error
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true) do |server, port|
server_connect(port) do |ssl|
ssl.write("abc\n")
# assert_raise(TypeError) { ssl.sysread(4, exception: false) }
buf = ''
assert_raise(ArgumentError) { ssl.sysread(4, buf, exception: false) }
assert_equal '', buf
assert_equal buf.object_id, ssl.sysread(4, buf).object_id
assert_equal "abc\n", buf
end
end
end if RUBY_VERSION > '2.0'

end