Resolve the log in issue for a user having a non-existing email id

1) Added CHECK_EMAIL_DELIVERABILITY & SECURITY_EMAIL_VALIDATOR_ARGS.
  2) Added test cases for deliverability check.

Fixes #6550
This commit is contained in:
Rahul Shirsat
2021-07-05 12:55:40 +05:30
committed by Akshay Joshi
parent ef67409d61
commit 9fdda038a9
10 changed files with 266 additions and 19 deletions

View File

@@ -98,3 +98,5 @@ BINARY_PATHS = {
}
UTILITIES_ARRAY = ['pg_dump', 'pg_dumpall', 'pg_restore', 'psql']
ENTER_EMAIL_ADDRESS = "Email address: "

View File

@@ -0,0 +1,82 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2021, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
from pgadmin.utils.route import BaseTestGenerator
from pgadmin.utils.validation_utils import validate_email
from unittest.mock import patch
import config
class TestEmailValidate(BaseTestGenerator):
""" This class will test the email validation utility with or without email
deliverability. """
scenarios = [
('Email validation (no deliverability)',
dict(
data=dict(
email_list=['postgres@local.dev', 'pg@pgadminrocks.com',
'me.pg@demo.dev', 'pg@123.pgcom',
'pg@postgres.local', 'postgres@pg.blah',
'john@doe.com', 'punster@tr.co',
'admin@example.com'],
check_deliverability=False,
expected_data=dict(
test_result=True
)
)
)),
('Email validation (with deliverability)',
dict(
data=dict(
email_list=['postgres@local.dev', 'pg@pgadminrocks.com',
'pg@postgres.local'],
check_deliverability=True,
expected_data=dict(
test_result=False
)
)
)),
('Empty email validation (no deliverability)',
dict(
data=dict(
email_list=[''],
check_deliverability=False,
expected_data=dict(
test_result=False
)
)
)),
('Empty email validation (with deliverability)',
dict(
data=dict(
email_list=[''],
check_deliverability=True,
expected_data=dict(
test_result=False
)
)
))
]
def runTest(self):
if config.SERVER_MODE is False:
self.skipTest(
"Can not run email validation test cases in the DESKTOP mode."
)
config.CHECK_EMAIL_DELIVERABILITY = self.data['check_deliverability']
for e in self.data['email_list']:
result = validate_email(e)
# validate_email returns True if email is valid,
# even if non-deliverable. False if email is not valid or
# deliverability is turned ON.
self.assertEqual(result,
self.data['expected_data']['test_result'])

View File

@@ -7,20 +7,21 @@
#
##########################################################################
import re
from email_validator import validate_email as email_validate, \
EmailNotValidError
import config
def validate_email(email):
if email == '' or email is None:
try:
# Validate.
valid = email_validate(
email, check_deliverability=config.CHECK_EMAIL_DELIVERABILITY)
# Update with the normalized form.
email = valid.email
return True
except EmailNotValidError as e:
# email is not valid, exception message is human-readable
print(str(e))
return False
email_filter = re.compile(
"^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9]"
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9]"
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
)
if not email_filter.match(email):
return False
return True