ruby-changes:47635
From: rhe <ko1@a...>
Date: Tue, 5 Sep 2017 18:48:04 +0900 (JST)
Subject: [ruby-changes:47635] rhe:r59751 (trunk): openssl: merge test fixes from upstream
rhe 2017-09-05 18:47:59 +0900 (Tue, 05 Sep 2017) New Revision: 59751 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59751 Log: openssl: merge test fixes from upstream Fix platform-dependent or fragile test cases added by r59734. This is a combined patch of the three commits below: 4fc17977350a test/test_fips: skip if setting FIPS mode fails b25179fbeebf test/test_asn1: fix possible failure in test_utctime 8ed81ff4b0a8 test/test_pair: fix test_write_nonblock{,_no_exceptions} Modified files: trunk/test/openssl/test_asn1.rb trunk/test/openssl/test_fips.rb trunk/test/openssl/test_pair.rb Index: test/openssl/test_fips.rb =================================================================== --- test/openssl/test_fips.rb (revision 59750) +++ test/openssl/test_fips.rb (revision 59751) @@ -10,13 +10,20 @@ class OpenSSL::TestFIPS < OpenSSL::TestC https://github.com/ruby/ruby/blob/trunk/test/openssl/test_fips.rb#L10 end def test_fips_mode_get - if OpenSSL::OPENSSL_FIPS - OpenSSL.fips_mode = true - assert OpenSSL.fips_mode == true, ".fips_mode returns true when .fips_mode=true" + return unless OpenSSL::OPENSSL_FIPS + assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;") + require #{__FILE__.dump} - OpenSSL.fips_mode = false - assert OpenSSL.fips_mode == false, ".fips_mode returns false when .fips_mode=false" - end + begin + OpenSSL.fips_mode = true + assert OpenSSL.fips_mode == true, ".fips_mode returns true when .fips_mode=true" + + OpenSSL.fips_mode = false + assert OpenSSL.fips_mode == false, ".fips_mode returns false when .fips_mode=false" + rescue OpenSSL::OpenSSLError + pend "Could not set FIPS mode (OpenSSL::OpenSSLError: \#$!); skipping" + end + end; end end Index: test/openssl/test_asn1.rb =================================================================== --- test/openssl/test_asn1.rb (revision 59750) +++ test/openssl/test_asn1.rb (revision 59751) @@ -379,11 +379,16 @@ class OpenSSL::TestASN1 < OpenSSL::Test https://github.com/ruby/ruby/blob/trunk/test/openssl/test_asn1.rb#L379 def test_utctime encode_decode_test B(%w{ 17 0D }) + "160908234339Z".b, OpenSSL::ASN1::UTCTime.new(Time.utc(2016, 9, 8, 23, 43, 39)) - # possible range of UTCTime is 1969-2068 currently - encode_decode_test B(%w{ 17 0D }) + "690908234339Z".b, - OpenSSL::ASN1::UTCTime.new(Time.utc(1969, 9, 8, 23, 43, 39)) - decode_test B(%w{ 17 0B }) + "6909082343Z".b, - OpenSSL::ASN1::UTCTime.new(Time.utc(1969, 9, 8, 23, 43, 0)) + # Seconds is omitted + decode_test B(%w{ 17 0B }) + "1609082343Z".b, + OpenSSL::ASN1::UTCTime.new(Time.utc(2016, 9, 8, 23, 43, 0)) + begin + # possible range of UTCTime is 1969-2068 currently + encode_decode_test B(%w{ 17 0D }) + "690908234339Z".b, + OpenSSL::ASN1::UTCTime.new(Time.utc(1969, 9, 8, 23, 43, 39)) + rescue OpenSSL::ASN1::ASN1Error + pend "No negative time_t support?" + end # not implemented # decode_test B(%w{ 17 11 }) + "500908234339+0930".b, # OpenSSL::ASN1::UTCTime.new(Time.new(1950, 9, 8, 23, 43, 39, "+09:30")) Index: test/openssl/test_pair.rb =================================================================== --- test/openssl/test_pair.rb (revision 59750) +++ test/openssl/test_pair.rb (revision 59751) @@ -238,44 +238,42 @@ module OpenSSL::TestPairM https://github.com/ruby/ruby/blob/trunk/test/openssl/test_pair.rb#L238 } end - def write_nonblock(socket, meth, str) - ret = socket.send(meth, str) - ret.is_a?(Symbol) ? 0 : ret - end - - def write_nonblock_no_ex(socket, str) - ret = socket.write_nonblock str, exception: false - ret.is_a?(Symbol) ? 0 : ret - end - def test_write_nonblock ssl_pair {|s1, s2| - n = 0 - begin - n += write_nonblock s1, :write_nonblock, "a" * 100000 - n += write_nonblock s1, :write_nonblock, "b" * 100000 - n += write_nonblock s1, :write_nonblock, "c" * 100000 - n += write_nonblock s1, :write_nonblock, "d" * 100000 - n += write_nonblock s1, :write_nonblock, "e" * 100000 - n += write_nonblock s1, :write_nonblock, "f" * 100000 - rescue IO::WaitWritable + assert_equal 3, s1.write_nonblock("foo") + assert_equal "foo", s2.read(3) + + data = "x" * 16384 + written = 0 + while true + begin + written += s1.write_nonblock(data) + rescue IO::WaitWritable, IO::WaitReadable + break + end end - s1.close - assert_equal(n, s2.read.length) + assert written > 0 + assert_equal written, s2.read(written).bytesize } end def test_write_nonblock_no_exceptions ssl_pair {|s1, s2| - n = 0 - n += write_nonblock_no_ex s1, "a" * 100000 - n += write_nonblock_no_ex s1, "b" * 100000 - n += write_nonblock_no_ex s1, "c" * 100000 - n += write_nonblock_no_ex s1, "d" * 100000 - n += write_nonblock_no_ex s1, "e" * 100000 - n += write_nonblock_no_ex s1, "f" * 100000 - s1.close - assert_equal(n, s2.read.length) + assert_equal 3, s1.write_nonblock("foo", exception: false) + assert_equal "foo", s2.read(3) + + data = "x" * 16384 + written = 0 + while true + case ret = s1.write_nonblock(data, exception: false) + when :wait_readable, :wait_writable + break + else + written += ret + end + end + assert written > 0 + assert_equal written, s2.read(written).bytesize } end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/