Skip to content
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

Ip validator and Ip tests renovation #32

Merged
merged 6 commits into from Nov 13, 2019
Merged

Conversation

@kamarton
Copy link
Contributor

kamarton commented Nov 1, 2019

Q A
Is bugfix? ✔️
New feature? ✔️
Breaks BC? ✔️
Tests pass? ✔️
Fixed issues -
Alternative PR #21 (abandoned)
@kamarton kamarton changed the title Ip validator and Ip tests renovation [WIP] Ip validator and Ip tests renovation Nov 1, 2019
@kamarton

This comment has been minimized.

Copy link
Contributor Author

kamarton commented Nov 1, 2019

@samdark questions

  • Does it make sense to allow leading zeros for IPv4? (10.001.000002.1) https://superuser.com/a/929180/1082613
    In my opinion, it makes no sense and only raises additional problems, eg. if allowed, then abnormal IP addresses will also pass through. 01.01.01.01, 001,001,001,001, 0000000000001.0000000000001.000000000001.00000000001.
    UPD:
$ php -r 'var_dump(inet_pton("01.01.01.01"));'
PHP Warning:  inet_pton(): Unrecognized address 01.01.01.01 in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. inet_pton() Command line code:1
Command line code:1:
bool(false)

$this->assertTrue($validator->validate('192.168.005.001'));

  • In the original code, the subnet had three states: optional, require, not allow. Since cannot modify the input value, required state does not make sense. 127.0.0.1 === 127.0.0.1 / 32.
    For example firewall in GCP:
    firewall example
Somogyi Márton
@kamarton

This comment has been minimized.

Copy link
Contributor Author

kamarton commented Nov 1, 2019

Tests with FakedValidationModel style is relevant?

@samdark

This comment has been minimized.

Copy link
Member

samdark commented Nov 2, 2019

Does it make sense to allow leading zeros for IPv4?

No.

In the original code, the subnet had three states: optional, require, not allow. Since cannot modify the input value, required state does not make sense. 127.0.0.1 === 127.0.0.1 / 32.

OK.

Tests with FakedValidationModel style is relevant?

No.

Somogyi Márton added 2 commits Nov 6, 2019
Somogyi Márton
Somogyi Márton
@kamarton kamarton changed the title [WIP] Ip validator and Ip tests renovation Ip validator and Ip tests renovation Nov 6, 2019
@kamarton

This comment has been minimized.

Copy link
Contributor Author

kamarton commented Nov 6, 2019

Finally, I left all the subnet options (not allow, reuqired, optional). Reviewable.

Desktop screenshot

@kamarton

This comment has been minimized.

Copy link
Contributor Author

kamarton commented Nov 6, 2019

The Ip::getRanges() function may not be required. It is currently used only for tests, but important for them.

@samdark

This comment has been minimized.

Copy link
Member

samdark commented Nov 12, 2019

Any idea why travis builds fail?

"ext-intl": "*"
},
"suggest": {

This comment has been minimized.

Copy link
@samdark

samdark Nov 12, 2019

Member

If the package is required, there's no sense in suggesting it.

This comment has been minimized.

Copy link
@kamarton

kamarton Nov 13, 2019

Author Contributor

removed

*/
public function setRanges($ranges)
public function ranges(array $ranges)

This comment has been minimized.

Copy link
@samdark

samdark Nov 12, 2019

Member
Suggested change
public function ranges(array $ranges)
public function ranges(array $ranges): self

This comment has been minimized.

Copy link
@kamarton

kamarton Nov 13, 2019

Author Contributor

Phpdoc @return static is a better solution because self must be compliance with the parent class name after inheritance.

example

MyExtendendIp extends Ip {         ˇˇ----- the PHP processor throws an error if I do not use the parent class.
  public function ranges($ranges): Ip {
     // overerride
  }
}

Of course, this is not a problem if we set the Ip class to final.

/**
* @return static
*/
public function allowIpv4(bool $value = true)

This comment has been minimized.

Copy link
@samdark

samdark Nov 12, 2019

Member
Suggested change
public function allowIpv4(bool $value = true)
public function allowIpv4(bool $value = true): self
/**
* @return static
*/
public function allowIpv6(bool $value = true)

This comment has been minimized.

Copy link
@samdark

samdark Nov 12, 2019

Member
Suggested change
public function allowIpv6(bool $value = true)
public function allowIpv6(bool $value = true): self
/**
* @return static
*/
public function allowNegation(bool $value = true)

This comment has been minimized.

Copy link
@samdark

samdark Nov 12, 2019

Member
Suggested change
public function allowNegation(bool $value = true)
public function allowNegation(bool $value = true): self

This comment has been minimized.

Copy link
@samdark

samdark Nov 12, 2019

Member

How about allowNegation and disallowNegation?

This comment has been minimized.

Copy link
@samdark

samdark Nov 12, 2019

Member

Same w/ other allow* methods.

This comment has been minimized.

Copy link
@kamarton

kamarton Nov 13, 2019

Author Contributor

How about allowNegation and disallowNegation?

like it.

This comment has been minimized.

Copy link
@kamarton

kamarton Nov 13, 2019

Author Contributor

added

*/
private function validateSubnet(string $ip)
public function allowSubnet(bool $allow = true, bool $required = false)

This comment has been minimized.

Copy link
@samdark

samdark Nov 12, 2019

Member
Suggested change
public function allowSubnet(bool $allow = true, bool $required = false)
public function allowSubnet(bool $allow = true, bool $required = false): self

This comment has been minimized.

Copy link
@samdark

samdark Nov 12, 2019

Member

Also it seems to try setting two separate things at the same time. How about allowSubnet(), requireSubnet(), disallowSubnet()?

This comment has been minimized.

Copy link
@kamarton

kamarton Nov 13, 2019

Author Contributor

How about allowSubnet(), requireSubnet(), disallowSubnet()?

Like it. It is much clearer to use.

This comment has been minimized.

Copy link
@kamarton

kamarton Nov 13, 2019

Author Contributor

added

@kamarton

This comment has been minimized.

Copy link
Contributor Author

kamarton commented Nov 13, 2019

Any idea why travis builds fail?

The other classes in the package are not ready yet, so the tests will fail.

Somogyi Márton added 2 commits Nov 13, 2019
@kamarton

This comment has been minimized.

Copy link
Contributor Author

kamarton commented Nov 13, 2019

@samdark samdark merged commit 3e67611 into yiisoft:master Nov 13, 2019
0 of 3 checks passed
0 of 3 checks passed
Travis CI - Pull Request Build Failed
Details
continuous-integration/styleci/pr Issues have been identified with 1 file
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
@samdark

This comment has been minimized.

Copy link
Member

samdark commented Nov 13, 2019

Merged. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.