Merge branch 'ps/reftable-write-optim'
[alt-git.git] / t / t0110-urlmatch-normalization.sh
blob12d817fbd34002cf5e8cd6561551b23303c27f6f
1 #!/bin/sh
3 test_description='urlmatch URL normalization'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 # The base name of the test url files
9 tu="$TEST_DIRECTORY/t0110/url"
11 # Note that only file: URLs should be allowed without a host
13 test_expect_success 'url scheme' '
14 ! test-tool urlmatch-normalization "" &&
15 ! test-tool urlmatch-normalization "_" &&
16 ! test-tool urlmatch-normalization "scheme" &&
17 ! test-tool urlmatch-normalization "scheme:" &&
18 ! test-tool urlmatch-normalization "scheme:/" &&
19 ! test-tool urlmatch-normalization "scheme://" &&
20 ! test-tool urlmatch-normalization "file" &&
21 ! test-tool urlmatch-normalization "file:" &&
22 ! test-tool urlmatch-normalization "file:/" &&
23 test-tool urlmatch-normalization "file://" &&
24 ! test-tool urlmatch-normalization "://acme.co" &&
25 ! test-tool urlmatch-normalization "x_test://acme.co" &&
26 ! test-tool urlmatch-normalization "-test://acme.co" &&
27 ! test-tool urlmatch-normalization "0test://acme.co" &&
28 ! test-tool urlmatch-normalization "+test://acme.co" &&
29 ! test-tool urlmatch-normalization ".test://acme.co" &&
30 ! test-tool urlmatch-normalization "schem%6e://" &&
31 test-tool urlmatch-normalization "x-Test+v1.0://acme.co" &&
32 test "$(test-tool urlmatch-normalization -p "AbCdeF://x.Y")" = "abcdef://x.y/"
35 test_expect_success 'url authority' '
36 ! test-tool urlmatch-normalization "scheme://user:pass@" &&
37 ! test-tool urlmatch-normalization "scheme://?" &&
38 ! test-tool urlmatch-normalization "scheme://#" &&
39 ! test-tool urlmatch-normalization "scheme:///" &&
40 ! test-tool urlmatch-normalization "scheme://:" &&
41 ! test-tool urlmatch-normalization "scheme://:555" &&
42 test-tool urlmatch-normalization "file://user:pass@" &&
43 test-tool urlmatch-normalization "file://?" &&
44 test-tool urlmatch-normalization "file://#" &&
45 test-tool urlmatch-normalization "file:///" &&
46 test-tool urlmatch-normalization "file://:" &&
47 ! test-tool urlmatch-normalization "file://:555" &&
48 test-tool urlmatch-normalization "scheme://user:pass@host" &&
49 test-tool urlmatch-normalization "scheme://@host" &&
50 test-tool urlmatch-normalization "scheme://%00@host" &&
51 ! test-tool urlmatch-normalization "scheme://%%@host" &&
52 test-tool urlmatch-normalization "scheme://host_" &&
53 test-tool urlmatch-normalization "scheme://user:pass@host/" &&
54 test-tool urlmatch-normalization "scheme://@host/" &&
55 test-tool urlmatch-normalization "scheme://host/" &&
56 test-tool urlmatch-normalization "scheme://host?x" &&
57 test-tool urlmatch-normalization "scheme://host#x" &&
58 test-tool urlmatch-normalization "scheme://host/@" &&
59 test-tool urlmatch-normalization "scheme://host?@x" &&
60 test-tool urlmatch-normalization "scheme://host#@x" &&
61 test-tool urlmatch-normalization "scheme://[::1]" &&
62 test-tool urlmatch-normalization "scheme://[::1]/" &&
63 ! test-tool urlmatch-normalization "scheme://hos%41/" &&
64 test-tool urlmatch-normalization "scheme://[invalid....:/" &&
65 test-tool urlmatch-normalization "scheme://invalid....:]/" &&
66 ! test-tool urlmatch-normalization "scheme://invalid....:[/" &&
67 ! test-tool urlmatch-normalization "scheme://invalid....:["
70 test_expect_success 'url port checks' '
71 test-tool urlmatch-normalization "xyz://q@some.host:" &&
72 test-tool urlmatch-normalization "xyz://q@some.host:456/" &&
73 ! test-tool urlmatch-normalization "xyz://q@some.host:0" &&
74 ! test-tool urlmatch-normalization "xyz://q@some.host:0000000" &&
75 test-tool urlmatch-normalization "xyz://q@some.host:0000001?" &&
76 test-tool urlmatch-normalization "xyz://q@some.host:065535#" &&
77 test-tool urlmatch-normalization "xyz://q@some.host:65535" &&
78 ! test-tool urlmatch-normalization "xyz://q@some.host:65536" &&
79 ! test-tool urlmatch-normalization "xyz://q@some.host:99999" &&
80 ! test-tool urlmatch-normalization "xyz://q@some.host:100000" &&
81 ! test-tool urlmatch-normalization "xyz://q@some.host:100001" &&
82 test-tool urlmatch-normalization "http://q@some.host:80" &&
83 test-tool urlmatch-normalization "https://q@some.host:443" &&
84 test-tool urlmatch-normalization "http://q@some.host:80/" &&
85 test-tool urlmatch-normalization "https://q@some.host:443?" &&
86 ! test-tool urlmatch-normalization "http://q@:8008" &&
87 ! test-tool urlmatch-normalization "http://:8080" &&
88 ! test-tool urlmatch-normalization "http://:" &&
89 test-tool urlmatch-normalization "xyz://q@some.host:456/" &&
90 test-tool urlmatch-normalization "xyz://[::1]:456/" &&
91 test-tool urlmatch-normalization "xyz://[::1]:/" &&
92 ! test-tool urlmatch-normalization "xyz://[::1]:000/" &&
93 ! test-tool urlmatch-normalization "xyz://[::1]:0%300/" &&
94 ! test-tool urlmatch-normalization "xyz://[::1]:0x80/" &&
95 ! test-tool urlmatch-normalization "xyz://[::1]:4294967297/" &&
96 ! test-tool urlmatch-normalization "xyz://[::1]:030f/"
99 test_expect_success 'url port normalization' '
100 test "$(test-tool urlmatch-normalization -p "http://x:800")" = "http://x:800/" &&
101 test "$(test-tool urlmatch-normalization -p "http://x:0800")" = "http://x:800/" &&
102 test "$(test-tool urlmatch-normalization -p "http://x:00000800")" = "http://x:800/" &&
103 test "$(test-tool urlmatch-normalization -p "http://x:065535")" = "http://x:65535/" &&
104 test "$(test-tool urlmatch-normalization -p "http://x:1")" = "http://x:1/" &&
105 test "$(test-tool urlmatch-normalization -p "http://x:80")" = "http://x/" &&
106 test "$(test-tool urlmatch-normalization -p "http://x:080")" = "http://x/" &&
107 test "$(test-tool urlmatch-normalization -p "http://x:000000080")" = "http://x/" &&
108 test "$(test-tool urlmatch-normalization -p "https://x:443")" = "https://x/" &&
109 test "$(test-tool urlmatch-normalization -p "https://x:0443")" = "https://x/" &&
110 test "$(test-tool urlmatch-normalization -p "https://x:000000443")" = "https://x/"
113 test_expect_success 'url general escapes' '
114 ! test-tool urlmatch-normalization "http://x.y?%fg" &&
115 test "$(test-tool urlmatch-normalization -p "X://W/%7e%41^%3a")" = "x://w/~A%5E%3A" &&
116 test "$(test-tool urlmatch-normalization -p "X://W/:/?#[]@")" = "x://w/:/?#[]@" &&
117 test "$(test-tool urlmatch-normalization -p "X://W/$&()*+,;=")" = "x://w/$&()*+,;=" &&
118 test "$(test-tool urlmatch-normalization -p "X://W/'\''")" = "x://w/'\''" &&
119 test "$(test-tool urlmatch-normalization -p "X://W?'\!'")" = "x://w/?'\!'"
122 test_expect_success !MINGW 'url high-bit escapes' '
123 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-1")")" = "x://q/%01%02%03%04%05%06%07%08%0E%0F%10%11%12" &&
124 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-2")")" = "x://q/%13%14%15%16%17%18%19%1B%1C%1D%1E%1F%7F" &&
125 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-3")")" = "x://q/%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F" &&
126 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-4")")" = "x://q/%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F" &&
127 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-5")")" = "x://q/%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF" &&
128 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-6")")" = "x://q/%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF" &&
129 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-7")")" = "x://q/%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF" &&
130 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-8")")" = "x://q/%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF" &&
131 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-9")")" = "x://q/%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF" &&
132 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-10")")" = "x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF"
135 test_expect_success 'url utf-8 escapes' '
136 test "$(test-tool urlmatch-normalization -p "$(cat "$tu-11")")" = "x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD"
139 test_expect_success 'url username/password escapes' '
140 test "$(test-tool urlmatch-normalization -p "x://%41%62(^):%70+d@foo")" = "x://Ab(%5E):p+d@foo/"
143 test_expect_success 'url normalized lengths' '
144 test "$(test-tool urlmatch-normalization -l "Http://%4d%65:%4d^%70@The.Host")" = 25 &&
145 test "$(test-tool urlmatch-normalization -l "http://%41:%42@x.y/%61/")" = 17 &&
146 test "$(test-tool urlmatch-normalization -l "http://@x.y/^")" = 15
149 test_expect_success 'url . and .. segments' '
150 test "$(test-tool urlmatch-normalization -p "x://y/.")" = "x://y/" &&
151 test "$(test-tool urlmatch-normalization -p "x://y/./")" = "x://y/" &&
152 test "$(test-tool urlmatch-normalization -p "x://y/a/.")" = "x://y/a" &&
153 test "$(test-tool urlmatch-normalization -p "x://y/a/./")" = "x://y/a/" &&
154 test "$(test-tool urlmatch-normalization -p "x://y/.?")" = "x://y/?" &&
155 test "$(test-tool urlmatch-normalization -p "x://y/./?")" = "x://y/?" &&
156 test "$(test-tool urlmatch-normalization -p "x://y/a/.?")" = "x://y/a?" &&
157 test "$(test-tool urlmatch-normalization -p "x://y/a/./?")" = "x://y/a/?" &&
158 test "$(test-tool urlmatch-normalization -p "x://y/a/./b/.././../c")" = "x://y/c" &&
159 test "$(test-tool urlmatch-normalization -p "x://y/a/./b/../.././c/")" = "x://y/c/" &&
160 test "$(test-tool urlmatch-normalization -p "x://y/a/./b/.././../c/././.././.")" = "x://y/" &&
161 ! test-tool urlmatch-normalization "x://y/a/./b/.././../c/././.././.." &&
162 test "$(test-tool urlmatch-normalization -p "x://y/a/./?/././..")" = "x://y/a/?/././.." &&
163 test "$(test-tool urlmatch-normalization -p "x://y/%2e/")" = "x://y/" &&
164 test "$(test-tool urlmatch-normalization -p "x://y/%2E/")" = "x://y/" &&
165 test "$(test-tool urlmatch-normalization -p "x://y/a/%2e./")" = "x://y/" &&
166 test "$(test-tool urlmatch-normalization -p "x://y/b/.%2E/")" = "x://y/" &&
167 test "$(test-tool urlmatch-normalization -p "x://y/c/%2e%2E/")" = "x://y/"
170 # http://@foo specifies an empty user name but does not specify a password
171 # http://foo specifies neither a user name nor a password
172 # So they should not be equivalent
173 test_expect_success 'url equivalents' '
174 test-tool urlmatch-normalization "httP://x" "Http://X/" &&
175 test-tool urlmatch-normalization "Http://%4d%65:%4d^%70@The.Host" "hTTP://Me:%4D^p@the.HOST:80/" &&
176 ! test-tool urlmatch-normalization "https://@x.y/^" "httpS://x.y:443/^" &&
177 test-tool urlmatch-normalization "https://@x.y/^" "httpS://@x.y:0443/^" &&
178 test-tool urlmatch-normalization "https://@x.y/^/../abc" "httpS://@x.y:0443/abc" &&
179 test-tool urlmatch-normalization "https://@x.y/^/.." "httpS://@x.y:0443/"
182 test_done