MCPcopy Index your code
hub / github.com/coder/coder / TestRewritePassthroughRequest

Function TestRewritePassthroughRequest

aibridge/passthrough_internal_test.go:141–258  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

139}
140
141func TestRewritePassthroughRequest(t *testing.T) {
142 t.Parallel()
143
144 tests := []struct {
145 name string
146 reqPath string
147 reqRemoteAddr string
148 reqHeaders http.Header
149 reqTLS bool
150 provider *testutil.MockProvider
151 expectURL string
152 expectHeaders http.Header
153 }{
154 {
155 name: "sets_upstream_url_and_forwarded_headers_from_client_peer",
156 reqPath: "http://client-host/chat?stream=true",
157 reqRemoteAddr: "1.1.1.1:1111",
158 provider: &testutil.MockProvider{URL: "https://upstream-host/base"},
159 expectURL: "https://upstream-host/base/chat?stream=true",
160 expectHeaders: http.Header{
161 "X-Forwarded-Host": {"client-host"},
162 "X-Forwarded-Proto": {"http"},
163 "X-Forwarded-For": {"1.1.1.1"},
164 "User-Agent": {"aibridge"},
165 },
166 },
167 {
168 name: "preserves_client_user_agent",
169 reqPath: "http://client-host/chat",
170 reqRemoteAddr: "1.1.1.1:1111",
171 reqHeaders: http.Header{"User-Agent": {"custom-agent/1.0"}},
172 provider: &testutil.MockProvider{URL: "https://upstream-host/base"},
173 expectURL: "https://upstream-host/base/chat",
174 expectHeaders: http.Header{
175 "X-Forwarded-Host": {"client-host"},
176 "X-Forwarded-Proto": {"http"},
177 "X-Forwarded-For": {"1.1.1.1"},
178 "User-Agent": {"custom-agent/1.0"},
179 },
180 },
181 {
182 name: "appends_remote_addr_to_existing_forwarded_for_chain",
183 reqPath: "http://client-host/chat",
184 reqRemoteAddr: "1.1.1.1:1111",
185 reqHeaders: http.Header{
186 "X-Forwarded-For": {"2.2.2.2, 3.3.3.3"},
187 },
188 provider: &testutil.MockProvider{URL: "https://upstream-host/base"},
189 expectURL: "https://upstream-host/base/chat",
190 expectHeaders: http.Header{
191 "X-Forwarded-Host": {"client-host"},
192 "X-Forwarded-Proto": {"http"},
193 "X-Forwarded-For": {"2.2.2.2, 3.3.3.3, 1.1.1.1"},
194 "User-Agent": {"aibridge"},
195 },
196 },
197 {
198 name: "tls_request_sets_forwarded_proto_to_https",

Callers

nothing calls this directly

Calls 8

RunMethod · 0.65
CopyMethod · 0.65
ParseMethod · 0.65
ContextMethod · 0.65
CloneMethod · 0.45
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected