From 686795eed3e3cf3dc9b7a0ba73e4c43540b5f3c6 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Mon, 26 Mar 2018 14:54:59 +0100 Subject: [PATCH] Allow pages domain verification to run on invalid domains --- app/services/verify_pages_domain_service.rb | 10 +++++++--- ...-domain-verification-validation-errors.yml | 5 +++++ .../verify_pages_domain_service_spec.rb | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/43794-fix-domain-verification-validation-errors.yml diff --git a/app/services/verify_pages_domain_service.rb b/app/services/verify_pages_domain_service.rb index 86166047302..13cb53dee01 100644 --- a/app/services/verify_pages_domain_service.rb +++ b/app/services/verify_pages_domain_service.rb @@ -34,7 +34,8 @@ class VerifyPagesDomainService < BaseService # Prevent any pre-existing grace period from being truncated reverify = [domain.enabled_until, VERIFICATION_PERIOD.from_now].compact.max - domain.update!(verified_at: Time.now, enabled_until: reverify) + domain.assign_attributes(verified_at: Time.now, enabled_until: reverify) + domain.save!(validate: false) if was_disabled notify(:enabled) @@ -47,7 +48,9 @@ class VerifyPagesDomainService < BaseService def unverify_domain! if domain.verified? - domain.update!(verified_at: nil) + domain.assign_attributes(verified_at: nil) + domain.save!(validate: false) + notify(:verification_failed) end @@ -55,7 +58,8 @@ class VerifyPagesDomainService < BaseService end def disable_domain! - domain.update!(verified_at: nil, enabled_until: nil) + domain.assign_attributes(verified_at: nil, enabled_until: nil) + domain.save!(validate: false) notify(:disabled) diff --git a/changelogs/unreleased/43794-fix-domain-verification-validation-errors.yml b/changelogs/unreleased/43794-fix-domain-verification-validation-errors.yml new file mode 100644 index 00000000000..861820c7538 --- /dev/null +++ b/changelogs/unreleased/43794-fix-domain-verification-validation-errors.yml @@ -0,0 +1,5 @@ +--- +title: Avoid validation errors when running the Pages domain verification service +merge_request: 17992 +author: +type: fixed diff --git a/spec/services/verify_pages_domain_service_spec.rb b/spec/services/verify_pages_domain_service_spec.rb index 576db1dde2d..d974cc0226f 100644 --- a/spec/services/verify_pages_domain_service_spec.rb +++ b/spec/services/verify_pages_domain_service_spec.rb @@ -93,6 +93,25 @@ describe VerifyPagesDomainService do expect(domain).not_to be_enabled end end + + context 'invalid domain' do + let(:domain) { build(:pages_domain, :expired, :with_missing_chain) } + + before do + domain.save(validate: false) + end + + it 'can be disabled' do + error_status[:message] += '. It is now disabled.' + + stub_resolver + + expect(service.execute).to eq(error_status) + + expect(domain).not_to be_verified + expect(domain).not_to be_enabled + end + end end context 'timeout behaviour' do