Skip to content

Commit

Permalink
Merge pull request #3086 from fluent/raise-error-for-broken-cert
Browse files Browse the repository at this point in the history
Raise an error for broken certificate file. fix #3085
  • Loading branch information
repeatedly authored Jul 28, 2020
2 parents be905c9 + 7f94694 commit 8ebff61
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/plugin_helper/cert_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def cert_option_certificates_from_file(path)
list = []
data.scan(pattern){|match| list << OpenSSL::X509::Certificate.new(match) }
if list.length == 0
log.warn "cert_path does not contain a valid certificate"
raise Fluent::ConfigError, "cert_path does not contain a valid certificate"
end
list
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin_helper/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def socket_certificates_from_file(path)
list = []
data.scan(pattern) { |match| list << OpenSSL::X509::Certificate.new(match) }
if list.length == 0
log.warn "cert_path does not contain a valid certificate"
raise Fluent::ConfigError, "cert_path does not contain a valid certificate"
end
list
end
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions test/plugin_helper/test_cert_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ class Dummy < Fluent::Plugin::TestBase
certs = d.cert_option_certificates_from_file("test/plugin_helper/data/cert/cert-with-CRLF.pem")
assert_equal(1, certs.length)
end

test 'raise an error for broken certificates_from_file file' do
d = Dummy.new
assert_raise Fluent::ConfigError do
certs = d.cert_option_certificates_from_file("test/plugin_helper/data/cert/empty.pem")
end
end
end
8 changes: 8 additions & 0 deletions test/plugin_helper/test_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,12 @@ def do_start
client.close
end
end

test 'with empty cert file' do
cert_path = File.expand_path(File.dirname(__FILE__) + '/data/cert/empty.pem')

assert_raise Fluent::ConfigError do
SocketHelperTestPlugin.new.socket_create_tls('127.0.0.1', PORT, cert_path: cert_path)
end
end
end

0 comments on commit 8ebff61

Please sign in to comment.