@@ -135,3 +135,24 @@ func TestRedirectToHTTPSFalse(t *testing.T) {
135135
136136 assert.Equal(t, http.StatusOK, rw.Code, "status code should be %d, got: %d", http.StatusOK, rw.Code)
137137}
138+
139+func TestRedirectNotWhenHTTPS(t *testing.T) {
140+ opts := NewOptions()
141+ opts.ForceHTTPS = true
142+ handler := func(w http.ResponseWriter, req *http.Request) {
143+ w.Write([]byte("test"))
144+ }
145+
146+ h := redirectToHTTPS(opts, http.HandlerFunc(handler))
147+ s := httptest.NewTLSServer(h)
148+ defer s.Close()
149+
150+ opts.HTTPSAddress = s.URL
151+ client := s.Client()
152+ res, err := client.Get(s.URL)
153+ if err != nil {
154+ t.Fatalf("request to test server failed with error: %v", err)
155+ }
156+
157+ assert.Equal(t, http.StatusOK, res.StatusCode, "status code should be %d, got: %d", http.StatusOK, res.StatusCode)
158+}