You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

email_address_test.rb 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class EmailAddressTest < ActiveSupport::TestCase
  20. fixtures :users
  21. def setup
  22. User.current = nil
  23. end
  24. def test_address_with_punycode_tld_should_be_valid
  25. email = EmailAddress.new(address: 'jsmith@example.xn--80akhbyknj4f')
  26. assert email.valid?
  27. end
  28. def test_address_should_be_validated_against_denied_domains
  29. with_settings :email_domains_denied => "black.test\r\nBLACK.EXAMPLE, .subdomain.test" do
  30. email = EmailAddress.new(address: 'user@black.test')
  31. assert_not email.valid?
  32. email = EmailAddress.new(address: 'user@notblack.test')
  33. assert email.valid?
  34. email = EmailAddress.new(address: 'user@BLACK.TEST')
  35. assert_not email.valid?
  36. email = EmailAddress.new(address: 'user@black.example')
  37. assert_not email.valid?
  38. email = EmailAddress.new(address: 'user@subdomain.test')
  39. assert email.valid?
  40. email = EmailAddress.new(address: 'user@foo.subdomain.test')
  41. assert_not email.valid?
  42. end
  43. end
  44. def test_address_should_be_validated_against_allowed_domains
  45. with_settings :email_domains_allowed => "white.test\r\nWHITE.EXAMPLE, .subdomain.test" do
  46. email = EmailAddress.new(address: 'user@white.test')
  47. assert email.valid?
  48. email = EmailAddress.new(address: 'user@notwhite.test')
  49. assert_not email.valid?
  50. email = EmailAddress.new(address: 'user@WHITE.TEST')
  51. assert email.valid?
  52. email = EmailAddress.new(address: 'user@white.example')
  53. assert email.valid?
  54. email = EmailAddress.new(address: 'user@subdomain.test')
  55. assert_not email.valid?
  56. email = EmailAddress.new(address: 'user@foo.subdomain.test')
  57. assert email.valid?
  58. end
  59. end
  60. end