10 "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/options"
11 "github.com/stretchr/testify/assert"
14func TestRedirectToHTTPSTrue(t *testing.T) {
15 opts := options.NewOptions()
16 opts.ForceHTTPS = true
17 handler := func(w http.ResponseWriter, req *http.Request) {
18 w.Write([]byte("test"))
21 h := redirectToHTTPS(opts, http.HandlerFunc(handler))
22 rw := httptest.NewRecorder()
23 r, _ := http.NewRequest("GET", "/", nil)
26 assert.Equal(t, http.StatusPermanentRedirect, rw.Code, "status code should be %d, got: %d", http.StatusPermanentRedirect, rw.Code)
29func TestRedirectToHTTPSFalse(t *testing.T) {
30 opts := options.NewOptions()
31 handler := func(w http.ResponseWriter, req *http.Request) {
32 w.Write([]byte("test"))
35 h := redirectToHTTPS(opts, http.HandlerFunc(handler))
36 rw := httptest.NewRecorder()
37 r, _ := http.NewRequest("GET", "/", nil)
40 assert.Equal(t, http.StatusOK, rw.Code, "status code should be %d, got: %d", http.StatusOK, rw.Code)
43func TestRedirectNotWhenHTTPS(t *testing.T) {
44 opts := options.NewOptions()
45 opts.ForceHTTPS = true
46 handler := func(w http.ResponseWriter, req *http.Request) {
47 w.Write([]byte("test"))
50 h := redirectToHTTPS(opts, http.HandlerFunc(handler))
51 s := httptest.NewTLSServer(h)
54 opts.HTTPSAddress = s.URL
56 res, err := client.Get(s.URL)
58 t.Fatalf("request to test server failed with error: %v", err)
61 assert.Equal(t, http.StatusOK, res.StatusCode, "status code should be %d, got: %d", http.StatusOK, res.StatusCode)
64func TestGracefulShutdown(t *testing.T) {
65 opts := options.NewOptions()
66 stop := make(chan struct{}, 1)
67 srv := Server{Handler: http.DefaultServeMux, Opts: opts, stop: stop}
75 stop <- struct{}{} // emulate catching signals
77 // An idiomatic for sync.WaitGroup with timeout
78 c := make(chan struct{})
85 case <-time.After(1 * time.Second):
86 t.Fatal("Server should return gracefully but timeout has occurred")
89 assert.Len(t, stop, 0) // check if stop chan is empty
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list