2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-12 10:05:17 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe PagesDomain do
|
2018-02-06 08:25:46 -05:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
subject(:pages_domain) { described_class.new }
|
|
|
|
|
2016-02-12 10:05:17 -05:00
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:project) }
|
2020-02-25 13:09:02 -05:00
|
|
|
it { is_expected.to have_many(:serverless_domain_clusters) }
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
2016-12-20 06:24:44 -05:00
|
|
|
|
2021-05-26 11:10:57 -04:00
|
|
|
describe '.for_project' do
|
|
|
|
it 'returns domains assigned to project' do
|
|
|
|
domain = create(:pages_domain, :with_project)
|
|
|
|
create(:pages_domain) # unrelated domain
|
|
|
|
|
|
|
|
expect(described_class.for_project(domain.project)).to eq([domain])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-13 17:14:17 -04:00
|
|
|
describe '.verified' do
|
|
|
|
let!(:verified) { create(:pages_domain) }
|
|
|
|
let!(:unverified) { create(:pages_domain, :unverified) }
|
|
|
|
|
|
|
|
it 'finds verified' do
|
|
|
|
expect(described_class.verified).to match_array(verified)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe 'validate domain' do
|
2017-05-19 10:07:38 -04:00
|
|
|
subject(:pages_domain) { build(:pages_domain, domain: domain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
|
|
|
context 'is unique' do
|
|
|
|
let(:domain) { 'my.domain.com' }
|
|
|
|
|
2017-07-24 08:33:14 -04:00
|
|
|
it { is_expected.to validate_uniqueness_of(:domain).case_insensitive }
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
describe "hostname" do
|
|
|
|
{
|
2022-09-02 11:12:37 -04:00
|
|
|
'my.domain.com' => true,
|
|
|
|
'123.456.789' => true,
|
|
|
|
'0x12345.com' => true,
|
|
|
|
'0123123' => true,
|
|
|
|
'a-reserved.com' => true,
|
2022-01-24 07:10:54 -05:00
|
|
|
'a.b-reserved.com' => true,
|
2022-09-02 11:12:37 -04:00
|
|
|
'reserved.com' => true,
|
|
|
|
'_foo.com' => false,
|
|
|
|
'a.reserved.com' => false,
|
2022-01-24 07:10:54 -05:00
|
|
|
'a.b.reserved.com' => false,
|
2022-09-02 11:12:37 -04:00
|
|
|
nil => false
|
2018-01-03 03:07:03 -05:00
|
|
|
}.each do |value, validity|
|
|
|
|
context "domain #{value.inspect} validity" do
|
|
|
|
before do
|
|
|
|
allow(Settings.pages).to receive(:host).and_return('reserved.com')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:domain) { value }
|
|
|
|
|
|
|
|
it { expect(pages_domain.valid?).to eq(validity) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "HTTPS-only" do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let(:domain) { 'my.domain.com' }
|
|
|
|
|
|
|
|
let(:project) do
|
2022-09-11 23:13:31 -04:00
|
|
|
instance_double(Project, pages_https_only?: pages_https_only, can_create_custom_domains?: true)
|
2018-01-03 03:07:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:pages_domain) do
|
2022-09-02 11:12:37 -04:00
|
|
|
build(:pages_domain, certificate: certificate, key: key, auto_ssl_enabled: auto_ssl_enabled).tap do |pd|
|
2018-01-03 03:07:03 -05:00
|
|
|
allow(pd).to receive(:project).and_return(project)
|
|
|
|
pd.valid?
|
2017-05-19 10:07:38 -04:00
|
|
|
end
|
2018-01-03 03:07:03 -05:00
|
|
|
end
|
2017-05-19 10:07:38 -04:00
|
|
|
|
2019-07-12 10:19:01 -04:00
|
|
|
where(:pages_https_only, :certificate, :key, :auto_ssl_enabled, :errors_on) do
|
2018-01-03 03:07:03 -05:00
|
|
|
attributes = attributes_for(:pages_domain)
|
|
|
|
cert, key = attributes.fetch_values(:certificate, :key)
|
|
|
|
|
2019-07-12 10:19:01 -04:00
|
|
|
true | nil | nil | false | %i(certificate key)
|
|
|
|
true | nil | nil | true | []
|
|
|
|
true | cert | nil | false | %i(key)
|
|
|
|
true | cert | nil | true | %i(key)
|
|
|
|
true | nil | key | false | %i(certificate key)
|
|
|
|
true | nil | key | true | %i(key)
|
|
|
|
true | cert | key | false | []
|
|
|
|
true | cert | key | true | []
|
|
|
|
false | nil | nil | false | []
|
|
|
|
false | nil | nil | true | []
|
|
|
|
false | cert | nil | false | %i(key)
|
|
|
|
false | cert | nil | true | %i(key)
|
|
|
|
false | nil | key | false | %i(key)
|
|
|
|
false | nil | key | true | %i(key)
|
|
|
|
false | cert | key | false | []
|
|
|
|
false | cert | key | true | []
|
2018-01-03 03:07:03 -05:00
|
|
|
end
|
2017-05-19 10:07:38 -04:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
with_them do
|
|
|
|
it "is adds the expected errors" do
|
2021-10-08 14:13:02 -04:00
|
|
|
expect(pages_domain.errors.attribute_names).to eq errors_on
|
2018-01-03 03:07:03 -05:00
|
|
|
end
|
2017-05-19 10:07:38 -04:00
|
|
|
end
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-06 15:14:09 -04:00
|
|
|
describe 'when certificate is specified' do
|
|
|
|
let(:domain) { build(:pages_domain) }
|
|
|
|
|
|
|
|
it 'saves validity time' do
|
2021-11-03 17:10:35 -04:00
|
|
|
domain.save!
|
2019-06-06 15:14:09 -04:00
|
|
|
|
2020-05-22 05:08:09 -04:00
|
|
|
expect(domain.certificate_valid_not_before).to be_like_time(Time.zone.parse("2020-03-16 14:20:34 UTC"))
|
|
|
|
expect(domain.certificate_valid_not_after).to be_like_time(Time.zone.parse("2220-01-28 14:20:34 UTC"))
|
2019-06-06 15:14:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-12 10:05:17 -05:00
|
|
|
describe 'validate certificate' do
|
|
|
|
subject { domain }
|
|
|
|
|
2020-02-17 19:09:20 -05:00
|
|
|
context 'serverless domain' do
|
|
|
|
it 'requires certificate and key to be present' do
|
|
|
|
expect(build(:pages_domain, :without_certificate, :without_key, usage: :serverless)).not_to be_valid
|
|
|
|
expect(build(:pages_domain, :without_certificate, usage: :serverless)).not_to be_valid
|
|
|
|
expect(build(:pages_domain, :without_key, usage: :serverless)).not_to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
context 'with matching key' do
|
|
|
|
let(:domain) { build(:pages_domain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
it { is_expected.to be_valid }
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
context 'when no certificate is specified' do
|
|
|
|
let(:domain) { build(:pages_domain, :without_certificate) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
2016-05-30 04:11:46 -04:00
|
|
|
it { is_expected.not_to be_valid }
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
context 'when no key is specified' do
|
|
|
|
let(:domain) { build(:pages_domain, :without_key) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
it { is_expected.not_to be_valid }
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for not matching key' do
|
2018-01-03 03:07:03 -05:00
|
|
|
let(:domain) { build(:pages_domain, :with_missing_chain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
2016-05-30 04:11:46 -04:00
|
|
|
it { is_expected.not_to be_valid }
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
2019-07-22 11:38:08 -04:00
|
|
|
|
|
|
|
context 'when certificate is expired' do
|
|
|
|
let(:domain) do
|
|
|
|
build(:pages_domain, :with_trusted_expired_chain)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when certificate is being changed' do
|
|
|
|
it "adds error to certificate" do
|
|
|
|
domain.valid?
|
|
|
|
|
2021-10-08 14:13:02 -04:00
|
|
|
expect(domain.errors.attribute_names).to contain_exactly(:key, :certificate)
|
2019-07-22 11:38:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when certificate is already saved' do
|
|
|
|
it "doesn't add error to certificate" do
|
2021-11-03 17:10:35 -04:00
|
|
|
domain.save!(validate: false)
|
2019-07-22 11:38:08 -04:00
|
|
|
|
|
|
|
domain.valid?
|
|
|
|
|
2021-10-08 14:13:02 -04:00
|
|
|
expect(domain.errors.attribute_names).to contain_exactly(:key)
|
2019-07-22 11:38:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-06 20:29:03 -04:00
|
|
|
|
|
|
|
context 'with ecdsa certificate' do
|
|
|
|
it "is valid" do
|
|
|
|
domain = build(:pages_domain, :ecdsa)
|
|
|
|
|
|
|
|
expect(domain).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when curve is set explicitly by parameters' do
|
2019-10-08 11:06:04 -04:00
|
|
|
it 'adds errors to private key' do
|
2019-09-06 20:29:03 -04:00
|
|
|
domain = build(:pages_domain, :explicit_ecdsa)
|
|
|
|
|
|
|
|
expect(domain).to be_invalid
|
|
|
|
|
|
|
|
expect(domain.errors[:key]).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
|
|
|
|
2018-02-06 08:25:46 -05:00
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:verification_code) }
|
|
|
|
end
|
|
|
|
|
2019-12-14 10:07:56 -05:00
|
|
|
describe 'default values' do
|
|
|
|
it 'defaults wildcard to false' do
|
|
|
|
expect(subject.wildcard).to eq(false)
|
|
|
|
end
|
|
|
|
|
2020-01-31 19:08:41 -05:00
|
|
|
it 'defaults scope to project' do
|
|
|
|
expect(subject.scope).to eq('project')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults usage to pages' do
|
|
|
|
expect(subject.usage).to eq('pages')
|
2019-12-14 10:07:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-06 08:25:46 -05:00
|
|
|
describe '#verification_code' do
|
|
|
|
subject { pages_domain.verification_code }
|
|
|
|
|
|
|
|
it 'is set automatically with 128 bits of SecureRandom data' do
|
|
|
|
expect(SecureRandom).to receive(:hex).with(16) { 'verification code' }
|
|
|
|
|
|
|
|
is_expected.to eq('verification code')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#keyed_verification_code' do
|
|
|
|
subject { pages_domain.keyed_verification_code }
|
|
|
|
|
|
|
|
it { is_expected.to eq("gitlab-pages-verification-code=#{pages_domain.verification_code}") }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#verification_domain' do
|
|
|
|
subject { pages_domain.verification_domain }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
|
|
|
|
it 'is a well-known subdomain if the domain is present' do
|
|
|
|
pages_domain.domain = 'example.com'
|
|
|
|
|
|
|
|
is_expected.to eq('_gitlab-pages-verification-code.example.com')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#url' do
|
2016-02-12 10:05:17 -05:00
|
|
|
subject { domain.url }
|
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
let(:domain) { build(:pages_domain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
it { is_expected.to eq("https://#{domain.domain}") }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
context 'without the certificate' do
|
|
|
|
let(:domain) { build(:pages_domain, :without_certificate) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
it { is_expected.to eq("http://#{domain.domain}") }
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#has_matching_key?' do
|
2016-02-12 10:05:17 -05:00
|
|
|
subject { domain.has_matching_key? }
|
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
let(:domain) { build(:pages_domain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
it { is_expected.to be_truthy }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
|
|
|
context 'for invalid key' do
|
2018-01-03 03:07:03 -05:00
|
|
|
let(:domain) { build(:pages_domain, :with_missing_chain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#has_intermediates?' do
|
2016-02-12 10:05:17 -05:00
|
|
|
subject { domain.has_intermediates? }
|
|
|
|
|
|
|
|
context 'for self signed' do
|
2018-01-03 03:07:03 -05:00
|
|
|
let(:domain) { build(:pages_domain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
2016-02-16 08:39:58 -05:00
|
|
|
context 'for missing certificate chain' do
|
|
|
|
let(:domain) { build(:pages_domain, :with_missing_chain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
2016-02-16 08:39:58 -05:00
|
|
|
|
|
|
|
context 'for trusted certificate chain' do
|
2016-02-17 04:05:26 -05:00
|
|
|
# We only validate that we can to rebuild the trust chain, for certificates
|
|
|
|
# We assume that 'AddTrustExternalCARoot' needed to validate the chain is in trusted store.
|
|
|
|
# It will be if ca-certificates is installed on Debian/Ubuntu/Alpine
|
|
|
|
|
2016-02-16 08:39:58 -05:00
|
|
|
let(:domain) { build(:pages_domain, :with_trusted_chain) }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#expired?' do
|
2016-02-12 10:05:17 -05:00
|
|
|
subject { domain.expired? }
|
|
|
|
|
|
|
|
context 'for valid' do
|
2018-01-03 03:07:03 -05:00
|
|
|
let(:domain) { build(:pages_domain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for expired' do
|
|
|
|
let(:domain) { build(:pages_domain, :with_expired_certificate) }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#subject' do
|
2018-01-03 03:07:03 -05:00
|
|
|
let(:domain) { build(:pages_domain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
|
|
|
subject { domain.subject }
|
|
|
|
|
|
|
|
it { is_expected.to eq('/CN=test-certificate') }
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#certificate_text' do
|
2018-01-03 03:07:03 -05:00
|
|
|
let(:domain) { build(:pages_domain) }
|
2016-02-12 10:05:17 -05:00
|
|
|
|
|
|
|
subject { domain.certificate_text }
|
|
|
|
|
|
|
|
# We test only existence of output, since the output is long
|
2016-05-30 04:11:46 -04:00
|
|
|
it { is_expected.not_to be_empty }
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|
2018-02-06 08:25:46 -05:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
describe "#https?" do
|
|
|
|
context "when a certificate is present" do
|
|
|
|
subject { build(:pages_domain) }
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
it { is_expected.to be_https }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no certificate is present" do
|
|
|
|
subject { build(:pages_domain, :without_certificate) }
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2018-01-03 03:07:03 -05:00
|
|
|
it { is_expected.not_to be_https }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-21 08:06:12 -04:00
|
|
|
describe '#user_provided_key' do
|
|
|
|
subject { domain.user_provided_key }
|
|
|
|
|
|
|
|
context 'when certificate is provided by user' do
|
|
|
|
let(:domain) { create(:pages_domain) }
|
|
|
|
|
|
|
|
it 'returns key' do
|
|
|
|
is_expected.to eq(domain.key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when certificate is provided by gitlab' do
|
|
|
|
let(:domain) { create(:pages_domain, :letsencrypt) }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#user_provided_certificate' do
|
|
|
|
subject { domain.user_provided_certificate }
|
|
|
|
|
|
|
|
context 'when certificate is provided by user' do
|
|
|
|
let(:domain) { create(:pages_domain) }
|
|
|
|
|
|
|
|
it 'returns key' do
|
|
|
|
is_expected.to eq(domain.certificate)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when certificate is provided by gitlab' do
|
|
|
|
let(:domain) { create(:pages_domain, :letsencrypt) }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'certificate setter' do |attribute, setter_name, old_certificate_source, new_certificate_source|
|
|
|
|
let(:domain) do
|
|
|
|
create(:pages_domain, certificate_source: old_certificate_source)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:old_value) { domain.public_send(attribute) }
|
|
|
|
|
|
|
|
subject { domain.public_send(setter_name, new_value) }
|
|
|
|
|
|
|
|
context 'when value has been changed' do
|
|
|
|
let(:new_value) { 'new_value' }
|
|
|
|
|
|
|
|
it "assignes new value to #{attribute}" do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to change { domain.public_send(attribute) }.from(old_value).to('new_value')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'changes certificate source' do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to change { domain.certificate_source }.from(old_certificate_source).to(new_certificate_source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when value has not been not changed' do
|
|
|
|
let(:new_value) { old_value }
|
|
|
|
|
|
|
|
it 'does not change certificate source' do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.not_to change { domain.certificate_source }.from(old_certificate_source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#user_provided_key=' do
|
|
|
|
include_examples('certificate setter', 'key', 'user_provided_key=',
|
|
|
|
'gitlab_provided', 'user_provided')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#gitlab_provided_key=' do
|
|
|
|
include_examples('certificate setter', 'key', 'gitlab_provided_key=',
|
|
|
|
'user_provided', 'gitlab_provided')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#user_provided_certificate=' do
|
|
|
|
include_examples('certificate setter', 'certificate', 'user_provided_certificate=',
|
|
|
|
'gitlab_provided', 'user_provided')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#gitlab_provided_certificate=' do
|
|
|
|
include_examples('certificate setter', 'certificate', 'gitlab_provided_certificate=',
|
|
|
|
'user_provided', 'gitlab_provided')
|
|
|
|
end
|
|
|
|
|
2020-04-14 17:09:52 -04:00
|
|
|
describe '#save' do
|
|
|
|
context 'when we failed to obtain ssl certificate' do
|
|
|
|
let(:domain) { create(:pages_domain, auto_ssl_enabled: true, auto_ssl_failed: true) }
|
|
|
|
|
|
|
|
it 'clears failure if auto ssl is disabled' do
|
|
|
|
expect do
|
|
|
|
domain.update!(auto_ssl_enabled: false)
|
|
|
|
end.to change { domain.auto_ssl_failed }.from(true).to(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not clear failure on unrelated updates' do
|
|
|
|
expect do
|
2020-05-22 05:08:09 -04:00
|
|
|
domain.update!(verified_at: Time.current)
|
2020-04-14 17:09:52 -04:00
|
|
|
end.not_to change { domain.auto_ssl_failed }.from(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-30 08:05:54 -04:00
|
|
|
describe '.for_removal' do
|
|
|
|
subject { described_class.for_removal }
|
|
|
|
|
|
|
|
context 'when domain is not schedule for removal' do
|
|
|
|
let!(:domain) { create :pages_domain }
|
|
|
|
|
|
|
|
it 'does not return domain' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when domain is scheduled for removal yesterday' do
|
|
|
|
let!(:domain) { create :pages_domain, remove_at: 1.day.ago }
|
|
|
|
|
|
|
|
it 'returns domain' do
|
|
|
|
is_expected.to eq([domain])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when domain is scheduled for removal tomorrow' do
|
|
|
|
let!(:domain) { create :pages_domain, remove_at: 1.day.from_now }
|
|
|
|
|
|
|
|
it 'does not return domain' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-06-24 16:35:12 -04:00
|
|
|
|
2020-02-17 19:09:20 -05:00
|
|
|
describe '.instance_serverless' do
|
|
|
|
subject { described_class.instance_serverless }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:pages_domain, wildcard: true)
|
|
|
|
create(:pages_domain, :instance_serverless)
|
|
|
|
create(:pages_domain, scope: :instance)
|
|
|
|
create(:pages_domain, :instance_serverless)
|
|
|
|
create(:pages_domain, usage: :serverless)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns domains that are wildcard, instance-level, and serverless' do
|
|
|
|
expect(subject.length).to eq(2)
|
|
|
|
|
|
|
|
subject.each do |domain|
|
|
|
|
expect(domain.wildcard).to eq(true)
|
|
|
|
expect(domain.usage).to eq('serverless')
|
|
|
|
expect(domain.scope).to eq('instance')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-24 16:35:12 -04:00
|
|
|
describe '.need_auto_ssl_renewal' do
|
|
|
|
subject { described_class.need_auto_ssl_renewal }
|
|
|
|
|
|
|
|
let!(:domain_with_user_provided_certificate) { create(:pages_domain) }
|
|
|
|
let!(:domain_with_expired_user_provided_certificate) do
|
|
|
|
create(:pages_domain, :with_expired_certificate)
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2019-06-24 16:35:12 -04:00
|
|
|
let!(:domain_with_user_provided_certificate_and_auto_ssl) do
|
|
|
|
create(:pages_domain, auto_ssl_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:domain_with_gitlab_provided_certificate) { create(:pages_domain, :letsencrypt) }
|
|
|
|
let!(:domain_with_expired_gitlab_provided_certificate) do
|
|
|
|
create(:pages_domain, :letsencrypt, :with_expired_certificate)
|
|
|
|
end
|
|
|
|
|
2020-04-22 05:09:36 -04:00
|
|
|
let!(:domain_with_failed_auto_ssl) do
|
|
|
|
create(:pages_domain, auto_ssl_enabled: true, auto_ssl_failed: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains only domains needing ssl renewal' do
|
2019-06-24 16:35:12 -04:00
|
|
|
is_expected.to(
|
|
|
|
contain_exactly(
|
|
|
|
domain_with_user_provided_certificate_and_auto_ssl,
|
|
|
|
domain_with_expired_gitlab_provided_certificate
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2019-09-10 20:04:16 -04:00
|
|
|
|
2019-09-25 05:06:04 -04:00
|
|
|
describe '#pages_virtual_domain' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:pages_domain) { create(:pages_domain, project: project) }
|
2019-09-10 20:04:16 -04:00
|
|
|
|
2019-09-25 05:06:04 -04:00
|
|
|
context 'when there are no pages deployed for the project' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(pages_domain.pages_virtual_domain).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-09-10 20:04:16 -04:00
|
|
|
|
2022-07-06 11:08:08 -04:00
|
|
|
context 'when there are pages deployed for the project' do
|
|
|
|
let(:virtual_domain) { pages_domain.pages_virtual_domain }
|
2019-09-25 05:06:04 -04:00
|
|
|
|
2022-07-06 11:08:08 -04:00
|
|
|
before do
|
|
|
|
project.mark_pages_as_deployed
|
|
|
|
project.update_pages_deployment!(create(:pages_deployment, project: project))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the virual domain when there are pages deployed for the project' do
|
|
|
|
expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain)
|
|
|
|
expect(virtual_domain.lookup_paths).not_to be_empty
|
2022-10-03 08:08:27 -04:00
|
|
|
expect(virtual_domain.cache_key).to match(/pages_domain_for_project_#{project.id}_/)
|
2022-07-06 11:08:08 -04:00
|
|
|
end
|
2019-09-10 20:04:16 -04:00
|
|
|
|
2022-07-06 11:08:08 -04:00
|
|
|
context 'when :cache_pages_domain_api is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(cache_pages_domain_api: false)
|
|
|
|
end
|
2019-10-01 08:05:59 -04:00
|
|
|
|
2022-07-06 11:08:08 -04:00
|
|
|
it 'returns the virual domain when there are pages deployed for the project' do
|
|
|
|
expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain)
|
|
|
|
expect(virtual_domain.lookup_paths).not_to be_empty
|
|
|
|
expect(virtual_domain.cache_key).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-09-10 20:04:16 -04:00
|
|
|
end
|
|
|
|
end
|
2020-02-25 16:09:23 -05:00
|
|
|
|
2022-09-11 23:13:31 -04:00
|
|
|
describe '#validate_custom_domain_count_per_project' do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
|
|
|
context 'when max custom domain setting is set to 0' do
|
|
|
|
it 'returns without an error' do
|
|
|
|
pages_domain = create(:pages_domain, project: project)
|
|
|
|
|
|
|
|
expect(pages_domain).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when max custom domain setting is not set to 0' do
|
|
|
|
it 'returns with an error for extra domains' do
|
|
|
|
Gitlab::CurrentSettings.update!(max_pages_custom_domains_per_project: 1)
|
|
|
|
|
|
|
|
pages_domain = create(:pages_domain, project: project)
|
|
|
|
expect(pages_domain).to be_valid
|
|
|
|
|
|
|
|
pages_domain = build(:pages_domain, project: project)
|
|
|
|
expect(pages_domain).not_to be_valid
|
|
|
|
expect(pages_domain.errors.full_messages)
|
|
|
|
.to contain_exactly('This project reached the limit of custom domains. (Max 1)')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-25 16:09:23 -05:00
|
|
|
describe '.find_by_domain_case_insensitive' do
|
|
|
|
it 'lookup is case-insensitive' do
|
|
|
|
pages_domain = create(:pages_domain, domain: "Pages.IO")
|
|
|
|
|
|
|
|
expect(PagesDomain.find_by_domain_case_insensitive('pages.io')).to eq(pages_domain)
|
|
|
|
end
|
|
|
|
end
|
2016-02-12 10:05:17 -05:00
|
|
|
end
|