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.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- 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_relative '../test_helper'
  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. def test_should_reject_invalid_email
  61. assert_not EmailAddress.new(address: 'invalid,email@example.com').valid?
  62. end
  63. def test_should_normalize_idn_email_address
  64. email = EmailAddress.new(address: 'marie@société.example')
  65. assert_equal 'marie@xn--socit-esab.example', email.address
  66. assert email.valid?
  67. end
  68. end