0001-validators-close-smtp-socket-after-email-rcpt-check-.patch
src/authentic2/validators.py | ||
---|---|---|
63 | 63 |
def check_rcpt(self, value, mxs): |
64 | 64 |
for server in mxs: |
65 | 65 |
try: |
66 |
smtp = smtplib.SMTP()
|
|
67 |
smtp.connect(server) |
|
68 |
status = smtp.helo() |
|
69 |
if status[0] != 250: |
|
70 |
continue |
|
71 |
smtp.mail('') |
|
72 |
status = smtp.rcpt(value) |
|
66 |
with smtplib.SMTP() as smtp:
|
|
67 |
smtp.connect(server)
|
|
68 |
status = smtp.helo()
|
|
69 |
if status[0] != 250:
|
|
70 |
continue
|
|
71 |
smtp.mail('')
|
|
72 |
status = smtp.rcpt(value)
|
|
73 | 73 |
if status[0] // 100 == 5: |
74 | 74 |
raise ValidationError(_('Invalid email address.'), code='rcpt-check-failed') |
75 | 75 |
break |
tests/test_validators.py | ||
---|---|---|
71 | 71 | |
72 | 72 |
@pytest.fixture |
73 | 73 |
def smtp(): |
74 |
def __enter__(self): |
|
75 |
return self |
|
76 | ||
77 |
def __exit__(self, *args): |
|
78 |
return None |
|
79 | ||
74 | 80 |
smtp = mock.Mock() |
75 | 81 |
smtp.helo.return_value = 250, None |
82 |
smtp.__enter__ = __enter__ |
|
83 |
smtp.__exit__ = __exit__ |
|
76 | 84 |
with mock.patch('smtplib.SMTP', return_value=smtp): |
77 | 85 |
yield smtp |
78 | 86 | |
79 |
- |