From ee837184df37014809ff8dbf546551ca83b40be8 Mon Sep 17 00:00:00 2001 From: StevenLeighton21 Date: Thu, 26 Oct 2023 14:16:37 +0100 Subject: [PATCH] Allow case insensitive domains for service_email_output (#2467) * Allow case insensitive domains for service_email_output --- Gemfile.lock | 6 ++++++ app/validators/domain_validator.rb | 2 +- spec/models/email_settings_spec.rb | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 779578f7f..565907108 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -180,6 +180,7 @@ GEM ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) + google-protobuf (3.24.4) google-protobuf (3.24.4-x86_64-darwin) google-protobuf (3.24.4-x86_64-linux) googleapis-common-protos-types (1.9.0) @@ -284,6 +285,7 @@ GEM sprockets-rails method_source (1.0.0) mini_mime (1.1.5) + mini_portile2 (2.8.5) minitest (5.20.0) msgpack (1.7.2) multi_json (1.15.0) @@ -299,6 +301,9 @@ GEM net-smtp (0.4.0) net-protocol nio4r (2.5.9) + nokogiri (1.15.4) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) nokogiri (1.15.4-x86_64-darwin) racc (~> 1.4) nokogiri (1.15.4-x86_64-linux) @@ -728,6 +733,7 @@ GEM zeitwerk (2.6.12) PLATFORMS + ruby x86_64-darwin-20 x86_64-darwin-21 x86_64-linux diff --git a/app/validators/domain_validator.rb b/app/validators/domain_validator.rb index 64948e43d..c3f21b0f4 100644 --- a/app/validators/domain_validator.rb +++ b/app/validators/domain_validator.rb @@ -1,7 +1,7 @@ class DomainValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) domain = value.split('@').last - if value.present? && !domain.in?(Rails.application.config.allowed_domains) + if value.present? && !domain.downcase.in?(Rails.application.config.allowed_domains) record.errors.add( attribute, I18n.t("activemodel.errors.models.#{record.model_name.singular}.domain_invalid") diff --git a/spec/models/email_settings_spec.rb b/spec/models/email_settings_spec.rb index da4993cd7..b193aa29b 100644 --- a/spec/models/email_settings_spec.rb +++ b/spec/models/email_settings_spec.rb @@ -27,6 +27,12 @@ ).for(:service_email_output) end + it 'allows domains case insensitive' do + should allow_values( + 'frodo@digital.Justice.gov.uk' + ).for(:service_email_output) + end + it 'do not allow malformed emails' do should_not allow_values( 'organa', 'leia'