Skip to content

Commit

Permalink
Merge pull request #358 from alphagov/ENG-462/allow_gpa_emails
Browse files Browse the repository at this point in the history
ENG-462: Allow GPA email addresses to log in and request new users and accounts
  • Loading branch information
stephengrier authored Sep 9, 2024
2 parents 8c1fb7b + e0fe4a7 commit 43ebd79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/lib/email_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def self.email_is_allowed_basic?(email)
end
return true if email.end_with? '@digital.cabinet-office.gov.uk'
return true if email.end_with? '@cabinetoffice.gov.uk'
return true if email.end_with? '@gpa.gov.uk'
return true if email.end_with? '@softwire.com'
return true if email.end_with? '@fidusinfosec.com'
return true if email.end_with? '@cyberis.com'
Expand All @@ -21,6 +22,7 @@ def self.email_is_allowed_advanced?(email)
end
return true if email.end_with? '@digital.cabinet-office.gov.uk'
return true if email.end_with? '@cabinetoffice.gov.uk'
return true if email.end_with? '@gpa.gov.uk'
false
end

Expand All @@ -29,6 +31,7 @@ def self.allowed_emails_regexp
/\A(#{Regexp.union(
/([a-z0-9.\-\']+@digital\.cabinet-office\.gov\.uk,?\s*)/,
/([a-z0-9.\-\']+@cabinetoffice\.gov\.uk,?\s*)/,
/([a-z0-9.\-\']+@gpa\.gov\.uk,?\s*)/,
/([a-z0-9.\-\']+@softwire\.com,?\s*)/,
/([a-z0-9.\-\']+@fidusinfosec\.com,?\s*)/,
/([a-z0-9.\-\']+@cyberis\.com,?\s*)/,
Expand Down
15 changes: 15 additions & 0 deletions test/lib/email_validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class EmailValidatorTest < ActiveSupport::TestCase
assert EmailValidator.email_is_allowed_basic?(email)
end

test 'Government Property Agency email addresses are allowed to sign in' do
email = 'fname.lname@gpa.gov.uk'
assert EmailValidator.email_is_allowed_basic?(email)
end

test 'Softwire email addresses are allowed to sign in' do
email = 'fname.lname@softwire.com'
assert EmailValidator.email_is_allowed_basic?(email)
Expand Down Expand Up @@ -46,6 +51,11 @@ class EmailValidatorTest < ActiveSupport::TestCase
assert EmailValidator.email_is_allowed_advanced?(email)
end

test 'Government Property Agency email addresses are allowed to manage users' do
email = 'fname.lname@gpa.gov.uk'
assert EmailValidator.email_is_allowed_advanced?(email)
end

test 'Softwire email addresses are not allowed to manage users' do
email = 'fname.lname@softwire.com'
assert ! EmailValidator.email_is_allowed_advanced?(email)
Expand Down Expand Up @@ -76,6 +86,11 @@ class EmailValidatorTest < ActiveSupport::TestCase
assert_match EmailValidator.allowed_emails_regexp, email
end

test 'Government Property Agency emails can be used as usernames for new users' do
email = 'fname.lname@gpa.gov.uk'
assert_match EmailValidator.allowed_emails_regexp, email
end

test 'Softwire emails are matched by the allowed emails regexp' do
email = 'fname.lname@softwire.com'
assert_match EmailValidator.allowed_emails_regexp, email
Expand Down

0 comments on commit 43ebd79

Please sign in to comment.