Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MX validation behaves inconsistently depending on network connectivity #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

afair
Copy link
Owner

@afair afair commented Nov 23, 2019

Description: Validation gives inconsistent results depending on network status.

Reproduction:

  1. Turn off your network connection.

  2. Do the following:

    irb(main):001:0> require 'email_address'
    => true
    irb(main):002:0> EmailAddress::Config.configure(host_validation: :mx)
    => {:dns_lookup=>:mx, :sha1_secret=>"", :munge_string=>"*****", :local_downcase=>true, :local_fix=>false, :local_encoding=>:ascii, :local_parse=>nil, :local_format=>:conventional, :local_size=>1..64, :tag_separator=>"+", :mailbox_size=>1..64, :mailbox_canonical=>nil, :mailbox_validator=>nil, :host_encoding=>:punycode, :host_validation=>:mx, :host_size=>1..253, :host_allow_ip=>false, :host_remove_spaces=>false, :host_local=>false, :address_validation=>:parts, :address_size=>3..254, :address_fqdn_domain=>nil}
    irb(main):003:0> EmailAddress.error('[email protected]')
    => "Domain name not registered"
    
  3. Turn your network connection back on.

  4. In the same IRB session, with connectivity restored:

    irb(main):004:0> EmailAddress.error('[email protected]')
    => "This domain is not configured to accept email"
    
  5. Start a new IRB session:

    irb(main):001:0> require 'email_address'
    => true
    irb(main):002:0> EmailAddress::Config.configure(host_validation: :mx)
    => {:dns_lookup=>:mx, :sha1_secret=>"", :munge_string=>"*****", :local_downcase=>true, :local_fix=>false, :local_encoding=>:ascii, :local_parse=>nil, :local_format=>:conventional, :local_size=>1..64, :tag_separator=>"+", :mailbox_size=>1..64, :mailbox_canonical=>nil, :mailbox_validator=>nil, :host_encoding=>:punycode, :host_validation=>:mx, :host_size=>1..253, :host_allow_ip=>false, :host_remove_spaces=>false, :host_local=>false, :address_validation=>:parts, :address_size=>3..254, :address_fqdn_domain=>nil}
    irb(main):003:0> EmailAddress.error('[email protected]')
    => nil
    

Expected Behavior: Seems like if there's no network connection, it should raise a warning about MX not being able to validate, not report that validation has failed. Also, it definitely shouldn't report "This domain is not configured to accept email" about gmail.com at any point. Whatever is giving that report on that domain is pretty much by definition incorrect.

@afair
Copy link
Owner

afair commented Nov 21, 2019

It seems the gem cached the result of the offline response. Not found requests are the slowest and need to be cached. We should see if the result is offline vs not found.

We can't tell (in Ruby?) that the network is down, so if a dns lookup
returned a SocketError, it can mean either not found or network
unavailable. Until I find a better way, I test the network on that
exception by looking up "example.com". If it works, then assume it was a
not-found condition. For unavailable, a dummy record is returned.

Also, moved the a-record lookup into the same exchanger object, with the
same network test.

Exchanger objects are cached. When I pull it out of the cache, I check
to see if the network-down occurred, and if so, throw it away and create
a new one so it can work properly when the network becomes available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant