Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator, FrameworkBundle] Add prevent DNS lookup option to EmailValidator #18142

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

Closed

Conversation

patrick-mcdougle
Copy link
Contributor

Q A
Branch master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16819
License MIT
Doc PR symfony/symfony-docs#6359

@a-ast
Copy link
Contributor

a-ast commented Mar 12, 2016

Hi, @patrick-mcdougle.
It looks nice, but I think it would make sense to extend EmailValidatorTest to check that checkdnsrr is never called if $preventDNSLookups = = true. What do you think?

@patrick-mcdougle
Copy link
Contributor Author

@AAstakhov I wanted to add some tests, but it looks like none of the check methods are currently tested. I would imagine this is because symfony doesn't want to have a dependency on the network/DNS when it's running automated tests. I'm willing to write a few tests but I don't want to put in the effort if they're going to be flaky/unpredictable tests.

@a-ast
Copy link
Contributor

a-ast commented Mar 12, 2016

Status: Reviewed

Code is nice, tests pass. I tested it with different scenarios.

@patrick-mcdougle, you are right, if checkMX and checkHost options are not tested than it does not make any sense in additional tests.

@patrick-mcdougle
Copy link
Contributor Author

Appveyor test failure likely unrelated. @symfony/deciders

@@ -81,7 +87,7 @@ public function validate($value, Constraint $constraint)
$host = substr($value, strpos($value, '@') + 1);

// Check for host DNS resource records
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a little more DRY if there were just a single if (!$this->preventDNSLookups) conditional wrapping both the MX section and the hostname section. It would also keep the original if statements uncluttered by this new logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion! I'll make this change when I get back to my computer.

@javiereguiluz
Copy link
Member

@patrick-mcdougle thanks for this contribution!

My only concern is that variables with a "negation name" usually reduce code readability (especially when you negate them in a condition):

if (!$this->preventDNSLookups && $constraint->checkMX) {
    // ...
}

Maybe we could use the same name used by PHP and rename this variable to $checkDnsRecord:

if ($this->checkDnsRecord && $constraint->checkMX) {
    // ...
}

@inso
Copy link

inso commented Mar 13, 2016

👎 Why not just mock checkdnsrr during tests?

@patrick-mcdougle
Copy link
Contributor Author

@inso I'm pretty new at this and I'm just implementing this feature because there was an open issue about it. Can you further elaborate on your suggestion to mock in #16819? Perhaps this doesn't need to be a feature at all. I don't personally know how to do what you're proposing, but if you provided more insight on how that would work It'd be appreciated (perhaps open a PR testing checkdnsrr(), because this aspect isn't currently tested).

In the meantime, I'm going to address Javier and Nate's comments.

@patrick-mcdougle
Copy link
Contributor Author

Alternatively, we could demote the checkHost() and checkMX() to protected methods so they could be overridden using inheritance.

@patrick-mcdougle
Copy link
Contributor Author

PR updated. I'd suggest viewing with ?w=1 because the diff is misleading.

@@ -49,6 +49,7 @@

<service id="validator.email" class="Symfony\Component\Validator\Constraints\EmailValidator">
<argument></argument>
<argument></argument>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good IMO to add comment that those two options are passed in extension.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way we do this elsewhere is like this: <argument /> <!-- XXX -->

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will do later tonight.

@inso
Copy link

inso commented Mar 14, 2016

@patrick-mcdougle here you can review how time related functions are mocked

@patrick-mcdougle
Copy link
Contributor Author

@inso interesting. That probably is the right way to do this. I'll try that out later tonight.

@nicolas-grekas
Copy link
Member

checkdnsrr mocking implemented in #18181
thank you @patrick-mcdougle for the heads up on the topic!

@patrick-mcdougle patrick-mcdougle deleted the pmcd-issue_16819 branch March 15, 2016 21:29
@patrick-mcdougle
Copy link
Contributor Author

@nicolas-grekas do you think you could briefly explain how to use this in #16819? Once explained there, that issue can also be closed. Thanks. Also, nice palindromic PR number 😺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants