Skip to content

Commit

Permalink
Fix crash when S3_ALIAS_HOST or S3_CLOUDFRONT_HOST have a path compon…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Jun 1, 2023
1 parent 2b45fec commit b922ad7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ def cdn_host?
end

def storage_host
URI::HTTPS.build(host: storage_host_name).to_s
"https://#{storage_host_var}"
end

def storage_host?
storage_host_name.present?
storage_host_var.present?
end

def quote_wrap(text, line_width: 80, break_sequence: "\n")
Expand Down Expand Up @@ -234,7 +234,7 @@ def prerender_custom_emojis(html, custom_emojis, other_options = {})

private

def storage_host_name
def storage_host_var
ENV.fetch('S3_ALIAS_HOST', nil) || ENV.fetch('S3_CLOUDFRONT_HOST', nil)
end
end
18 changes: 12 additions & 6 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@
end
end

context 'when S3 alias includes a path component' do
around do |example|
ClimateControl.modify S3_ALIAS_HOST: 's3.alias/path' do
example.run
end
end

it 'returns a correct URL' do
expect(helper.storage_host).to eq('https://s3.alias/path')
end
end

context 'when S3 cloudfront is present' do
around do |example|
ClimateControl.modify S3_CLOUDFRONT_HOST: 's3.cloudfront' do
Expand All @@ -219,12 +231,6 @@
expect(helper.storage_host).to eq('https://s3.cloudfront')
end
end

context 'when neither env value is present' do
it 'returns false' do
expect(helper.storage_host).to eq('https:')
end
end
end

describe 'storage_host?' do
Expand Down

0 comments on commit b922ad7

Please sign in to comment.