Skip to content

Commit

Permalink
Lint it
Browse files Browse the repository at this point in the history
  • Loading branch information
foot committed Feb 21, 2022
1 parent 490a0b5 commit 000e115
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/server/auth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (s *AuthServer) SignIn() http.HandlerFunc {
err := json.NewDecoder(r.Body).Decode(&loginRequest)
if err != nil {
s.logger.Error(err, "Failed to decode from JSON")
http.Error(rw, fmt.Sprintf("Failed to read request body."), http.StatusBadRequest)
http.Error(rw, "Failed to read request body.", http.StatusBadRequest)

return
}
Expand All @@ -246,7 +246,7 @@ func (s *AuthServer) SignIn() http.HandlerFunc {
Name: "admin-password-hash",
}, &hashedSecret); err != nil {
s.logger.Error(err, "Failed to query for the secret")
http.Error(rw, fmt.Sprint("Please ensure that a password has been set."), http.StatusBadRequest)
http.Error(rw, "Please ensure that a password has been set.", http.StatusBadRequest)

return
}
Expand Down Expand Up @@ -296,7 +296,7 @@ func (s *AuthServer) UserInfo() http.HandlerFunc {
ui := UserInfo{
Email: claims.Subject,
}
toJson(rw, ui)
toJson(rw, ui, s.logger)

return
}
Expand All @@ -313,18 +313,21 @@ func (s *AuthServer) UserInfo() http.HandlerFunc {
Email: info.Email,
}

toJson(rw, ui)
toJson(rw, ui, s.logger)
}
}

func toJson(rw http.ResponseWriter, ui UserInfo) {
func toJson(rw http.ResponseWriter, ui UserInfo, logger logr.Logger) {
b, err := json.Marshal(ui)
if err != nil {
http.Error(rw, fmt.Sprintf("failed to marshal to JSON: %v", err), http.StatusInternalServerError)
return
}

rw.Write(b)
_, err = rw.Write(b)
if err != nil {
logger.Error(err, "Failing to write response")
}
}

func (c *AuthServer) startAuthFlow(rw http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/auth/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ func TestSingInCorrectPassword(t *testing.T) {

if cookie == nil {
t.Errorf("expected to find cookie %q but did not", auth.IDTokenCookieName)
// Make linter happy about possible nil deref below
return
}

if _, err := tokenSignerVerifier.Verify(cookie.Value); err != nil {
Expand Down

0 comments on commit 000e115

Please sign in to comment.