mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-18 16:21:13 +00:00
Add redirection test for service using request host. Transport has no
scheme and host.
This commit is contained in:
parent
db809c0eb7
commit
6567bbee7b
@ -53,6 +53,9 @@ func TestProxyTransport(t *testing.T) {
|
|||||||
Host: "foo.com",
|
Host: "foo.com",
|
||||||
PathPrepend: "/proxy/node/node1:10250",
|
PathPrepend: "/proxy/node/node1:10250",
|
||||||
}
|
}
|
||||||
|
emptyHostAndSchemeTransport := &Transport{
|
||||||
|
PathPrepend: "/proxy/node/node1:10250",
|
||||||
|
}
|
||||||
type Item struct {
|
type Item struct {
|
||||||
input string
|
input string
|
||||||
sourceURL string
|
sourceURL string
|
||||||
@ -62,6 +65,7 @@ func TestProxyTransport(t *testing.T) {
|
|||||||
forwardedURI string
|
forwardedURI string
|
||||||
redirect string
|
redirect string
|
||||||
redirectWant string
|
redirectWant string
|
||||||
|
reqHost string
|
||||||
}
|
}
|
||||||
|
|
||||||
table := map[string]Item{
|
table := map[string]Item{
|
||||||
@ -158,6 +162,14 @@ func TestProxyTransport(t *testing.T) {
|
|||||||
redirectWant: "http://example.com/redirected/target/",
|
redirectWant: "http://example.com/redirected/target/",
|
||||||
forwardedURI: "/proxy/node/node1:10250/redirect",
|
forwardedURI: "/proxy/node/node1:10250/redirect",
|
||||||
},
|
},
|
||||||
|
"redirect abs use reqHost no host no scheme": {
|
||||||
|
sourceURL: "http://mynode.com/redirect",
|
||||||
|
transport: emptyHostAndSchemeTransport,
|
||||||
|
redirect: "http://10.0.0.1:8001/redirected/target/",
|
||||||
|
redirectWant: "http://10.0.0.1:8001/proxy/node/node1:10250/redirected/target/",
|
||||||
|
forwardedURI: "/proxy/node/node1:10250/redirect",
|
||||||
|
reqHost: "10.0.0.1:8001",
|
||||||
|
},
|
||||||
"source contains the redirect already": {
|
"source contains the redirect already": {
|
||||||
input: `<pre><a href="kubelet.log">kubelet.log</a><a href="http://foo.com/proxy/node/node1:10250/google.log">google.log</a></pre>`,
|
input: `<pre><a href="kubelet.log">kubelet.log</a><a href="http://foo.com/proxy/node/node1:10250/google.log">google.log</a></pre>`,
|
||||||
sourceURL: "http://foo.com/logs/log.log",
|
sourceURL: "http://foo.com/logs/log.log",
|
||||||
@ -233,6 +245,9 @@ func TestProxyTransport(t *testing.T) {
|
|||||||
t.Errorf("%v: Unexpected error: %v", name, err)
|
t.Errorf("%v: Unexpected error: %v", name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if item.reqHost != "" {
|
||||||
|
req.Host = item.reqHost
|
||||||
|
}
|
||||||
resp, err := item.transport.RoundTrip(req)
|
resp, err := item.transport.RoundTrip(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%v: Unexpected error: %v", name, err)
|
t.Errorf("%v: Unexpected error: %v", name, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user