Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve implementations for skipping and conditions. #860

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/openssl/test_bn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def test_argument_error
end

def test_get_flags_and_set_flags
return if aws_lc? # AWS-LC does not support BN::CONSTTIME.
omit "AWS-LC does not support BN::CONSTTIME" if aws_lc?

e = OpenSSL::BN.new(999)

Expand Down Expand Up @@ -366,7 +366,7 @@ def test_ractor
assert_equal(true, Ractor.new(@e2) { _1.negative? }.take)
assert_include(128..255, Ractor.new { OpenSSL::BN.rand(8)}.take)
assert_include(0...2**32, Ractor.new { OpenSSL::BN.generate_prime(32) }.take)
if !aws_lc? # AWS-LC does not support BN::CONSTTIME.
unless aws_lc? # AWS-LC does not support BN::CONSTTIME.
assert_equal(0, Ractor.new { OpenSSL::BN.new(999).get_flags(OpenSSL::BN::CONSTTIME) }.take)
end
# test if shareable when frozen
Expand Down
9 changes: 5 additions & 4 deletions test/openssl/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def test_s_parse
end

def test_s_parse_format
# AWS-LC removed support for parsing $foo variables.
return if aws_lc?
omit "AWS-LC removed support for parsing $foo variables" if aws_lc?

c = OpenSSL::Config.parse(<<__EOC__)
baz =qx\t # "baz = qx"
Expand Down Expand Up @@ -223,8 +222,10 @@ def test_get_value
end

def test_get_value_ENV
# LibreSSL and AWS-LC removed support for NCONF_get_string(conf, "ENV", str)
return if libressl? || aws_lc?
if libressl? || aws_lc?
omit 'LibreSSL and AWS-LC removed support for '\
'NCONF_get_string(conf, "ENV", str)'
end

key = ENV.keys.first
assert_not_nil(key) # make sure we have at least one ENV var.
Expand Down
6 changes: 3 additions & 3 deletions test/openssl/test_fips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ def test_fips_mode_get_is_false_on_fips_mode_disabled
end

def test_fips_mode_is_reentrant
return if aws_lc? # AWS-LC's FIPS mode is decided at compile time.

assert_separately(["-ropenssl"], <<~"end;")
OpenSSL.fips_mode = false
OpenSSL.fips_mode = false
end;
end

def test_fips_mode_get_with_fips_mode_set
omit('OpenSSL is not FIPS-capable') unless OpenSSL::OPENSSL_FIPS and !aws_lc? # AWS-LC's FIPS mode is decided at compile time.
unless ENV["TEST_RUBY_OPENSSL_FIPS_ENABLED"]
omit "Only for FIPS mode environment"
end

assert_separately(["-ropenssl"], <<~"end;")
begin
Expand Down
4 changes: 2 additions & 2 deletions test/openssl/test_pkey_dh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_new_generate
end if ENV["OSSL_TEST_ALL"]

def test_new_break_on_non_fips
omit_on_fips if !aws_lc?
omit_on_fips unless aws_lc?

assert_nil(OpenSSL::PKey::DH.new(NEW_KEYLEN) { break })
assert_raise(RuntimeError) do
Expand All @@ -29,7 +29,7 @@ def test_new_break_on_non_fips

def test_new_break_on_fips
omit_on_non_fips
return unless openssl? # This behavior only applies to OpenSSL.
omit "This test only applies to OpenSSL" unless openssl?

# The block argument is not executed in FIPS case.
# See https://github.com/ruby/openssl/issues/692 for details.
Expand Down
34 changes: 21 additions & 13 deletions test/openssl/test_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def test_ctx_options
end

def test_ctx_options_config
omit "LibreSSL and AWS-LC do not support OPENSSL_CONF" if libressl? || aws_lc?
if libressl? || aws_lc?
omit "LibreSSL and AWS-LC do not support OPENSSL_CONF"
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed?

Copy link
Member Author

@junaruga junaruga Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this change is because the line length was more than 80 bytes. I didn't like it. I was working with a sleepy brain. I shouldn't include this change in this commit. I will revert this part.


