mirror of https://github.com/tootsuite/mastodon
Fix crash when S3_ALIAS_HOST or S3_CLOUDFRONT_HOST have a path component (#25018)
parent
2b45fecde1
commit
b922ad7a1b
|
@ -169,11 +169,11 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def storage_host
|
def storage_host
|
||||||
URI::HTTPS.build(host: storage_host_name).to_s
|
"https://#{storage_host_var}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def storage_host?
|
def storage_host?
|
||||||
storage_host_name.present?
|
storage_host_var.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def quote_wrap(text, line_width: 80, break_sequence: "\n")
|
def quote_wrap(text, line_width: 80, break_sequence: "\n")
|
||||||
|
@ -234,7 +234,7 @@ module ApplicationHelper
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def storage_host_name
|
def storage_host_var
|
||||||
ENV.fetch('S3_ALIAS_HOST', nil) || ENV.fetch('S3_CLOUDFRONT_HOST', nil)
|
ENV.fetch('S3_ALIAS_HOST', nil) || ENV.fetch('S3_CLOUDFRONT_HOST', nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -208,6 +208,18 @@ describe ApplicationHelper do
|
||||||
end
|
end
|
||||||
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
|
context 'when S3 cloudfront is present' do
|
||||||
around do |example|
|
around do |example|
|
||||||
ClimateControl.modify S3_CLOUDFRONT_HOST: 's3.cloudfront' do
|
ClimateControl.modify S3_CLOUDFRONT_HOST: 's3.cloudfront' do
|
||||||
|
@ -219,12 +231,6 @@ describe ApplicationHelper do
|
||||||
expect(helper.storage_host).to eq('https://s3.cloudfront')
|
expect(helper.storage_host).to eq('https://s3.cloudfront')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when neither env value is present' do
|
|
||||||
it 'returns false' do
|
|
||||||
expect(helper.storage_host).to eq('https:')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'storage_host?' do
|
describe 'storage_host?' do
|
||||||
|
|
Loading…
Reference in New Issue