зеркало из https://github.com/github/ruby.git
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} git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
31a447d1c3
Коммит
d68a6b3ebe
|
@ -379,11 +379,16 @@ class OpenSSL::TestASN1 < OpenSSL::TestCase
|
|||
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"))
|
||||
|
|
|
@ -10,13 +10,20 @@ class OpenSSL::TestFIPS < OpenSSL::TestCase
|
|||
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
|
||||
|
||||
|
|
|
@ -238,44 +238,42 @@ module OpenSSL::TestPairM
|
|||
}
|
||||
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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче