diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/lets_encrypt/client_spec.rb | 36 | ||||
-rw-r--r-- | spec/lib/gitlab/lets_encrypt_spec.rb | 56 | ||||
-rw-r--r-- | spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb | 13 | ||||
-rw-r--r-- | spec/workers/pages_domain_ssl_renewal_worker_spec.rb | 19 |
4 files changed, 79 insertions, 45 deletions
diff --git a/spec/lib/gitlab/lets_encrypt/client_spec.rb b/spec/lib/gitlab/lets_encrypt/client_spec.rb index 5454d9c1af4..cbb862cb0c9 100644 --- a/spec/lib/gitlab/lets_encrypt/client_spec.rb +++ b/spec/lib/gitlab/lets_encrypt/client_spec.rb @@ -116,42 +116,6 @@ describe ::Gitlab::LetsEncrypt::Client do end end - describe '#enabled?' do - subject { client.enabled? } - - context 'when terms of service are accepted' do - it { is_expected.to eq(true) } - - context "when private_key isn't present and database is read only" do - before do - allow(::Gitlab::Database).to receive(:read_only?).and_return(true) - end - - it 'returns false' do - expect(::Gitlab::CurrentSettings.lets_encrypt_private_key).to eq(nil) - - is_expected.to eq(false) - end - end - - context 'when feature flag is disabled' do - before do - stub_feature_flags(pages_auto_ssl: false) - end - - it { is_expected.to eq(false) } - end - end - - context 'when terms of service are not accepted' do - before do - stub_application_setting(lets_encrypt_terms_of_service_accepted: false) - end - - it { is_expected.to eq(false) } - end - end - describe '#terms_of_service_url' do subject { client.terms_of_service_url } diff --git a/spec/lib/gitlab/lets_encrypt_spec.rb b/spec/lib/gitlab/lets_encrypt_spec.rb new file mode 100644 index 00000000000..674b114e9d3 --- /dev/null +++ b/spec/lib/gitlab/lets_encrypt_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::Gitlab::LetsEncrypt do + include LetsEncryptHelpers + + before do + stub_lets_encrypt_settings + end + + describe '.enabled?' do + let(:project) { create(:project) } + let(:pages_domain) { create(:pages_domain, project: project) } + + subject { described_class.enabled?(pages_domain) } + + context 'when terms of service are accepted' do + it { is_expected.to eq(true) } + + context 'when feature flag is disabled' do + before do + stub_feature_flags(pages_auto_ssl: false) + end + + it { is_expected.to eq(false) } + end + end + + context 'when terms of service are not accepted' do + before do + stub_application_setting(lets_encrypt_terms_of_service_accepted: false) + end + + it { is_expected.to eq(false) } + end + + context 'when feature flag for project is disabled' do + before do + stub_feature_flags(pages_auto_ssl_for_project: false) + end + + it 'returns false' do + is_expected.to eq(false) + end + end + + context 'when domain has not project' do + let(:pages_domain) { create(:pages_domain) } + + it 'returns false' do + is_expected.to eq(false) + end + end + end +end diff --git a/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb b/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb index 2ae4872f51d..08a3511f70b 100644 --- a/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb +++ b/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb @@ -12,15 +12,18 @@ describe PagesDomainSslRenewalCronWorker do end describe '#perform' do - let!(:domain) { create(:pages_domain) } - let!(:domain_with_enabled_auto_ssl) { create(:pages_domain, auto_ssl_enabled: true) } - let!(:domain_with_obtained_letsencrypt) { create(:pages_domain, :letsencrypt, auto_ssl_enabled: true) } + let(:project) { create :project } + let!(:domain) { create(:pages_domain, project: project) } + let!(:domain_with_enabled_auto_ssl) { create(:pages_domain, project: project, auto_ssl_enabled: true) } + let!(:domain_with_obtained_letsencrypt) do + create(:pages_domain, :letsencrypt, project: project, auto_ssl_enabled: true) + end let!(:domain_without_auto_certificate) do - create(:pages_domain, :without_certificate, :without_key, auto_ssl_enabled: true) + create(:pages_domain, :without_certificate, :without_key, project: project, auto_ssl_enabled: true) end let!(:domain_with_expired_auto_ssl) do - create(:pages_domain, :letsencrypt, :with_expired_certificate) + create(:pages_domain, :letsencrypt, :with_expired_certificate, project: project) end it 'enqueues a PagesDomainSslRenewalWorker for domains needing renewal' do diff --git a/spec/workers/pages_domain_ssl_renewal_worker_spec.rb b/spec/workers/pages_domain_ssl_renewal_worker_spec.rb index a3d33de1b40..3552ff0823a 100644 --- a/spec/workers/pages_domain_ssl_renewal_worker_spec.rb +++ b/spec/workers/pages_domain_ssl_renewal_worker_spec.rb @@ -7,7 +7,8 @@ describe PagesDomainSslRenewalWorker do subject(:worker) { described_class.new } - let(:domain) { create(:pages_domain) } + let(:project) { create(:project) } + let(:domain) { create(:pages_domain, project: project) } before do stub_lets_encrypt_settings @@ -22,14 +23,24 @@ describe PagesDomainSslRenewalWorker do worker.perform(domain.id) end + shared_examples 'does nothing' do + it 'does nothing' do + expect(::PagesDomains::ObtainLetsEncryptCertificateService).not_to receive(:new) + end + end + context 'when domain was deleted' do before do domain.destroy! end - it 'does nothing' do - expect(::PagesDomains::ObtainLetsEncryptCertificateService).not_to receive(:new) - end + include_examples 'does nothing' + end + + context 'when domain is disabled' do + let(:domain) { create(:pages_domain, :disabled) } + + include_examples 'does nothing' end end end |