-
Notifications
You must be signed in to change notification settings - Fork 9
Enhance IP validation #274
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
Conversation
| return celtypes.BoolType(_is_ip_prefix(val, version, strict=strict)) | ||
|
|
||
|
|
||
| def _is_ip_prefix(string: str, version: int, *, strict=False) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure of the best way to handle this. Other validation methods call this internally and if we stick with just is_ip_prefix then they have to pass cel values and handle cel types.
We have a similar scenario with Java (and C++). We could go back to the is_email and validate_email pattern that was in use before. FWIW, Java has that pattern now also. 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks like a good reason for a separate function to me.
is_ vs. validate_ is not self-explanatory. What if we prefix the type converting function with cel_?
def cel_is_ip(val: celtypes.Value, ver: typing.Optional[celtypes.Value] = None) -> celpy.Result:
...
return celtypes.BoolType(is_ip(...))
def is_ip(val: str, ver: int) -> bool:
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. I also updated the other functions that don't require an internal implementation just to keep things consistent.
| # The below tests are failing due to a bug in the conformance runner. These | ||
| # proto messages are marked as IGNORE_ALWAYS which means they should always | ||
| # pass, which this implementation does correctly. However, the runner is | ||
| # expecting them to fail. | ||
| # See: | ||
| # https://github.com/bufbuild/protovalidate/blob/main/proto/protovalidate-testing/buf/validate/conformance/cases/required_field_proto2.proto#L24 | ||
| # https://github.com/bufbuild/protovalidate/blob/main/proto/protovalidate-testing/buf/validate/conformance/cases/required_field_proto2.proto#L31 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing this in bufbuild/protovalidate#340.
This beefs up the validation for the following:
IP address (v4 and v6)
IP prefix (v4 and v6)
Hostname / Port
The validation here adheres to the defined RFC standards for each entity and passes conformance for all new conformance tests defined in bufbuild/protovalidate#320.