aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2020-07-11 16:10:41 +0900
committernagachika <nagachika@ruby-lang.org>2020-07-11 16:10:41 +0900
commitb4c893a62c71ac28795f8fcefb375131833afd0c (patch)
treeb8b7bcc53638ee75f8123fbec4c57e1e11cdc1cf /test
parenta0bb4eb04512b3f8ca50ec5fa72e3d4a8278ca46 (diff)
downloadruby-b4c893a62c71ac28795f8fcefb375131833afd0c.tar.gz
OpenSSL 1.1.1 introduces a new '.include' directive. Update our config
parser to support that. As mentioned in the referenced GitHub issue, we should use the OpenSSL API instead of implementing the parsing logic ourselves, but it will need backwards-incompatible changes which we can't backport to stable versions. So continue to use the Ruby implementation for now. References: https://github.com/ruby/openssl/issues/208 https://github.com/ruby/openssl/pull/216 The original patch was written by Kazuki Yamaguchi <k@rhe.jp> and the patch for ruby_2_7 branch was prepared by Vít Ondruch.
Diffstat (limited to 'test')
-rw-r--r--test/openssl/test_config.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/openssl/test_config.rb b/test/openssl/test_config.rb
index 3606c67d65..c1a01d4dbe 100644
--- a/test/openssl/test_config.rb
+++ b/test/openssl/test_config.rb
@@ -120,6 +120,49 @@ __EOC__
assert_equal("error in line 7: missing close square bracket", excn.message)
end
+ def test_s_parse_include
+ in_tmpdir("ossl-config-include-test") do |dir|
+ Dir.mkdir("child")
+ File.write("child/a.conf", <<~__EOC__)
+ [default]
+ file-a = a.conf
+ [sec-a]
+ a = 123
+ __EOC__
+ File.write("child/b.cnf", <<~__EOC__)
+ [default]
+ file-b = b.cnf
+ [sec-b]
+ b = 123
+ __EOC__
+ File.write("include-child.conf", <<~__EOC__)
+ key_outside_section = value_a
+ .include child
+ __EOC__
+
+ include_file = <<~__EOC__
+ [default]
+ file-main = unnamed
+ [sec-main]
+ main = 123
+ .include = include-child.conf
+ __EOC__
+
+ # Include a file by relative path
+ c1 = OpenSSL::Config.parse(include_file)
+ assert_equal(["default", "sec-a", "sec-b", "sec-main"], c1.sections.sort)
+ assert_equal(["file-main", "file-a", "file-b"], c1["default"].keys)
+ assert_equal({"a" => "123"}, c1["sec-a"])
+ assert_equal({"b" => "123"}, c1["sec-b"])
+ assert_equal({"main" => "123", "key_outside_section" => "value_a"}, c1["sec-main"])
+
+ # Relative paths are from the working directory
+ assert_raise(OpenSSL::ConfigError) do
+ Dir.chdir("child") { OpenSSL::Config.parse(include_file) }
+ end
+ end
+ end
+
def test_s_load
# alias of new
c = OpenSSL::Config.load
@@ -299,6 +342,17 @@ __EOC__
@it['newsection'] = {'a' => 'b'}
assert_not_equal(@it.sections.sort, c.sections.sort)
end
+
+ private
+
+ def in_tmpdir(*args)
+ Dir.mktmpdir(*args) do |dir|
+ dir = File.realpath(dir)
+ Dir.chdir(dir) do
+ yield dir
+ end
+ end
+ end
end
end