From ddc8fba31196675a30ad26d447c420212784447f Mon Sep 17 00:00:00 2001 From: ydah Date: Mon, 10 Aug 2026 13:40:08 +0900 Subject: [PATCH] Fix SSL configuration paths --- lib/gruf/configuration.rb | 5 +++-- spec/gruf/configuration_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/gruf/configuration.rb b/lib/gruf/configuration.rb index cb270b1..90c3cb6 100644 --- a/lib/gruf/configuration.rb +++ b/lib/gruf/configuration.rb @@ -172,8 +172,9 @@ def reset self.hooks = ::Gruf::Hooks::Registry.new self.root_path = ::Rails.root.to_s.chomp('/') if defined?(::Rails) determine_loggers - self.ssl_crt_file = "#{root_path}config/ssl/#{environment}.crt" - self.ssl_key_file = "#{root_path}config/ssl/#{environment}.key" + ssl_path = root_path.to_s.empty? ? 'config/ssl' : "#{root_path}/config/ssl" + self.ssl_crt_file = "#{ssl_path}/#{environment}.crt" + self.ssl_key_file = "#{ssl_path}/#{environment}.key" cp = ::ENV.fetch('GRUF_CONTROLLERS_PATH', 'app/rpc').to_s self.controllers_path = root_path.to_s.empty? ? cp : "#{root_path}/#{cp}" self.backtrace_on_error = ::ENV.fetch('GRPC_BACKTRACE_ON_ERROR', 0).to_i.positive? diff --git a/spec/gruf/configuration_spec.rb b/spec/gruf/configuration_spec.rb index bc5e483..49ad21d 100644 --- a/spec/gruf/configuration_spec.rb +++ b/spec/gruf/configuration_spec.rb @@ -34,6 +34,28 @@ class TestConfiguration obj.reset expect(subject).not_to eq 'test.dev' end + + context 'when a Rails root path is configured' do + before do + stub_const('Rails', double(root: '/app/', logger: nil, env: 'production')) + end + + it 'joins the SSL paths with the root path separator' do + obj.reset + + expect(obj.ssl_crt_file).to eq '/app/config/ssl/production.crt' + expect(obj.ssl_key_file).to eq '/app/config/ssl/production.key' + end + end + + context 'when no Rails root path is configured' do + it 'keeps the SSL paths relative' do + obj.reset + + expect(obj.ssl_crt_file).to eq "config/ssl/#{obj.send(:environment)}.crt" + expect(obj.ssl_key_file).to eq "config/ssl/#{obj.send(:environment)}.key" + end + end end describe '.environment' do