this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

pkg/net: add regression tests for IP validators with unexpected types

Add test cases for net.IPCIDR, net.IP, net.IPv4, and net.IPv6
with integer values. This shows the existing behavior where
net.IPCIDR incorrectly succeeds on non-string types like integers.

The other validators (IP, IPv4, IPv6) happen to return false for
unexpected types, which works but gives less informative errors.

Also drop the out/net golden section and the diff between the old
and new evaluators, as the difference no longer matters.

For #3979.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I9a73d8dce473487aa4e7896e4986e099cfb90ca3
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1233775
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+61 -47
+61 -47
pkg/net/testdata/gen.txtar
··· 23 23 t18: net.IPCIDR("192.168.1.0/24") 24 24 t19: net.IPCIDR("2001:db8:a0b:12f0::1/32") 25 25 t20: net.IPCIDR("172.16.12.3") 26 + t20b: 123 & net.IPCIDR 27 + t20c: 123 & net.IP 28 + t20d: 123 & net.IPv4 29 + t20e: 123 & net.IPv6 26 30 t21: net.PathEscape("foo/bar") 27 31 t22: net.PathUnescape("foo%2Fbar") 28 32 t23: net.QueryEscape("f%o") ··· 50 54 t45: net.AddIPCIDR("192.168.0.0", 1) 51 55 t46: net.AddIPCIDR("10.0.0.0/8", -11) 52 56 t47: net.AddIPCIDR("255.0.0.0/8", 1) 53 - -- out/net -- 57 + -- out/net-v3 -- 54 58 Errors: 59 + t20c: invalid value 123 (does not satisfy net.IP): 60 + ./in.cue:24:7 61 + t20d: invalid value 123 (does not satisfy net.IPv4): 62 + ./in.cue:25:7 63 + t20e: invalid value 123 (does not satisfy net.IPv6): 64 + ./in.cue:26:7 55 65 t25: invalid value "2001:db8::1234567" (does not satisfy net.IPv6): 56 - ./in.cue:27:6 57 - ./in.cue:27:17 66 + ./in.cue:31:6 67 + ./in.cue:31:17 58 68 t30: invalid value "%" (does not satisfy net.URL): error in call to net.URL: parse "%": invalid URL escape "%": 59 - ./in.cue:32:6 60 - ./in.cue:32:16 69 + ./in.cue:36:6 70 + ./in.cue:36:16 61 71 t32: invalid value "/foo/bar" (does not satisfy net.AbsURL): error in call to net.AbsURL: URL is not absolute: 62 - ./in.cue:34:6 63 - ./in.cue:34:19 72 + ./in.cue:38:6 73 + ./in.cue:38:19 64 74 t34: invalid value "%" (does not satisfy net.AbsURL): error in call to net.AbsURL: parse "%": invalid URL escape "%": 65 - ./in.cue:36:6 66 - ./in.cue:36:19 75 + ./in.cue:40:6 76 + ./in.cue:40:19 67 77 t9: invalid value "23.23.23.2333" (does not satisfy net.IPv4): 68 78 ./in.cue:11:6 69 79 ./in.cue:11:17 ··· 75 85 t20: error in call to net.IPCIDR: netip.ParsePrefix("172.16.12.3"): no '/': 76 86 ./in.cue:22:6 77 87 t27: invalid value "23.23.23.23" (does not satisfy net.IPv6): 78 - ./in.cue:29:6 79 - ./in.cue:29:19 88 + ./in.cue:33:6 89 + ./in.cue:33:19 80 90 t39: error in call to net.AddIP: invalid IP "invalid ip": 81 - ./in.cue:41:6 91 + ./in.cue:45:6 82 92 t40: error in call to net.AddIP: IP address arithmetic resulted in out-of-range address (underflow): 83 - ./in.cue:42:6 93 + ./in.cue:46:6 84 94 t41: error in call to net.AddIP: IP address arithmetic resulted in out-of-range address (overflow): 85 - ./in.cue:43:6 95 + ./in.cue:47:6 86 96 t45: error in call to net.AddIPCIDR: netip.ParsePrefix("192.168.0.0"): no '/': 87 - ./in.cue:47:6 97 + ./in.cue:51:6 88 98 t46: error in call to net.AddIPCIDR: IP address arithmetic resulted in out-of-range address (underflow): 89 - ./in.cue:48:6 99 + ./in.cue:52:6 90 100 t47: error in call to net.AddIPCIDR: IP address arithmetic resulted in out-of-range address (overflow): 91 - ./in.cue:49:6 101 + ./in.cue:53:6 92 102 93 103 Result: 94 104 t1: "foo.bar." ··· 108 118 t15: true 109 119 t16: [127, 0, 0, 1] 110 120 t17: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1] 111 - t18: true 112 - t19: true 113 - t20: _|_ // t20: error in call to net.IPCIDR: netip.ParsePrefix("172.16.12.3"): no '/' 114 - t21: "foo%2Fbar" 115 - t22: "foo/bar" 116 - t23: "f%25o" 117 - t24: "f%o" 118 - t25: _|_ // t25: invalid value "2001:db8::1234567" (does not satisfy net.IPv6) 119 - t26: true 120 - t27: _|_ // t27: invalid value "23.23.23.23" (does not satisfy net.IPv6) 121 - t28: true 122 - t29: "/foo/bar" 123 - t30: _|_ // t30: invalid value "%" (does not satisfy net.URL): t30: error in call to net.URL: parse "%": invalid URL escape "%" 124 - t31: "https://foo.com/bar" 125 - t32: _|_ // t32: invalid value "/foo/bar" (does not satisfy net.AbsURL): t32: error in call to net.AbsURL: URL is not absolute 126 - t33: "https://foo.com/bar" 127 - t34: _|_ // t34: invalid value "%" (does not satisfy net.AbsURL): t34: error in call to net.AbsURL: parse "%": invalid URL escape "%" 128 - t35: "127.0.0.2" 129 - t36: "127.0.0.3/8" 130 - t37: "2001:db8::1" 131 - t38: "2001:db8::2/64" 132 - t39: _|_ // t39: error in call to net.AddIP: invalid IP "invalid ip" 133 - t40: _|_ // t40: error in call to net.AddIP: IP address arithmetic resulted in out-of-range address (underflow) 134 - t41: _|_ // t41: error in call to net.AddIP: IP address arithmetic resulted in out-of-range address (overflow) 135 - t42: "::ffff:127.0.0.2" 136 - t43: "192.168.2.0/23" 137 - t44: "2001:db8:1111:2223::/64" 138 - t45: _|_ // t45: error in call to net.AddIPCIDR: netip.ParsePrefix("192.168.0.0"): no '/' 139 - t46: _|_ // t46: error in call to net.AddIPCIDR: IP address arithmetic resulted in out-of-range address (underflow) 140 - t47: _|_ // t47: error in call to net.AddIPCIDR: IP address arithmetic resulted in out-of-range address (overflow) 121 + t18: true 122 + t19: true 123 + t20: _|_ // t20: error in call to net.IPCIDR: netip.ParsePrefix("172.16.12.3"): no '/' 124 + t20b: 123 125 + t20c: _|_ // t20c: invalid value 123 (does not satisfy net.IP) 126 + t20d: _|_ // t20d: invalid value 123 (does not satisfy net.IPv4) 127 + t20e: _|_ // t20e: invalid value 123 (does not satisfy net.IPv6) 128 + t21: "foo%2Fbar" 129 + t22: "foo/bar" 130 + t23: "f%25o" 131 + t24: "f%o" 132 + t25: _|_ // t25: invalid value "2001:db8::1234567" (does not satisfy net.IPv6) 133 + t26: true 134 + t27: _|_ // t27: invalid value "23.23.23.23" (does not satisfy net.IPv6) 135 + t28: true 136 + t29: "/foo/bar" 137 + t30: _|_ // t30: invalid value "%" (does not satisfy net.URL): t30: error in call to net.URL: parse "%": invalid URL escape "%" 138 + t31: "https://foo.com/bar" 139 + t32: _|_ // t32: invalid value "/foo/bar" (does not satisfy net.AbsURL): t32: error in call to net.AbsURL: URL is not absolute 140 + t33: "https://foo.com/bar" 141 + t34: _|_ // t34: invalid value "%" (does not satisfy net.AbsURL): t34: error in call to net.AbsURL: parse "%": invalid URL escape "%" 142 + t35: "127.0.0.2" 143 + t36: "127.0.0.3/8" 144 + t37: "2001:db8::1" 145 + t38: "2001:db8::2/64" 146 + t39: _|_ // t39: error in call to net.AddIP: invalid IP "invalid ip" 147 + t40: _|_ // t40: error in call to net.AddIP: IP address arithmetic resulted in out-of-range address (underflow) 148 + t41: _|_ // t41: error in call to net.AddIP: IP address arithmetic resulted in out-of-range address (overflow) 149 + t42: "::ffff:127.0.0.2" 150 + t43: "192.168.2.0/23" 151 + t44: "2001:db8:1111:2223::/64" 152 + t45: _|_ // t45: error in call to net.AddIPCIDR: netip.ParsePrefix("192.168.0.0"): no '/' 153 + t46: _|_ // t46: error in call to net.AddIPCIDR: IP address arithmetic resulted in out-of-range address (underflow) 154 + t47: _|_ // t47: error in call to net.AddIPCIDR: IP address arithmetic resulted in out-of-range address (overflow)