From 77e2e453649220ba9c002c935bbc18c34fbf5b11 Mon Sep 17 00:00:00 2001 From: Vladimir Shushlin Date: Mon, 22 Jul 2019 15:38:08 +0000 Subject: Validate certificate chain only if it's changed This validation prevents the domain from being saved from the UI e.g. when user tries to enable Let's Encrypt integration --- spec/models/pages_domain_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'spec/models/pages_domain_spec.rb') diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb index 973c67937b7..519c519fbcf 100644 --- a/spec/models/pages_domain_spec.rb +++ b/spec/models/pages_domain_spec.rb @@ -127,6 +127,30 @@ describe PagesDomain do it { is_expected.not_to be_valid } end + + 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? + + expect(domain.errors.keys).to contain_exactly(:key, :certificate) + end + end + + context 'when certificate is already saved' do + it "doesn't add error to certificate" do + domain.save(validate: false) + + domain.valid? + + expect(domain.errors.keys).to contain_exactly(:key) + end + end + end end describe 'validations' do -- cgit v1.2.1