Log certificate loading errors into sentry
This commit is contained in:
parent
32c4f70aa5
commit
d975074e1f
2 changed files with 24 additions and 4 deletions
|
@ -57,18 +57,22 @@ module Gitlab
|
|||
end
|
||||
end
|
||||
|
||||
def self.stub_cert_paths
|
||||
cert_paths = Dir["#{OpenSSL::X509::DEFAULT_CERT_DIR}/*"]
|
||||
cert_paths << OpenSSL::X509::DEFAULT_CERT_FILE if File.exist? OpenSSL::X509::DEFAULT_CERT_FILE
|
||||
cert_paths
|
||||
end
|
||||
|
||||
def self.stub_certs
|
||||
return @certs if @certs
|
||||
|
||||
cert_paths = Dir["#{OpenSSL::X509::DEFAULT_CERT_DIR}/*"]
|
||||
cert_paths << OpenSSL::X509::DEFAULT_CERT_FILE if File.exist? OpenSSL::X509::DEFAULT_CERT_FILE
|
||||
|
||||
@certs = cert_paths.flat_map do |cert_file|
|
||||
@certs = stub_cert_paths.flat_map do |cert_file|
|
||||
File.read(cert_file).scan(PEM_REGEX).map do |cert|
|
||||
begin
|
||||
OpenSSL::X509::Certificate.new(cert).to_pem
|
||||
rescue OpenSSL::OpenSSLError => e
|
||||
Rails.logger.error "Could not load certificate #{cert_file} #{e}"
|
||||
Gitlab::Sentry.track_exception(e, extra: { cert_file: cert_file })
|
||||
nil
|
||||
end
|
||||
end.compact
|
||||
|
|
|
@ -30,6 +30,22 @@ describe Gitlab::GitalyClient do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.stub_certs' do
|
||||
it 'skips certificates if OpenSSLError is raised and report it' do
|
||||
expect(Rails.logger).to receive(:error).at_least(:once)
|
||||
expect(Gitlab::Sentry)
|
||||
.to receive(:track_exception)
|
||||
.with(
|
||||
a_kind_of(OpenSSL::X509::CertificateError),
|
||||
extra: { cert_file: a_kind_of(String) }).at_least(:once)
|
||||
|
||||
expect(OpenSSL::X509::Certificate)
|
||||
.to receive(:new)
|
||||
.and_raise(OpenSSL::X509::CertificateError).at_least(:once)
|
||||
|
||||
expect(described_class.stub_certs).to be_a(String)
|
||||
end
|
||||
end
|
||||
describe '.stub_creds' do
|
||||
it 'returns :this_channel_is_insecure if unix' do
|
||||
address = 'unix:/tmp/gitaly.sock'
|
||||
|
|
Loading…
Reference in a new issue