Welcome to mirror list, hosted at ThFree Co, Russian Federation.

asset_proxy_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d7952d5741f145177e2697d6f6faf6434b696ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::AssetProxy do
  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
      stub_asset_proxy_setting(allowlist: %w(gitlab.com *.mydomain.com))
      stub_asset_proxy_setting(
        enabled: true,
        url: 'https://assets.example.com',
        secret_key: 'shared-secret',
        domain_regexp: Banzai::Filter::AssetProxyFilter.compile_allowlist(Gitlab.config.asset_proxy.allowlist)
      )
    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

    it 'returns original URL for invalid domains' do
      url = 'foo_bar://'

      expect(described_class.proxy_url(url)).to eq(url)
    end

    context 'whitelisted domain' do
      it 'returns original URL for single domain whitelist' do
        url = 'http://gitlab.com/${default_branch}/test.png'

        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