Debian Codegraph @

caddyconfig/httpcaddyfile/addresses_test.go

raw symbols SCIP
1 package httpcaddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/
2
3 import (
4 "testingscip-go gomod github.com/golang/go/src go1.25.1 testing/"
5 )
6
7 func TestParseAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/TestParseAddress().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
8 for i, test := range []struct {
9 input string
10 scheme, host, port, path string
11 shouldErr bool
12 }{
13 {``, "", "", "", "", false},
14 {`localhost`, "", "localhost", "", "", false},
15 {`localhost:1234`, "", "localhost", "1234", "", false},
16 {`localhost:`, "", "localhost", "", "", false},
17 {`0.0.0.0`, "", "0.0.0.0", "", "", false},
18 {`127.0.0.1:1234`, "", "127.0.0.1", "1234", "", false},
19 {`:1234`, "", "", "1234", "", false},
20 {`[::1]`, "", "::1", "", "", false},
21 {`[::1]:1234`, "", "::1", "1234", "", false},
22 {`:`, "", "", "", "", false},
23 {`:http`, "", "", "", "", true},
24 {`:https`, "", "", "", "", true},
25 {`localhost:http`, "", "", "", "", true}, // using service name in port is verboten, as of Go 1.12.8
26 {`localhost:https`, "", "", "", "", true},
27 {`http://localhost:https`, "", "", "", "", true}, // conflict
28 {`http://localhost:http`, "", "", "", "", true}, // repeated scheme
29 {`host:https/path`, "", "", "", "", true},
30 {`http://localhost:443`, "http", "localhost", "443", "", false}, // NOTE: not conventional
31 {`https://localhost:80`, "https", "localhost", "80", "", false}, // NOTE: not conventional
32 {`http://localhost`, "http", "localhost", "", "", false},
33 {`https://localhost`, "https", "localhost", "", "", false},
34 {`http://{env.APP_DOMAIN}`, "http", "{env.APP_DOMAIN}", "", "", false},
35 {`{env.APP_DOMAIN}:80`, "", "{env.APP_DOMAIN}", "80", "", false},
36 {`{env.APP_DOMAIN}/path`, "", "{env.APP_DOMAIN}", "", "/path", false},
37 {`example.com/{env.APP_PATH}`, "", "example.com", "", "/{env.APP_PATH}", false},
38 {`http://127.0.0.1`, "http", "127.0.0.1", "", "", false},
39 {`https://127.0.0.1`, "https", "127.0.0.1", "", "", false},
40 {`http://[::1]`, "http", "::1", "", "", false},
41 {`http://localhost:1234`, "http", "localhost", "1234", "", false},
42 {`https://127.0.0.1:1234`, "https", "127.0.0.1", "1234", "", false},
43 {`http://[::1]:1234`, "http", "::1", "1234", "", false},
44 {``, "", "", "", "", false},
45 {`::1`, "", "::1", "", "", false},
46 {`localhost::`, "", "localhost::", "", "", false},
47 {`#$%@`, "", "#$%@", "", "", false}, // don't want to presume what the hostname could be
48 {`host/path`, "", "host", "", "/path", false},
49 {`http://host/`, "http", "host", "", "/", false},
50 {`//asdf`, "", "", "", "//asdf", false},
51 {`:1234/asdf`, "", "", "1234", "/asdf", false},
52 {`http://host/path`, "http", "host", "", "/path", false},
53 {`https://host:443/path/foo`, "https", "host", "443", "/path/foo", false},
54 {`host:80/path`, "", "host", "80", "/path", false},
55 {`/path`, "", "", "", "/path", false},
56 } {
57 actual, err := ParseAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ParseAddress().(test.input)
58
59 if err != nil && !test.shouldErr {
60 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d (%s): Expected no error, but had error: %v", i, test.input, err)
61 }
62 if err == nil && test.shouldErr {
63 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d (%s): Expected error, but had none (%#v)", i, test.input, actual)
64 }
65
66 if !test.shouldErr && actual.Originalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Original. != test.input {
67 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d (%s): Expected original '%s', got '%s'", i, test.input, test.input, actual.Originalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Original.)
68 }
69 if actual.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme. != test.scheme {
70 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d (%s): Expected scheme '%s', got '%s'", i, test.input, test.scheme, actual.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.)
71 }
72 if actual.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. != test.host {
73 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d (%s): Expected host '%s', got '%s'", i, test.input, test.host, actual.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.)
74 }
75 if actual.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port. != test.port {
76 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d (%s): Expected port '%s', got '%s'", i, test.input, test.port, actual.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.)
77 }
78 if actual.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path. != test.path {
79 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d (%s): Expected path '%s', got '%s'", i, test.input, test.path, actual.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.)
80 }
81 }
82 }
83
84 func TestAddressStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/TestAddressString().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
85 for i, test := range []struct {
86 addr Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#
87 expected string
88 }{
89 {Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "http", Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "host", Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "1234", Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: "/path"}, "http://host:1234/path"},
90 {Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "", Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "host", Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "", Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: ""}, "http://host"},
91 {Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "", Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "host", Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "80", Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: ""}, "http://host"},
92 {Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "", Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "host", Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "443", Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: ""}, "https://host"},
93 {Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "https", Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "host", Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "443", Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: ""}, "https://host"},
94 {Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "https", Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "host", Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "", Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: ""}, "https://host"},
95 {Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "", Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "host", Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "80", Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: "/path"}, "http://host/path"},
96 {Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "http", Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "", Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "1234", Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: ""}, "http://:1234"},
97 {Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "", Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "", Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "", Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: ""}, ""},
98 } {
99 actual := test.addr.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#String().()
100 if actual != test.expected {
101 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d: expected '%s' but got '%s'", i, test.expected, actual)
102 }
103 }
104 }
105
106 func TestKeyNormalizationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/TestKeyNormalization().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
107 testCases := []struct {
108 input string
109 expect Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#
110 }{
111 {
112 input: "example.com",
113 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
114 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "example.com",
115 },
116 },
117 {
118 input: "http://host:1234/path",
119 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
120 Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "http",
121 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "host",
122 Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "1234",
123 Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: "/path",
124 },
125 },
126 {
127 input: "HTTP://A/ABCDEF",
128 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
129 Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.: "http",
130 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "a",
131 Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: "/ABCDEF",
132 },
133 },
134 {
135 input: "A/ABCDEF",
136 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
137 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "a",
138 Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: "/ABCDEF",
139 },
140 },
141 {
142 input: "A:2015/Path",
143 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
144 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "a",
145 Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "2015",
146 Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.: "/Path",
147 },
148 },
149 {
150 input: "sub.{env.MY_DOMAIN}",
151 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
152 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "sub.{env.MY_DOMAIN}",
153 },
154 },
155 {
156 input: "sub.ExAmPle",
157 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
158 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "sub.example",
159 },
160 },
161 {
162 input: "sub.\\{env.MY_DOMAIN\\}",
163 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
164 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "sub.\\{env.my_domain\\}",
165 },
166 },
167 {
168 input: "sub.{env.MY_DOMAIN}.com",
169 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
170 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "sub.{env.MY_DOMAIN}.com",
171 },
172 },
173 {
174 input: ":80",
175 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
176 Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "80",
177 },
178 },
179 {
180 input: ":443",
181 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
182 Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "443",
183 },
184 },
185 {
186 input: ":1234",
187 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
188 Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "1234",
189 },
190 },
191 {
192 input: "",
193 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{},
194 },
195 {
196 input: ":",
197 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{},
198 },
199 {
200 input: "[::]",
201 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
202 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "::",
203 },
204 },
205 {
206 input: "127.0.0.1",
207 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
208 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "127.0.0.1",
209 },
210 },
211 {
212 input: "[2001:db8:85a3:8d3:1319:8a2e:370:7348]:1234",
213 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
214 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "2001:db8:85a3:8d3:1319:8a2e:370:7348",
215 Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "1234",
216 },
217 },
218 {
219 // IPv4 address in IPv6 form (#4381)
220 input: "[::ffff:cff4:e77d]:1234",
221 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
222 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "::ffff:cff4:e77d",
223 Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.: "1234",
224 },
225 },
226 {
227 input: "::ffff:cff4:e77d",
228 expect: Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#{
229 Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.: "::ffff:cff4:e77d",
230 },
231 },
232 }
233 for i, tc := range testCases {
234 addr, err := ParseAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ParseAddress().(tc.input)
235 if err != nil {
236 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d: Parsing address '%s': %v", i, tc.input, err)
237 continue
238 }
239 actual := addr.Normalizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Normalize().()
240 if actual.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme. != tc.expect.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme. {
241 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d: Input '%s': Expected Scheme='%s' but got Scheme='%s'", i, tc.input, tc.expect.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme., actual.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme.)
242 }
243 if actual.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. != tc.expect.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. {
244 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d: Input '%s': Expected Host='%s' but got Host='%s'", i, tc.input, tc.expect.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host., actual.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.)
245 }
246 if actual.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port. != tc.expect.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port. {
247 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d: Input '%s': Expected Port='%s' but got Port='%s'", i, tc.input, tc.expect.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port., actual.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port.)
248 }
249 if actual.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path. != tc.expect.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path. {
250 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d: Input '%s': Expected Path='%s' but got Path='%s'", i, tc.input, tc.expect.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path., actual.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.)
251 }
252 }
253 }