fix issue where whitelist always passes for email validation#46
fix issue where whitelist always passes for email validation#46johannestaas wants to merge 3 commits intopython-validators:masterfrom
Conversation
|
Oh... I see what you were doing... I misunderstood what "whitelist" was supposed to be. It's a whitelist so domains can pass that don't match the regex like "localhost". In that case, it might be nice to have another keyword argument that fails it if the email doesn't have a certain domain, like I could edit this to match that logic if that's alright. My use case might be for passivetotal.org, where if someone wants to join the organization "passivetotal", it can check their email against their domain to validate they belong there. Org admins could automatically whitelist emails with domains from their org. |
|
Alright, I implemented |
|
ref #241 | Whitelisting will be considered later, the test cases (hopefully all) in this PR passed. |
So, it looks like the logic was off for the email validation and whitelist keyword. It'd always pass the whitelist if the domain was fine. check the top level if condition in the original code and you see that if it's not in whitelist and the domain_regex passes, it just skips over to return True.
if domain_part not in whitelist and not domain_regex.match(domain_part):
Testing patch:
In [2]: email('test@riskiq.net')
Out[2]: True
In [3]: email('test@riskiq.net', whitelist=['riskiq.net'])
Out[3]: True
In [4]: email('test@riskiq.net', whitelist=['riskiq.com'])
Out[4]: ValidationFailure(func=email, args={'value': 'test@riskiq.net', 'whitelist': ['riskiq.com']})