From 3cfb2b30a68dfc265f4157f049cdf1f0e4b42046 Mon Sep 17 00:00:00 2001 From: Tanmay Naik Date: Tue, 9 Jun 2020 17:19:01 -0400 Subject: [PATCH] fix: the bug when htpasswd has multiple creds earlier, when you had more than one creds in htpasswd file separated by newline, it used to only read the first cred in the file and ignore the rest. --- pkg/api/auth.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/api/auth.go b/pkg/api/auth.go index 2efaa4fe..402cbe86 100644 --- a/pkg/api/auth.go +++ b/pkg/api/auth.go @@ -141,15 +141,16 @@ func basicAuthHandler(c *Controller) mux.MiddlewareFunc { if err != nil { panic(err) } + defer f.Close() - for { - r := bufio.NewReader(f) - line, err := r.ReadString('\n') - if err != nil { - break + scanner := bufio.NewScanner(f) + + for scanner.Scan() { + line := scanner.Text() + if strings.Contains(line, ":") { + tokens := strings.Split(scanner.Text(), ":") + credMap[tokens[0]] = tokens[1] } - tokens := strings.Split(line, ":") - credMap[tokens[0]] = tokens[1] } } }