Skip to content

Commit 67055d4

Browse files
author
Steve Ayers
committed
Final
1 parent 9429db7 commit 67055d4

3 files changed

Lines changed: 12 additions & 113 deletions

File tree

protovalidate/internal/extra_func.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ def _is_hostname(val: str) -> bool:
193193
if len(val) > 253:
194194
return False
195195

196-
if val.endswith(val.lower()):
197-
string = val[0 : len(val) - 1]
196+
if val.endswith("."):
197+
string = val[0 : len(val) - 1].lower()
198198
else:
199-
string = val
199+
string = val.lower()
200200

201201
all_digits = False
202202
parts = string.lower().split(sep=".")
@@ -265,6 +265,7 @@ def _is_host_and_port(val: str, *, port_required=False) -> bool:
265265
return False
266266

267267
split_idx = val.rfind(":")
268+
268269
if val[0] == "[":
269270
end = val.rfind("]")
270271
end_plus = end + 1
@@ -646,7 +647,7 @@ def __address_part(self) -> bool:
646647
break
647648

648649
# dotted notation for right-most 32 bits, e.g. 0:0:0:0:0:ffff:192.1.56.10
649-
if self._double_colon_seen or (len(self._pieces) == 6 and self.__dotted()):
650+
if (self._double_colon_seen or len(self._pieces) == 6) and self.__dotted():
650651
dotted = Ipv4(self._dotted_raw)
651652

652653
if dotted.address():

tests/conformance/nonconforming.yaml

Lines changed: 7 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,87 +8,13 @@ standard_constraints/well_known_types/timestamp:
88
- gte_lte/invalid/above
99
- lte/invalid
1010

11-
library/is_host_and_port:
12-
- port_required/false/invalid/port_number_sign
13-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsHostAndPort]:{val:"example.com:+0"}
14-
# want: validation error (1 violation)
15-
# 1. constraint_id: "library.is_host_and_port"
16-
# got: valid
17-
- port_required/false/valid/ipv6_zone-id_any_non_null_character
18-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsHostAndPort]:{val:"[::1%% :x\x1f]"}
19-
# want: valid
20-
# got: validation error (1 violation)
21-
# 1. constraint_id: "library.is_host_and_port"
22-
# message: ""
23-
# for_key: false
24-
- port_required/true/invalid/port_number_sign
25-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsHostAndPort]:{val:"example.com:+0" port_required:true}
26-
# want: validation error (1 violation)
27-
# 1. constraint_id: "library.is_host_and_port"
28-
# got: valid
29-
- version/1/invalid/empty_string
30-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIp]:{version:1}
31-
# want: validation error (1 violation)
32-
# 1. constraint_id: "library.is_ip"
33-
# got: runtime error: invalid argument, expected 4 or 6
34-
- version/omitted/valid/ipv6_zone-id_any_non_null_character
35-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIp]:{val:"::1%% :x\x1f"}
36-
# want: valid
37-
# got: validation error (1 violation)
38-
# 1. constraint_id: "library.is_ip"
39-
# message: ""
40-
# for_key: false
41-
library/is_ip_prefix:
42-
- version/0/strict/omitted/valid/ipv4_prefix
43-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"127.0.0.1/16" version:0}
44-
# want: valid
45-
# got: runtime error: invalid argument, expected 4 or 6
46-
- version/0/strict/omitted/valid/ipv6_prefix
47-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"::1/64" version:0}
48-
# want: valid
49-
# got: runtime error: invalid argument, expected 4 or 6
50-
- version/1/strict/omitted/invalid/empty_string
51-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{version:1}
52-
# want: validation error (1 violation)
53-
# 1. constraint_id: "library.is_ip_prefix"
54-
# got: runtime error: invalid argument, expected 4 or 6
55-
- version/5/strict/omitted/invalid/ipv6_prefix
56-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"::1/64" version:5}
57-
# want: validation error (1 violation)
58-
# 1. constraint_id: "library.is_ip_prefix"
59-
# got: runtime error: invalid argument, expected 4 or 6
60-
- version/7/strict/omitted/invalid/ipv6_prefix
61-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"::1/64" version:7}
62-
# want: validation error (1 violation)
63-
# 1. constraint_id: "library.is_ip_prefix"
64-
# got: runtime error: invalid argument, expected 4 or 6
65-
- version/omitted/strict/omitted/invalid/ipv4_bad_leading_zero_in_prefix-length
66-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"192.168.1.0/024"}
67-
# want: validation error (1 violation)
68-
# 1. constraint_id: "library.is_ip_prefix"
69-
# got: valid
70-
- version/omitted/strict/omitted/invalid/ipv6_bad_leading_zero_in_prefix-length
71-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"2001:0DB8:ABCD:0012:FFFF:FFFF:FFFF:FFFF/024"}
72-
# want: validation error (1 violation)
73-
# 1. constraint_id: "library.is_ip_prefix"
74-
# got: valid
75-
- version/omitted/strict/omitted/invalid/ipv6_zone-id/a
76-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"::1%en1/64"}
77-
# want: validation error (1 violation)
78-
# 1. constraint_id: "library.is_ip_prefix"
79-
# got: valid
8011
standard_constraints/required:
12+
# The below tests are failing due to a bug in the conformance runner. These
13+
# proto messages are marked as IGNORE_ALWAYS which means they should always
14+
# pass, which this implementation does correctly. However, the runner is
15+
# expecting them to fail.
16+
# See:
17+
# https://github.com/bufbuild/protovalidate/blob/main/proto/protovalidate-testing/buf/validate/conformance/cases/required_field_proto2.proto#L24
18+
# https://github.com/bufbuild/protovalidate/blob/main/proto/protovalidate-testing/buf/validate/conformance/cases/required_field_proto2.proto#L31
8119
- proto2/scalar/optional/unset
82-
# input: [type.googleapis.com/buf.validate.conformance.cases.RequiredProto2ScalarOptional]:{}
83-
# want: validation error (1 violation)
84-
# 1. constraint_id: "required"
85-
# field: "val" elements:{field_number:1 field_name:"val" field_type:TYPE_STRING}
86-
# rule: "required" elements:{field_number:25 field_name:"required" field_type:TYPE_BOOL}
87-
# got: valid
8820
- proto2/scalar/optional_with_default/unset
89-
# input: [type.googleapis.com/buf.validate.conformance.cases.RequiredProto2ScalarOptionalDefault]:{}
90-
# want: validation error (1 violation)
91-
# 1. constraint_id: "required"
92-
# field: "val" elements:{field_number:1 field_name:"val" field_type:TYPE_STRING}
93-
# rule: "required" elements:{field_number:25 field_name:"required" field_type:TYPE_BOOL}
94-
# got: valid

tests/extra_func_test.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)