debian-mirror-gitlab/spec/lib/gitlab/asset_proxy_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.6 KiB
Ruby
Raw Normal View History

2020-03-07 23:17:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::AssetProxy do
2020-03-07 23:17:34 +05:30
context 'when asset proxy is disabled' do
before do
stub_asset_proxy_setting(enabled: false)
end
it 'returns the original URL' do
url = 'http://example.com/test.png'
expect(described_class.proxy_url(url)).to eq(url)
end
end
context 'when asset proxy is enabled' do
before do
2021-03-08 18:12:59 +05:30
stub_asset_proxy_setting(allowlist: %w(gitlab.com *.mydomain.com))
2020-03-07 23:17:34 +05:30
stub_asset_proxy_setting(
enabled: true,
url: 'https://assets.example.com',
secret_key: 'shared-secret',
2021-03-08 18:12:59 +05:30
domain_regexp: Banzai::Filter::AssetProxyFilter.compile_allowlist(Gitlab.config.asset_proxy.allowlist)
2020-03-07 23:17:34 +05:30
)
end
it 'returns a proxied URL' do
url = 'http://example.com/test.png'
proxied_url = 'https://assets.example.com/08df250eeeef1a8cf2c761475ac74c5065105612/687474703a2f2f6578616d706c652e636f6d2f746573742e706e67'
expect(described_class.proxy_url(url)).to eq(proxied_url)
end
2020-03-13 15:44:24 +05:30
it 'returns original URL for invalid domains' do
url = 'foo_bar://'
expect(described_class.proxy_url(url)).to eq(url)
end
2020-03-07 23:17:34 +05:30
context 'whitelisted domain' do
it 'returns original URL for single domain whitelist' do
2020-03-13 15:44:24 +05:30
url = 'http://gitlab.com/${default_branch}/test.png'
2020-03-07 23:17:34 +05:30
expect(described_class.proxy_url(url)).to eq(url)
end
it 'returns original URL for wildcard subdomain whitelist' do
url = 'http://test.mydomain.com/test.png'
expect(described_class.proxy_url(url)).to eq(url)
end
end
end
end