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

domain_allowlist_entry_spec.rb « http_v2 « gitlab « spec « gitlab-http « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0f9d5bc550d9071d7e51a4e35985e510f5db99c8 (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
57
58
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::HTTP_V2::DomainAllowlistEntry do
  let(:domain) { 'www.example.com' }

  describe '#initialize' do
    it 'initializes without port' do
      domain_allowlist_entry = described_class.new(domain)

      expect(domain_allowlist_entry.domain).to eq(domain)
      expect(domain_allowlist_entry.port).to be(nil)
    end

    it 'initializes with port' do
      port = 8080
      domain_allowlist_entry = described_class.new(domain, port: port)

      expect(domain_allowlist_entry.domain).to eq(domain)
      expect(domain_allowlist_entry.port).to eq(port)
    end
  end

  describe '#match?' do
    it 'matches when domain and port are equal' do
      port = 8080
      domain_allowlist_entry = described_class.new(domain, port: port)

      expect(domain_allowlist_entry).to be_match(domain, port)
    end

    it 'matches any port when port is nil' do
      domain_allowlist_entry = described_class.new(domain)

      expect(domain_allowlist_entry).to be_match(domain, 8080)
      expect(domain_allowlist_entry).to be_match(domain, 9090)
    end

    it 'does not match when port is present but requested_port is nil' do
      domain_allowlist_entry = described_class.new(domain, port: 8080)

      expect(domain_allowlist_entry).not_to be_match(domain, nil)
    end

    it 'matches when port and requested_port are nil' do
      domain_allowlist_entry = described_class.new(domain)

      expect(domain_allowlist_entry).to be_match(domain)
    end

    it 'does not match if domain is not equal' do
      domain_allowlist_entry = described_class.new(domain)

      expect(domain_allowlist_entry).not_to be_match('www.gitlab.com', 8080)
    end
  end
end