integration: Add https redirect tests
This commit is contained in:
parent
a7c780a732
commit
9f1543f81e
|
@ -533,6 +533,49 @@ func TestH1H1RespPhaseReturn(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestH1H1HTTPSRedirect tests that the request to the backend which
|
||||
// requires TLS is redirected to https URI.
|
||||
func TestH1H1HTTPSRedirect(t *testing.T) {
|
||||
st := newServerTester([]string{"--redirect-if-not-tls"}, t, noopHandler)
|
||||
defer st.Close()
|
||||
|
||||
res, err := st.http1(requestParam{
|
||||
name: "TestH1H1HTTPSRedirect",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Error st.http1() = %v", err)
|
||||
}
|
||||
|
||||
if got, want := res.status, 308; got != want {
|
||||
t.Errorf("status = %v; want %v", got, want)
|
||||
}
|
||||
if got, want := res.header.Get("location"), "https://127.0.0.1/"; got != want {
|
||||
t.Errorf("location: %v; want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestH1H1HTTPSRedirectPort tests that the request to the backend
|
||||
// which requires TLS is redirected to https URI with given port.
|
||||
func TestH1H1HTTPSRedirectPort(t *testing.T) {
|
||||
st := newServerTester([]string{"--redirect-if-not-tls", "--redirect-https-port=8443"}, t, noopHandler)
|
||||
defer st.Close()
|
||||
|
||||
res, err := st.http1(requestParam{
|
||||
path: "/foo?bar",
|
||||
name: "TestH1H1HTTPSRedirectPort",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Error st.http1() = %v", err)
|
||||
}
|
||||
|
||||
if got, want := res.status, 308; got != want {
|
||||
t.Errorf("status = %v; want %v", got, want)
|
||||
}
|
||||
if got, want := res.header.Get("location"), "https://127.0.0.1:8443/foo?bar"; got != want {
|
||||
t.Errorf("location: %v; want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// // TestH1H2ConnectFailure tests that server handles the situation that
|
||||
// // connection attempt to HTTP/2 backend failed.
|
||||
// func TestH1H2ConnectFailure(t *testing.T) {
|
||||
|
|
|
@ -1405,6 +1405,49 @@ func TestH2H1DNS(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestH2H1HTTPSRedirect tests that the request to the backend which
|
||||
// requires TLS is redirected to https URI.
|
||||
func TestH2H1HTTPSRedirect(t *testing.T) {
|
||||
st := newServerTester([]string{"--redirect-if-not-tls"}, t, noopHandler)
|
||||
defer st.Close()
|
||||
|
||||
res, err := st.http2(requestParam{
|
||||
name: "TestH2H1HTTPSRedirect",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Error st.http2() = %v", err)
|
||||
}
|
||||
|
||||
if got, want := res.status, 308; got != want {
|
||||
t.Errorf("status = %v; want %v", got, want)
|
||||
}
|
||||
if got, want := res.header.Get("location"), "https://127.0.0.1/"; got != want {
|
||||
t.Errorf("location: %v; want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestH2H1HTTPSRedirectPort tests that the request to the backend
|
||||
// which requires TLS is redirected to https URI with given port.
|
||||
func TestH2H1HTTPSRedirectPort(t *testing.T) {
|
||||
st := newServerTester([]string{"--redirect-if-not-tls", "--redirect-https-port=8443"}, t, noopHandler)
|
||||
defer st.Close()
|
||||
|
||||
res, err := st.http2(requestParam{
|
||||
path: "/foo?bar",
|
||||
name: "TestH2H1HTTPSRedirectPort",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Error st.http2() = %v", err)
|
||||
}
|
||||
|
||||
if got, want := res.status, 308; got != want {
|
||||
t.Errorf("status = %v; want %v", got, want)
|
||||
}
|
||||
if got, want := res.header.Get("location"), "https://127.0.0.1:8443/foo?bar"; got != want {
|
||||
t.Errorf("location: %v; want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestH2H1GracefulShutdown tests graceful shutdown.
|
||||
func TestH2H1GracefulShutdown(t *testing.T) {
|
||||
st := newServerTester(nil, t, noopHandler)
|
||||
|
|
|
@ -101,10 +101,8 @@ func newServerTesterInternal(src_args []string, t *testing.T, handler http.Handl
|
|||
|
||||
args := []string{}
|
||||
|
||||
backendTLS := false
|
||||
dns := false
|
||||
externalDNS := false
|
||||
acceptProxyProtocol := false
|
||||
var backendTLS, dns, externalDNS, acceptProxyProtocol, redirectIfNotTLS bool
|
||||
|
||||
for _, k := range src_args {
|
||||
switch k {
|
||||
case "--http2-bridge":
|
||||
|
@ -116,6 +114,8 @@ func newServerTesterInternal(src_args []string, t *testing.T, handler http.Handl
|
|||
externalDNS = true
|
||||
case "--accept-proxy-protocol":
|
||||
acceptProxyProtocol = true
|
||||
case "--redirect-if-not-tls":
|
||||
redirectIfNotTLS = true
|
||||
default:
|
||||
args = append(args, k)
|
||||
}
|
||||
|
@ -164,6 +164,10 @@ func newServerTesterInternal(src_args []string, t *testing.T, handler http.Handl
|
|||
b += ";dns"
|
||||
}
|
||||
|
||||
if redirectIfNotTLS {
|
||||
b += ";redirect-if-not-tls"
|
||||
}
|
||||
|
||||
noTLS := ";no-tls"
|
||||
if frontendTLS {
|
||||
noTLS = ""
|
||||
|
|
Loading…
Reference in New Issue