Skip to content

Commit 40a0637

Browse files
Implement unified IPv4 and IPv6 parsers (#79)
This PR implements the formalized IPv4 and IPv6 grammars that we have selected for unifying the CEL library functions across implementations. In doing so, we can remove the split `expected_failures.yaml` file, as well as the need to link to Winsock32 on Windows.
1 parent 2d7d546 commit 40a0637

16 files changed

+858
-1666
lines changed

CMakeLists.txt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,19 @@ set(PROTOVALIDATE_LIBS
4848
cel_cpp::cel_cpp
4949
protovalidate::proto
5050
)
51-
if(WIN32)
52-
# For htonl/inet_pton
53-
list(APPEND PROTOVALIDATE_LIBS Ws2_32)
54-
endif()
5551
set(PROTOVALIDATE_TESTING_LIBS
5652
GTest::gmock_main
5753
protovalidate::testing_proto
5854
)
5955
file(GLOB PROTOVALIDATE_CC_CORE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
6056
buf/validate/*.h
6157
buf/validate/internal/*.h
58+
buf/validate/internal/lib/*.h
6259
)
6360
file(GLOB PROTOVALIDATE_CC_CORE_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
6461
buf/validate/*.cc
6562
buf/validate/internal/*.cc
63+
buf/validate/internal/lib/*.cc
6664
)
6765
set(PROTOVALIDATE_CC_TEST_SOURCES
6866
${PROTOVALIDATE_CC_CORE_SOURCES}
@@ -113,21 +111,14 @@ if(PROTOVALIDATE_CC_ENABLE_TESTS)
113111
unset(target_name)
114112
endforeach()
115113

116-
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
117-
set(EXPECTED_FAILURES_FILE "expected_failures_mac.yaml")
118-
else()
119-
# Default to Linux for now
120-
set(EXPECTED_FAILURES_FILE "expected_failures_linux.yaml")
121-
endif()
122-
123114
# TODO(jchadwick-buf): The conformance test runner does not work on Windows
124115
# yet, due to an issue with linking the protobuf descriptors.
125116
if(PROTOVALIDATE_CC_ENABLE_CONFORMANCE AND NOT WIN32)
126117
add_test(
127118
NAME protovalidate_cc_conformance
128119
COMMAND go run github.com/bufbuild/protovalidate/tools/protovalidate-conformance@v${PROTOVALIDATE_CC_PROTOVALIDATE_VERSION}
129120
--strict_message
130-
--expected_failures=${CMAKE_CURRENT_SOURCE_DIR}/buf/validate/conformance/${EXPECTED_FAILURES_FILE}
121+
--expected_failures=${CMAKE_CURRENT_SOURCE_DIR}/buf/validate/conformance/expected_failures.yaml
131122
$<TARGET_FILE:protovalidate_cc::conformance_runner_main>
132123
)
133124
endif()

Makefile

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ PROTOVALIDATE_VERSION ?= v$(shell <./deps/shared_deps.json jq -j .protovalidate.
1515
# Set to use a different compiler. For example, `GO=go1.18rc1 make test`.
1616
GO ?= go
1717

18-
UNAME_OS := $(shell uname -s)
19-
ifeq ($(UNAME_OS),Darwin)
20-
EXPECTED_FAILURES_FILE := expected_failures_mac.yaml
21-
else
22-
# Default to Linux for now
23-
EXPECTED_FAILURES_FILE := expected_failures_linux.yaml
24-
endif
25-
26-
ARGS ?= --strict_message --expected_failures=buf/validate/conformance/$(EXPECTED_FAILURES_FILE)
18+
ARGS ?= --strict_message --expected_failures=buf/validate/conformance/expected_failures.yaml
2719

2820
BAZEL ?= bazel
2921

buf/validate/conformance/expected_failures_mac.yaml renamed to buf/validate/conformance/expected_failures.yaml

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,83 +28,23 @@ library/is_email:
2828
# message: ""
2929
# for_key: false
3030
library/is_host_and_port:
31-
# FIXME - The following tests are inconsistent between Mac/Darwin and Linux
32-
# - port_required/false/valid/ipv6_with_zone-id
33-
- port_required/false/invalid/ipv6_zone-id_too_short
34-
# --------------------------------------------------------------------------
3531
- port_required/false/invalid/port_number_sign
3632
# input: [type.googleapis.com/buf.validate.conformance.cases.IsHostAndPort]:{val:"example.com:+0"}
3733
# want: validation error (1 violation)
3834
# 1. constraint_id: "library.is_host_and_port"
3935
# got: valid
40-
- port_required/false/valid/ipv6_zone-id_any_non_null_character
41-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsHostAndPort]:{val:"[::1%% :x\x1f]"}
42-
# want: valid
43-
# got: validation error (1 violation)
44-
# 1. constraint_id: "library.is_host_and_port"
45-
# message: ""
46-
# for_key: false
4736
- port_required/true/invalid/port_number_sign
4837
# input: [type.googleapis.com/buf.validate.conformance.cases.IsHostAndPort]:{val:"example.com:+0" port_required:true}
4938
# want: validation error (1 violation)
5039
# 1. constraint_id: "library.is_host_and_port"
5140
# got: valid
52-
library/is_ip:
53-
# FIXME - The following tests are inconsistent between Mac/Darwin and Linux
54-
- version/omitted/invalid/ipv6_zone-id
55-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIp]:{val:"::1%"}
56-
# want: validation error (1 violation)
57-
# 1. constraint_id: "library.is_ip"
58-
# got: valid
59-
# - version/omitted/valid/ipv6_zone-id
60-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIp]:{val:"::1%foo"}
61-
# want: valid
62-
# got: validation error (1 violation)
63-
# 1. constraint_id: "library.is_ip"
64-
# message: ""
65-
# --------------------------------------------------------------------------
66-
- version/omitted/valid/ipv6_zone-id_any_non_null_character
67-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIp]:{val:"::1%% :x\x1f"}
68-
# want: valid
69-
# got: validation error (1 violation)
70-
# 1. constraint_id: "library.is_ip"
71-
# message: ""
72-
# for_key: false
7341
library/is_hostname:
7442
- valid/label_interior_hyphen
7543
# input: [type.googleapis.com/buf.validate.conformance.cases.IsHostname]:{val:"a-b.a--b"}
7644
# want: valid
7745
# got: validation error (1 violation)
7846
# 1. constraint_id: "library.is_hostname"
7947
# message: ""
80-
library/is_ip_prefix:
81-
# FIXME - The following test is inconsistent between Mac/Darwin and Linux
82-
- version/omitted/strict/omitted/invalid/ipv6_zone-id/a
83-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"::1%en1/64"}
84-
# want: validation error (1 violation)
85-
# 1. constraint_id: "library.is_ip_prefix"
86-
# got: valid
87-
# --------------------------------------------------------------------------
88-
- version/omitted/strict/omitted/invalid/ipv4_prefix_trailing_space
89-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"127.0.0.1/16 "}
90-
# want: validation error (1 violation)
91-
# 1. constraint_id: "library.is_ip_prefix"
92-
# got: valid
93-
- version/omitted/strict/omitted/invalid/ipv6_prefix_trailing_space
94-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"::1/64 "}
95-
# want: validation error (1 violation)
96-
# 1. constraint_id: "library.is_ip_prefix"
97-
# got: valid
98-
- version/omitted/strict/omitted/invalid/ipv4_bad_leading_zero_in_prefix-length
99-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"192.168.1.0/024"}
100-
# want: validation error (1 violation)
101-
# 1. constraint_id: "library.is_ip_prefix"
102-
# got: valid
103-
- version/omitted/strict/omitted/invalid/ipv6_bad_leading_zero_in_prefix-length
104-
# input: [type.googleapis.com/buf.validate.conformance.cases.IsIpPrefix]:{val:"2001:0DB8:ABCD:0012:FFFF:FFFF:FFFF:FFFF/024"}
105-
# want: validation error (1 violation)
106-
# 1. constraint_id: "library.is_ip_prefix"
107-
# got: valid
10848
library/is_uri:
10949
- invalid/query_bad_pct-encoded
11050
# input: [type.googleapis.com/buf.validate.conformance.cases.IsUri]:{val:"https://example.com?%2x"}

0 commit comments

Comments
 (0)