diff options
Diffstat (limited to 'spec/models/pages_domain_spec.rb')
-rw-r--r-- | spec/models/pages_domain_spec.rb | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb index 4b85c5e8720..4c776e2e6d9 100644 --- a/spec/models/pages_domain_spec.rb +++ b/spec/models/pages_domain_spec.rb @@ -1,37 +1,37 @@ -require 'spec_helper' +require "spec_helper" describe PagesDomain do using RSpec::Parameterized::TableSyntax subject(:pages_domain) { described_class.new } - describe 'associations' do + describe "associations" do it { is_expected.to belong_to(:project) } end - describe 'validate domain' do + describe "validate domain" do subject(:pages_domain) { build(:pages_domain, domain: domain) } - context 'is unique' do - let(:domain) { 'my.domain.com' } + context "is unique" do + let(:domain) { "my.domain.com" } it { is_expected.to validate_uniqueness_of(:domain).case_insensitive } end describe "hostname" do { - 'my.domain.com' => true, - '123.456.789' => true, - '0x12345.com' => true, - '0123123' => true, - '_foo.com' => false, - 'reserved.com' => false, - 'a.reserved.com' => false, - nil => false + "my.domain.com" => true, + "123.456.789" => true, + "0x12345.com" => true, + "0123123" => true, + "_foo.com" => false, + "reserved.com" => false, + "a.reserved.com" => false, + nil => false, }.each do |value, validity| context "domain #{value.inspect} validity" do before do - allow(Settings.pages).to receive(:host).and_return('reserved.com') + allow(Settings.pages).to receive(:host).and_return("reserved.com") end let(:domain) { value } @@ -44,7 +44,7 @@ describe PagesDomain do describe "HTTPS-only" do using RSpec::Parameterized::TableSyntax - let(:domain) { 'my.domain.com' } + let(:domain) { "my.domain.com" } let(:project) do instance_double(Project, pages_https_only?: pages_https_only) @@ -61,13 +61,13 @@ describe PagesDomain do attributes = attributes_for(:pages_domain) cert, key = attributes.fetch_values(:certificate, :key) - true | nil | nil | %i(certificate key) - true | cert | nil | %i(key) - true | nil | key | %i(certificate key) + true | nil | nil | %i[certificate key] + true | cert | nil | %i[key] + true | nil | key | %i[certificate key] true | cert | key | [] false | nil | nil | [] - false | cert | nil | %i(key) - false | nil | key | %i(key) + false | cert | nil | %i[key] + false | nil | key | %i[key] false | cert | key | [] end @@ -79,110 +79,110 @@ describe PagesDomain do end end - describe 'validate certificate' do + describe "validate certificate" do subject { domain } - context 'with matching key' do + context "with matching key" do let(:domain) { build(:pages_domain) } it { is_expected.to be_valid } end - context 'when no certificate is specified' do + context "when no certificate is specified" do let(:domain) { build(:pages_domain, :without_certificate) } it { is_expected.not_to be_valid } end - context 'when no key is specified' do + context "when no key is specified" do let(:domain) { build(:pages_domain, :without_key) } it { is_expected.not_to be_valid } end - context 'for not matching key' do + context "for not matching key" do let(:domain) { build(:pages_domain, :with_missing_chain) } it { is_expected.not_to be_valid } end end - describe 'validations' do + describe "validations" do it { is_expected.to validate_presence_of(:verification_code) } end - describe '#verification_code' do + 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' } + 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') + is_expected.to eq("verification code") end end - describe '#keyed_verification_code' do + 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 + 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' + 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') + is_expected.to eq("_gitlab-pages-verification-code.example.com") end end - describe '#url' do + describe "#url" do subject { domain.url } let(:domain) { build(:pages_domain) } it { is_expected.to eq("https://#{domain.domain}") } - context 'without the certificate' do + context "without the certificate" do let(:domain) { build(:pages_domain, :without_certificate) } it { is_expected.to eq("http://#{domain.domain}") } end end - describe '#has_matching_key?' do + describe "#has_matching_key?" do subject { domain.has_matching_key? } let(:domain) { build(:pages_domain) } it { is_expected.to be_truthy } - context 'for invalid key' do + context "for invalid key" do let(:domain) { build(:pages_domain, :with_missing_chain) } it { is_expected.to be_falsey } end end - describe '#has_intermediates?' do + describe "#has_intermediates?" do subject { domain.has_intermediates? } - context 'for self signed' do + context "for self signed" do let(:domain) { build(:pages_domain) } it { is_expected.to be_truthy } end - context 'for missing certificate chain' do + context "for missing certificate chain" do let(:domain) { build(:pages_domain, :with_missing_chain) } it { is_expected.to be_falsey } end - context 'for trusted certificate chain' do + context "for trusted certificate chain" do # 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 @@ -193,31 +193,31 @@ describe PagesDomain do end end - describe '#expired?' do + describe "#expired?" do subject { domain.expired? } - context 'for valid' do + context "for valid" do let(:domain) { build(:pages_domain) } it { is_expected.to be_falsey } end - context 'for expired' do + context "for expired" do let(:domain) { build(:pages_domain, :with_expired_certificate) } it { is_expected.to be_truthy } end end - describe '#subject' do + describe "#subject" do let(:domain) { build(:pages_domain) } subject { domain.subject } - it { is_expected.to eq('/CN=test-certificate') } + it { is_expected.to eq("/CN=test-certificate") } end - describe '#certificate_text' do + describe "#certificate_text" do let(:domain) { build(:pages_domain) } subject { domain.certificate_text } @@ -238,8 +238,8 @@ describe PagesDomain do end end - describe '#update_daemon' do - it 'runs when the domain is created' do + describe "#update_daemon" do + it "runs when the domain is created" do domain = build(:pages_domain) expect(domain).to receive(:update_daemon) @@ -247,7 +247,7 @@ describe PagesDomain do domain.save! end - it 'runs when the domain is destroyed' do + it "runs when the domain is destroyed" do domain = create(:pages_domain) expect(domain).to receive(:update_daemon) @@ -255,15 +255,15 @@ describe PagesDomain do domain.destroy! end - it 'delegates to Projects::UpdatePagesConfigurationService' do - service = instance_double('Projects::UpdatePagesConfigurationService') + it "delegates to Projects::UpdatePagesConfigurationService" do + service = instance_double("Projects::UpdatePagesConfigurationService") expect(Projects::UpdatePagesConfigurationService).to receive(:new) { service } expect(service).to receive(:execute) create(:pages_domain) end - context 'configuration updates when attributes change' do + context "configuration updates when attributes change" do set(:project1) { create(:project) } set(:project2) { create(:project) } set(:domain) { create(:pages_domain) } @@ -278,12 +278,12 @@ describe PagesDomain do :project | :project1 | nil | true # domain can't be set to nil - :domain | 'a.com' | 'a.com' | false - :domain | 'a.com' | 'b.com' | true + :domain | "a.com" | "a.com" | false + :domain | "a.com" | "b.com" | true # verification_code can't be set to nil - :verification_code | 'foo' | 'foo' | false - :verification_code | 'foo' | 'bar' | false + :verification_code | "foo" | "foo" | false + :verification_code | "foo" | "bar" | false :verified_at | nil | now | false :verified_at | now | now | false @@ -297,7 +297,7 @@ describe PagesDomain do end with_them do - it 'runs if a relevant attribute has changed' do + it "runs if a relevant attribute has changed" do a = old_value.is_a?(Symbol) ? send(old_value) : old_value b = new_value.is_a?(Symbol) ? send(new_value) : new_value @@ -313,28 +313,28 @@ describe PagesDomain do end end - context 'TLS configuration' do + context "TLS configuration" do set(:domain_without_tls) { create(:pages_domain, :without_certificate, :without_key) } set(:domain) { create(:pages_domain) } let(:cert1) { domain.certificate } - let(:cert2) { cert1 + ' ' } + let(:cert2) { cert1 + " " } let(:key1) { domain.key } - let(:key2) { key1 + ' ' } + let(:key2) { key1 + " " } - it 'updates when added' do + it "updates when added" do expect(domain_without_tls).to receive(:update_daemon) domain_without_tls.update!(key: key1, certificate: cert1) end - it 'updates when changed' do + it "updates when changed" do expect(domain).to receive(:update_daemon) domain.update!(key: key2, certificate: cert2) end - it 'updates when removed' do + it "updates when removed" do expect(domain).to receive(:update_daemon) domain.update!(key: nil, certificate: nil) |