From 7b5ac688b865871b70b598c14c8e607e45d893c4 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Tue, 23 Mar 2021 01:31:42 +0000 Subject: [PATCH] fup: add test for disabled TokenAuthMiddleware --- web/fup/fuphttp/auth_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/web/fup/fuphttp/auth_test.go b/web/fup/fuphttp/auth_test.go index 811362b5d7..d1a1cf2e1e 100644 --- a/web/fup/fuphttp/auth_test.go +++ b/web/fup/fuphttp/auth_test.go @@ -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)