email_address_validation_spec.rb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe EmailAddressValidation do
  4. describe 'Valid email address' do
  5. describe 'with dot in domain' do
  6. describe 'with MX record' do
  7. let(:email_address) { 'greetings@example.com' }
  8. let(:email_address_validation) { described_class.new(email_address) }
  9. it 'reports given email address' do
  10. expect(email_address_validation.email_address).to eq(email_address)
  11. expect(email_address_validation.to_s).to eq(email_address)
  12. end
  13. it 'reports email address as valid' do
  14. expect(email_address_validation.valid_format?).to be(true)
  15. end
  16. it 'reports email address to have domain with MX record' do
  17. expect(email_address_validation.valid_mx?).to be(true)
  18. end
  19. end
  20. describe 'without MX record' do
  21. let(:email_address) { 'someone@this-is-probably-a-non-existent-domain.com.example' }
  22. let(:email_address_validation) { described_class.new(email_address) }
  23. it 'reports given email address' do
  24. expect(email_address_validation.email_address).to eq(email_address)
  25. expect(email_address_validation.to_s).to eq(email_address)
  26. end
  27. it 'reports email address as valid' do
  28. expect(email_address_validation.valid_format?).to be(true)
  29. end
  30. it 'reports email address to have domain without MX record' do
  31. expect(email_address_validation.valid_mx?).to be(false)
  32. end
  33. end
  34. end
  35. describe 'without dot in domain' do
  36. let(:email_address) { 'greetings@localhost' }
  37. let(:email_address_validation) { described_class.new(email_address) }
  38. it 'reports given email address' do
  39. expect(email_address_validation.email_address).to eq(email_address)
  40. expect(email_address_validation.to_s).to eq(email_address)
  41. end
  42. it 'reports email address as valid' do
  43. expect(email_address_validation.valid_format?).to be(true)
  44. end
  45. it 'reports email address to have domain without MX record' do
  46. expect(email_address_validation.valid_mx?).to be(false)
  47. end
  48. end
  49. end
  50. describe 'Email address' do
  51. describe 'without domain' do
  52. let(:email_address) { 'zammad' }
  53. let(:email_address_validation) { described_class.new(email_address) }
  54. it 'reports given email address' do
  55. expect(email_address_validation.email_address).to eq(email_address)
  56. expect(email_address_validation.to_s).to eq(email_address)
  57. end
  58. it 'reports email address as invalid' do
  59. expect(email_address_validation.valid_format?).to be(false)
  60. end
  61. it 'reports email address to have domain without MX record' do
  62. expect(email_address_validation.valid_mx?).to be(false)
  63. end
  64. end
  65. describe 'with invalid domain format' do
  66. let(:email_address) { 'greetings@example..com' }
  67. let(:email_address_validation) { described_class.new(email_address) }
  68. it 'reports given email address' do
  69. expect(email_address_validation.email_address).to eq(email_address)
  70. expect(email_address_validation.to_s).to eq(email_address)
  71. end
  72. it 'reports email address as invalid' do
  73. expect(email_address_validation.valid_format?).to be(false)
  74. end
  75. it 'reports email address to have domain without MX record' do
  76. expect(email_address_validation.valid_mx?).to be(false)
  77. end
  78. end
  79. describe 'which is empty' do
  80. let(:email_address) { '' }
  81. let(:email_address_validation) { described_class.new(email_address) }
  82. it 'reports given email address' do
  83. expect(email_address_validation.email_address).to eq(email_address)
  84. expect(email_address_validation.to_s).to eq(email_address)
  85. end
  86. it 'reports email address as invalid' do
  87. expect(email_address_validation.valid_format?).to be(false)
  88. end
  89. it 'reports email address to have domain without MX record' do
  90. expect(email_address_validation.valid_mx?).to be(false)
  91. end
  92. end
  93. end
  94. end