1
0
mirror of https://github.com/umputun/reproxy.git synced 2025-06-30 22:13:42 +02:00
Files
reproxy/app/proxy/ssl_test.go

39 lines
911 B
Go
Raw Normal View History

2021-04-02 03:13:49 -05:00
package proxy
import (
"crypto/tls"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSSL_Redirect(t *testing.T) {
p := Http{}
ts := httptest.NewServer(p.httpToHTTPSRouter())
defer ts.Close()
client := http.Client{
// prevent http redirect
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
// allow self-signed certificate
Transport: &http.Transport{
2021-04-03 01:00:09 -05:00
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint
2021-04-02 03:13:49 -05:00
},
}
// check http to https redirect response
resp, err := client.Get(strings.Replace(ts.URL, "127.0.0.1", "localhost", 1) + "/blah?param=1")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, 307, resp.StatusCode)
assert.Equal(t, "https://localhost:443/blah?param=1", resp.Header.Get("Location"))
}