Tempfile.create("openssl.cnf") { |f|
f.puts(<<~EOF)
Expand Down Expand Up @@ -838,7 +840,9 @@ def test_post_connection_check_wildcard_san

# LibreSSL 3.5.0+ doesn't support other wildcard certificates
# (it isn't required to, as RFC states MAY, not MUST)
return if libressl?
if libressl?
omit "LibreSSL 3.5.0+ doesn't support some wildcard certificates"
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#861 is an alternative to this. This test case should run with LibreSSL too.


assert_equal(true, OpenSSL::SSL.verify_certificate_identity(
create_cert_with_san('DNS:*baz.example.com'), 'foobaz.example.com'))
Expand Down Expand Up @@ -1412,7 +1416,9 @@ def test_minmax_version
end

def test_minmax_version_system_default
omit "LibreSSL and AWS-LC do not support OPENSSL_CONF" if libressl? || aws_lc?
if libressl? || aws_lc?
omit "LibreSSL and AWS-LC do not support OPENSSL_CONF"
end

Tempfile.create("openssl.cnf") { |f|
f.puts(<<~EOF)
Expand Down Expand Up @@ -1456,7 +1462,9 @@ def test_minmax_version_system_default
end

def test_respect_system_default_min
omit "LibreSSL and AWS-LC do not support OPENSSL_CONF" if libressl? || aws_lc?
if libressl? || aws_lc?
omit "LibreSSL and AWS-LC do not support OPENSSL_CONF"
end

Tempfile.create("openssl.cnf") { |f|
f.puts(<<~EOF)
Expand Down Expand Up @@ -1619,7 +1627,7 @@ def test_alpn_protocol_selection_cancel
end

def test_npn_protocol_selection_ary
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
omit unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)

advertised = ["http/1.1", "spdy/2"]
ctx_proc = proc { |ctx| ctx.npn_protocols = advertised }
Expand All @@ -1638,7 +1646,7 @@ def test_npn_protocol_selection_ary
end

def test_npn_protocol_selection_enum
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
omit unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)

advertised = Object.new
def advertised.each
Expand All @@ -1661,7 +1669,7 @@ def advertised.each
end

def test_npn_protocol_selection_cancel
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
omit unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)

ctx_proc = Proc.new { |ctx| ctx.npn_protocols = ["http/1.1"] }
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
Expand All @@ -1673,7 +1681,7 @@ def test_npn_protocol_selection_cancel
end

def test_npn_advertised_protocol_too_long
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
omit unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)

ctx = OpenSSL::SSL::SSLContext.new
assert_raise(OpenSSL::SSL::SSLError) do
Expand All @@ -1683,7 +1691,7 @@ def test_npn_advertised_protocol_too_long
end

def test_npn_selected_protocol_too_long
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
omit unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)

ctx_proc = Proc.new { |ctx| ctx.npn_protocols = ["http/1.1"] }
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
Expand Down Expand Up @@ -1739,7 +1747,7 @@ def test_get_ephemeral_key
end
end

if !aws_lc? # AWS-LC does not support DHE ciphersuites.
unless aws_lc? # AWS-LC does not support DHE ciphersuites.
# DHE
# TODO: SSL_CTX_set1_groups() is required for testing this with TLS 1.3
ctx_proc2 = proc { |ctx|
Expand Down Expand Up @@ -1774,7 +1782,7 @@ def test_get_ephemeral_key

def test_fallback_scsv
supported = check_supported_protocol_versions
return unless supported.include?(OpenSSL::SSL::TLS1_1_VERSION) &&
omit unless supported.include?(OpenSSL::SSL::TLS1_1_VERSION) &&
supported.include?(OpenSSL::SSL::TLS1_2_VERSION)
Comment on lines +1785 to 1786
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can assume all libssl versions support TLS 1.2 and TLS 1.3, so a check for TLS 1.2 is no longer necessary. #841 overlooked this.

I agree an explicit omission would be useful here, since TLS 1.1 is not typically disabled, and this should be noted.

Suggested change
omit unless supported.include?(OpenSSL::SSL::TLS1_1_VERSION) &&
supported.include?(OpenSSL::SSL::TLS1_2_VERSION)
omit "TLS 1.1 is required to run this test" unless supported.include?(OpenSSL::SSL::TLS1_1_VERSION)


pend "Fallback SCSV is not supported" unless \
Expand Down Expand Up @@ -2023,9 +2031,9 @@ def test_ecdh_curves_tls13
def test_security_level
ctx = OpenSSL::SSL::SSLContext.new
ctx.security_level = 1
if aws_lc? # AWS-LC does not support security levels.
if aws_lc?
assert_equal(0, ctx.security_level)
return
omit "AWS-LC does not support security levels"
end
assert_equal(1, ctx.security_level)

Expand Down
Loading