Skip to content

Commit

Permalink
Allow case insensitive domains for service_email_output (#2467)
Browse files Browse the repository at this point in the history
* Allow case insensitive domains for service_email_output
  • Loading branch information
StevenLeighton21 authored Oct 26, 2023
1 parent 8b0e2bb commit ee83718
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -728,6 +733,7 @@ GEM
zeitwerk (2.6.12)

PLATFORMS
ruby
x86_64-darwin-20
x86_64-darwin-21
x86_64-linux
Expand Down
2 changes: 1 addition & 1 deletion app/validators/domain_validator.rb
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
6 changes: 6 additions & 0 deletions spec/models/email_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
).for(:service_email_output)
end

it 'allows domains case insensitive' do
should allow_values(
'[email protected]'
).for(:service_email_output)
end

it 'do not allow malformed emails' do
should_not allow_values(
'organa', 'leia'
Expand Down

0 comments on commit ee83718

Please sign in to comment.