summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorVladimir Shushlin <vshushlin@gitlab.com>2019-04-09 17:46:29 +0000
committerNick Thomas <nick@gitlab.com>2019-04-09 17:46:29 +0000
commitd69d29011cf9fe06e50a2c7d65b1ea88ea2d41d5 (patch)
treea794b2c4bfe9b00b552463928249b85957a5de05 /spec
parent61ab1f7364b1ea44984a67bb6ea0f5a2b7a353c8 (diff)
downloadgitlab-ce-d69d29011cf9fe06e50a2c7d65b1ea88ea2d41d5.tar.gz
Mark unverified pages domains for removal
Set pages_domain.remove_at when disabling it Add specs for marking pages domain for removal Notify user that domain is being removed Add documentation
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/pages_domains.rb4
-rw-r--r--spec/mailers/emails/pages_domains_spec.rb24
-rw-r--r--spec/services/verify_pages_domain_service_spec.rb89
3 files changed, 96 insertions, 21 deletions
diff --git a/spec/factories/pages_domains.rb b/spec/factories/pages_domains.rb
index 20671da016e..b74f72f2bd3 100644
--- a/spec/factories/pages_domains.rb
+++ b/spec/factories/pages_domains.rb
@@ -41,6 +41,10 @@ nNp/xedE1YxutQ==
enabled_until nil
end
+ trait :scheduled_for_removal do
+ remove_at { 1.day.from_now }
+ end
+
trait :unverified do
verified_at nil
end
diff --git a/spec/mailers/emails/pages_domains_spec.rb b/spec/mailers/emails/pages_domains_spec.rb
index c74fd66ad22..050af587061 100644
--- a/spec/mailers/emails/pages_domains_spec.rb
+++ b/spec/mailers/emails/pages_domains_spec.rb
@@ -26,6 +26,26 @@ describe Emails::PagesDomains do
end
end
+ shared_examples 'notification about upcoming domain removal' do
+ context 'when domain is not scheduled for removal' do
+ it 'asks user to remove it' do
+ is_expected.to have_body_text 'please remove it'
+ end
+ end
+
+ context 'when domain is scheduled for removal' do
+ before do
+ domain.update!(remove_at: 1.week.from_now)
+ end
+ it 'notifies user that domain will be removed automatically' do
+ aggregate_failures do
+ is_expected.to have_body_text domain.remove_at.strftime('%F %T')
+ is_expected.to have_body_text "it will be removed from your GitLab project"
+ end
+ end
+ end
+ end
+
describe '#pages_domain_enabled_email' do
let(:email_subject) { "#{project.path} | GitLab Pages domain '#{domain.domain}' has been enabled" }
@@ -43,6 +63,8 @@ describe Emails::PagesDomains do
it_behaves_like 'a pages domain email'
+ it_behaves_like 'notification about upcoming domain removal'
+
it { is_expected.to have_body_text 'has been disabled' }
end
@@ -63,6 +85,8 @@ describe Emails::PagesDomains do
it_behaves_like 'a pages domain email'
+ it_behaves_like 'notification about upcoming domain removal'
+
it 'says verification has failed and when the domain is enabled until' do
is_expected.to have_body_text 'Verification has failed'
is_expected.to have_body_text domain.enabled_until.strftime('%F %T')
diff --git a/spec/services/verify_pages_domain_service_spec.rb b/spec/services/verify_pages_domain_service_spec.rb
index ddf9d2b4917..b60b13bb3fc 100644
--- a/spec/services/verify_pages_domain_service_spec.rb
+++ b/spec/services/verify_pages_domain_service_spec.rb
@@ -27,6 +27,7 @@ describe VerifyPagesDomainService do
expect(domain).to be_verified
expect(domain).to be_enabled
+ expect(domain.remove_at).to be_nil
end
end
@@ -48,18 +49,32 @@ describe VerifyPagesDomainService do
end
end
+ shared_examples 'unverifies and disables domain' do
+ it 'unverifies domain' do
+ expect(service.execute).to eq(error_status)
+ expect(domain).not_to be_verified
+ end
+
+ it 'disables domain and shedules it for removal' do
+ Timecop.freeze do
+ service.execute
+ expect(domain).not_to be_enabled
+ expect(domain.remove_at).to be_within(1.second).of(1.week.from_now)
+ end
+ end
+ end
+
context 'when domain is disabled(or new)' do
let(:domain) { create(:pages_domain, :disabled) }
include_examples 'successful enablement and verification'
- shared_examples 'unverifies and disables domain' do
- it 'unverifies and disables domain' do
- expect(service.execute).to eq(error_status)
-
- expect(domain).not_to be_verified
- expect(domain).not_to be_enabled
+ context 'when txt record does not contain verification code' do
+ before do
+ stub_resolver(domain_name => 'something else')
end
+
+ include_examples 'unverifies and disables domain'
end
context 'when txt record does not contain verification code' do
@@ -84,16 +99,25 @@ describe VerifyPagesDomainService do
include_examples 'successful enablement and verification'
- context 'when txt record does not contain verification code' do
- before do
- stub_resolver(domain_name => 'something else')
- end
-
+ shared_examples 'unverifing domain' do
it 'unverifies but does not disable domain' do
expect(service.execute).to eq(error_status)
expect(domain).not_to be_verified
expect(domain).to be_enabled
end
+
+ it 'does not schedule domain for removal' do
+ service.execute
+ expect(domain.remove_at).to be_nil
+ end
+ end
+
+ context 'when txt record does not contain verification code' do
+ before do
+ stub_resolver(domain_name => 'something else')
+ end
+
+ include_examples 'unverifing domain'
end
context 'when no txt records are present' do
@@ -101,11 +125,7 @@ describe VerifyPagesDomainService do
stub_resolver
end
- it 'unverifies but does not disable domain' do
- expect(service.execute).to eq(error_status)
- expect(domain).not_to be_verified
- expect(domain).to be_enabled
- end
+ include_examples 'unverifing domain'
end
end
@@ -125,13 +145,40 @@ describe VerifyPagesDomainService do
stub_resolver
end
- it 'disables domain' do
- error_status[:message] += '. It is now disabled.'
+ let(:error_status) { { status: :error, message: "Couldn't verify #{domain.domain}. It is now disabled." } }
- expect(service.execute).to eq(error_status)
+ include_examples 'unverifies and disables domain'
+ end
+ end
- expect(domain).not_to be_verified
- expect(domain).not_to be_enabled
+ context 'when domain is disabled and scheduled for removal' do
+ let(:domain) { create(:pages_domain, :disabled, :scheduled_for_removal) }
+
+ context 'when the right code is present' do
+ before do
+ stub_resolver(domain.domain => domain.keyed_verification_code)
+ end
+
+ it 'verifies and enables domain' do
+ expect(service.execute).to eq(status: :success)
+
+ expect(domain).to be_verified
+ expect(domain).to be_enabled
+ end
+
+ it 'prevent domain from being removed' do
+ expect { service.execute }.to change { domain.remove_at }.to(nil)
+ end
+ end
+
+ context 'when the right code is not present' do
+ before do
+ stub_resolver
+ end
+
+ it 'keeps domain scheduled for removal but does not change removal time' do
+ expect { service.execute }.not_to change { domain.remove_at }
+ expect(domain.remove_at).to be_present
end
end
end