[前][次][番号順一覧][スレッド一覧]

ruby-changes:44798

From: shugo <ko1@a...>
Date: Tue, 22 Nov 2016 14:17:51 +0900 (JST)
Subject: [ruby-changes:44798] shugo:r56871 (trunk): Add BufferedSSLSocket#send.

shugo	2016-11-22 14:17:45 +0900 (Tue, 22 Nov 2016)

  New Revision: 56871

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56871

  Log:
    Add BufferedSSLSocket#send.
    
    SSLSocket#send is not defined, so use #write instead.  flags and dest are
    ignored.

  Modified files:
    trunk/lib/net/ftp.rb
    trunk/test/net/ftp/test_ftp.rb
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 56870)
+++ test/net/ftp/test_ftp.rb	(revision 56871)
@@ -2069,6 +2069,59 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L2069
     end
   end
 
+  def test_abort_tls
+    commands = []
+    server = create_ftp_server { |sock|
+      sock.print("220 (test_ftp).\r\n")
+      commands.push(sock.gets)
+      sock.print("234 AUTH success.\r\n")
+      ctx = OpenSSL::SSL::SSLContext.new
+      ctx.ca_file = CA_FILE
+      ctx.key = File.open(SERVER_KEY) { |f|
+        OpenSSL::PKey::RSA.new(f)
+      }
+      ctx.cert = File.open(SERVER_CERT) { |f|
+        OpenSSL::X509::Certificate.new(f)
+      }
+      sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
+      sock.sync_close = true
+      sock.accept
+      commands.push(sock.gets)
+      sock.print("200 PSBZ success.\r\n")
+      commands.push(sock.gets)
+      sock.print("200 PROT success.\r\n")
+      commands.push(sock.gets)
+      sock.print("331 Please specify the password.\r\n")
+      commands.push(sock.gets)
+      sock.print("230 Login successful.\r\n")
+      commands.push(sock.gets)
+      sock.print("200 Switching to Binary mode.\r\n")
+      commands.push(sock.gets)
+      sock.print("225 No transfer to ABOR.\r\n")
+    }
+    begin
+      begin
+        ftp = Net::FTP.new("localhost",
+                           port: server.port,
+                           ssl: { ca_file: CA_FILE })
+        assert_equal("AUTH TLS\r\n", commands.shift)
+        assert_equal("PBSZ 0\r\n", commands.shift)
+        assert_equal("PROT P\r\n", commands.shift)
+        ftp.login
+        assert_match(/\AUSER /, commands.shift)
+        assert_match(/\APASS /, commands.shift)
+        assert_equal("TYPE I\r\n", commands.shift)
+        ftp.abort
+        assert_equal("ABOR\r\n", commands.shift)
+        assert_equal(nil, commands.shift)
+      ensure
+        ftp.close if ftp
+      end
+    ensure
+      server.close
+    end
+  end
+
   private
 
   def create_ftp_server(sleep_time = nil)
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 56870)
+++ lib/net/ftp.rb	(revision 56871)
@@ -1446,6 +1446,11 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L1446
           # SSL_shutdonw() will send the "close notify" alert to the peer,
           # so shutdown(2) should not be called.
         end
+
+        def send(mesg, flags, dest = nil)
+          # Ignore flags and dest.
+          @io.write(mesg)
+        end
       end
     end
     # :startdoc:

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]