fup: add test for disabled TokenAuthMiddleware

This commit is contained in:
Luke Granger-Brown 2021-03-23 01:31:42 +00:00
parent affe252f73
commit 7b5ac688b8

View file

@ -10,6 +10,31 @@ import (
"hg.lukegb.com/lukegb/depot/web/fup/fuphttp"
)
func TestTokenAuthMiddlewareNoToken(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
ccfg := *cfg
ccfg.AuthMiddleware = fuphttp.TokenAuthMiddleware("", "realm")
a, err := fuphttp.New(ctx, &ccfg)
if err != nil {
t.Fatalf("fuphttp.New: %v", err)
}
s := httptest.NewServer(a.Handler())
t.Cleanup(s.Close)
resp, err := s.Client().Get(s.URL)
if err != nil {
t.Fatalf("Get(%q): %v", s.URL, err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Errorf("status code was %v; want %v", resp.StatusCode, http.StatusOK)
}
}
func TestTokenAuthMiddleware(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)