Projet

Général

Profil

0005-emails-validators-add-option-to-bypass-smtp-validati.patch

Christophe Siraut, 18 avril 2019 12:41

Télécharger (1,79 ko)

Voir les différences:

Subject: [PATCH 5/6] emails/validators: add option to bypass smtp validation
 (#32435)

 hobo/emails/validators.py | 2 ++
 hobo/settings.py          | 1 +
 tests/test_emails.py      | 5 +++++
 3 files changed, 8 insertions(+)
hobo/emails/validators.py
23 23

  
24 24

  
25 25
def validate_email_address(value):
26
    if not settings.HOBO_VALIDATE_EMAIL_WITH_SMTP:
27
        return
26 28
    email_domain = value.split('@')[-1]
27 29
    try:
28 30
        mx_server = sorted(dns.resolver.query(email_domain, 'MX'), key=lambda rdata: rdata.preference)[0].exchange.to_text()
hobo/settings.py
26 26

  
27 27
ALLOWED_HOSTS = []
28 28

  
29
HOBO_VALIDATE_EMAIL_WITH_SMTP = True
29 30
ALLOWED_SPF_RECORDS = []
30 31

  
31 32
# Application definition
tests/test_emails.py
89 89
    assert 'Error while connecting' in str(e.value)
90 90

  
91 91

  
92
def test_validate_email_address_bypass(settings):
93
    settings.HOBO_VALIDATE_EMAIL_WITH_SMTP = False
94
    assert validate_email_address('foo') == None
95

  
96

  
92 97
def test_invalid_address(client, admin_user):
93 98
    client.post('/login/', {'username': 'admin', 'password': 'password'})
94 99
    response = client.post('/emails/', {'default_from_email': 'foobar'})
95
-