File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,14 @@ def consume_rbuff(size=nil)
101101
102102 public
103103
104+ # call-seq:
105+ # ssl.getbyte => 81
106+ #
107+ # Get the next 8bit byte from `ssl`. Returns `nil` on EOF
108+ def getbyte
109+ read ( 1 ) &.ord
110+ end
111+
104112 ##
105113 # Reads _size_ bytes from the stream. If _buf_ is provided it must
106114 # reference a string which will receive the data.
Original file line number Diff line number Diff line change @@ -492,4 +492,44 @@ def test_cert_verify_expired0_lets_encrypt # base_line
492492 assert_equal 'unable to get issuer certificate' , cert_store . error_string
493493 end
494494
495+ def test_getbyte
496+ start_server ( OpenSSL ::SSL ::VERIFY_NONE , true ) { |_ , port |
497+ server_connect ( port ) { |ssl |
498+ str = +( "x" * 100 + "\n " )
499+ ssl . syswrite ( str )
500+ newstr = str . bytesize . times . map { |i |
501+ ssl . getbyte
502+ } . pack ( "C*" )
503+ assert_equal ( str , newstr )
504+ }
505+ }
506+ end
507+
508+ def test_sync_close
509+ start_server ( OpenSSL ::SSL ::VERIFY_NONE , true ) do |_ , port |
510+ begin
511+ sock = TCPSocket . new ( "127.0.0.1" , port )
512+ ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
513+ ssl . connect
514+ ssl . puts "abc" ; assert_equal "abc\n " , ssl . gets
515+ ssl . close
516+ assert_not_predicate sock , :closed?
517+ ensure
518+ sock &.close
519+ end
520+
521+ begin
522+ sock = TCPSocket . new ( "127.0.0.1" , port )
523+ ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
524+ ssl . sync_close = true # !!
525+ ssl . connect
526+ ssl . puts "abc" ; assert_equal "abc\n " , ssl . gets
527+ ssl . close
528+ assert_predicate sock , :closed?
529+ ensure
530+ sock &.close
531+ end
532+ end
533+ end
534+
495535end
You can’t perform that action at this time.
0 commit comments