From ed965a74d22eee8de962ca8cc5a200374e9eff13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Fri, 30 Oct 2020 17:17:32 +0000 Subject: [PATCH] fix(tests): add missing test coverage for basic auth --- cmd/karma/views_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cmd/karma/views_test.go b/cmd/karma/views_test.go index 9c5ed8078..f8900bf3d 100644 --- a/cmd/karma/views_test.go +++ b/cmd/karma/views_test.go @@ -1032,6 +1032,35 @@ func TestAuthentication(t *testing.T) { } } +func TestInvalidBasicAuthHeader(t *testing.T) { + config.Config.Authentication.Header.Name = "" + config.Config.Authentication.Header.ValueRegex = "" + config.Config.Authentication.BasicAuth.Users = []config.AuthenticationUser{ + {Username: "john", Password: "foobar"}, + } + r := testRouter() + setupRouter(r) + mockCache() + for _, path := range []string{ + "/", + "/alerts.json", + "/autocomplete.json?term=foo", + "/labelNames.json", + "/labelValues.json?name=foo", + "/silences.json", + "/custom.css", + "/custom.js", + } { + req := httptest.NewRequest("GET", path, nil) + req.Header.Set("Authorization", "") + resp := httptest.NewRecorder() + r.ServeHTTP(resp, req) + if resp.Code != 401 { + t.Errorf("Expected 401 from %s, got %d", path, resp.Code) + } + } +} + func TestUpstreamStatus(t *testing.T) { zerolog.SetGlobalLevel(zerolog.FatalLevel)