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

Raise an error for broken certificate file. fix #3085 #3086

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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