summaryrefslogtreecommitdiff
path: root/spec/presenters/pages_domain_presenter_spec.rb
blob: f197daab7591530fc734bae57f7cf36f0a31a75a (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe PagesDomainPresenter, feature_category: :pages do
  using RSpec::Parameterized::TableSyntax
  include LetsEncryptHelpers

  let(:presenter) { Gitlab::View::Presenter::Factory.new(domain).fabricate! }

  describe 'needs_validation?' do
    where(:pages_verification_enabled, :traits, :expected) do
      false | :unverified | false
      false | []          | false
      true  | :unverified | true
      true  | []          | false
    end

    with_them do
      before do
        stub_application_setting(pages_domain_verification_enabled: pages_verification_enabled)
      end

      let(:domain) { create(:pages_domain, *traits) }

      it { expect(presenter.needs_verification?).to eq(expected) }
    end
  end

  describe 'show_auto_ssl_failed_warning?' do
    subject { presenter.show_auto_ssl_failed_warning? }

    let(:domain) { create(:pages_domain) }

    before do
      stub_lets_encrypt_settings
    end

    it { is_expected.to eq(false) }

    context "when we failed to obtain Let's Encrypt's certificate" do
      before do
        domain.update!(auto_ssl_failed: true)
      end

      it { is_expected.to eq(true) }

      context "when Let's Encrypt integration is disabled" do
        before do
          allow(::Gitlab::LetsEncrypt).to receive(:enabled?).and_return false
        end

        it { is_expected.to eq(false) }
      end

      context "when domain is unverified" do
        before do
          domain.update!(verified_at: nil)
        end

        it { is_expected.to eq(false) }
      end
    end
  end

  describe 'user_defined_certificate?' do
    subject { presenter.user_defined_certificate? }

    let(:domain) { create(:pages_domain) }

    context "when domain certificate is user provided" do
      it { is_expected.to eq(true) }
    end

    context "when domain is not persisted" do
      before do
        domain.destroy!
      end

      it { is_expected.to eq(false) }
    end

    context "when domain certificate is blank" do
      before do
        domain.update!(certificate: nil, key: nil)
      end

      it { is_expected.to eq(false) }
    end

    context "when domain certificate source is gitlab_provided" do
      before do
        domain.update!(certificate_source: :gitlab_provided)
      end

      it { is_expected.to eq(false) }
    end

    context "when domain certificate has error" do
      before do
        domain.errors.add(:certificate, "certificate error")
      end

      it { is_expected.to eq(false) }
    end
  end
end