mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-06-19 22:58:30 +02:00
Add SSL check and test no redirect when HTTPS
Signed-off-by: Josh Michielsen <github@mickey.dev>
This commit is contained in:
@@ -135,3 +135,24 @@ func TestRedirectToHTTPSFalse(t *testing.T) {
|
||||
|
||||
assert.Equal(t, http.StatusOK, rw.Code, "status code should be %d, got: %d", http.StatusOK, rw.Code)
|
||||
}
|
||||
|
||||
func TestRedirectNotWhenHTTPS(t *testing.T) {
|
||||
opts := NewOptions()
|
||||
opts.ForceHTTPS = true
|
||||
handler := func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Write([]byte("test"))
|
||||
}
|
||||
|
||||
h := redirectToHTTPS(opts, http.HandlerFunc(handler))
|
||||
s := httptest.NewTLSServer(h)
|
||||
defer s.Close()
|
||||
|
||||
opts.HTTPSAddress = s.URL
|
||||
client := s.Client()
|
||||
res, err := client.Get(s.URL)
|
||||
if err != nil {
|
||||
t.Fatalf("request to test server failed with error: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode, "status code should be %d, got: %d", http.StatusOK, res.StatusCode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user