diff --git a/Makefile b/Makefile index cdcf6af931aed4834f442e92bd70fe50a5ea8c1d..d83ed4c22158182ec74d1b5c839cb1c3a6026d19 100644 --- a/Makefile +++ b/Makefile @@ -97,9 +97,9 @@ vet: fi lint: - @echo "--> Running golint" - @which golint 2>/dev/null ; if [ $$? -eq 1 ]; then \ - go get -u github.com/golang/lint/golint; \ + @echo "--> Running golangci-lint" + @which golangci-lint 2>/dev/null ; if [ $$? -eq 1 ]; then \ + go get -u github.com/golangci/golangci-lint/cmd/golangci-lint; \ fi @golint . @@ -114,7 +114,7 @@ gofmt: verify: @echo "--> Verifying the code" - gometalinter --disable=errcheck --disable=gocyclo --disable=gas --disable=aligncheck --errors + golangci-lint run format: @echo "--> Running go fmt" diff --git a/cookies_test.go b/cookies_test.go index 6fb5f0a9b285340b6913e9183d3aafe37507fe87..bbd9cd4a001dd2543f5a12a9ad39848ec3c3f08b 100644 --- a/cookies_test.go +++ b/cookies_test.go @@ -36,13 +36,16 @@ func TestCookieDomainHostHeader(t *testing.T) { cookie = c } } + defer resp.Body.Close() + assert.NotNil(t, cookie) assert.Equal(t, cookie.Domain, "127.0.0.1") } func TestCookieBasePath(t *testing.T) { + const baseURI = "/base-uri" cfg := newFakeKeycloakConfig() - cfg.BaseURI = "/base-uri" + cfg.BaseURI = baseURI _, _, svc := newTestProxyService(cfg) @@ -52,12 +55,14 @@ func TestCookieBasePath(t *testing.T) { var cookie *http.Cookie for _, c := range resp.Cookies() { - if c.Name == "kc-access" { + if c.Name == accessCookie { cookie = c } } + defer resp.Body.Close() + assert.NotNil(t, cookie) - assert.Equal(t, "/base-uri", cookie.Path) + assert.Equal(t, baseURI, cookie.Path) } func TestCookieWithoutBasePath(t *testing.T) { @@ -71,10 +76,12 @@ func TestCookieWithoutBasePath(t *testing.T) { var cookie *http.Cookie for _, c := range resp.Cookies() { - if c.Name == "kc-access" { + if c.Name == accessCookie { cookie = c } } + defer resp.Body.Close() + assert.NotNil(t, cookie) assert.Equal(t, "/", cookie.Path) } @@ -92,6 +99,8 @@ func TestCookieDomain(t *testing.T) { cookie = c } } + defer resp.Body.Close() + assert.NotNil(t, cookie) assert.Equal(t, cookie.Domain, "domain.com") } diff --git a/e2e_test.go b/e2e_test.go index 37a6bce6e94ca48f5abaa9346a616d8c8f2670cb..a527ccc70fa194764a7675dcf43c1d7a3a64c883 100644 --- a/e2e_test.go +++ b/e2e_test.go @@ -45,10 +45,12 @@ func checkListenOrBail(endpoint string) bool { waitTime = 100 * time.Millisecond ) checkListen := http.Client{} + //nolint:bodyclose _, err := checkListen.Get(endpoint) limit := 0 for err != nil && limit < maxWaitCycles { time.Sleep(waitTime) + //nolint:bodyclose _, err = checkListen.Get(endpoint) limit++ } @@ -161,4 +163,5 @@ func TestCorsWithUpstream(t *testing.T) { // check the returned upstream response after proxying contains CORS headers assert.Equal(t, []string{"*"}, resp.Header["Access-Control-Allow-Origin"]) } + defer resp.Body.Close() } diff --git a/handlers.go b/handlers.go index bc7989a0417e7475bc094858a9bfc22f7d4419d6..0b61cd16f5e1919897ef69e99a8510a4ce073730 100644 --- a/handlers.go +++ b/handlers.go @@ -401,6 +401,7 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) { zap.Int("status", response.StatusCode), zap.String("response", fmt.Sprintf("%s", content))) } + defer response.Body.Close() } // step: should we redirect the user if redirectURL != "" { diff --git a/middleware.go b/middleware.go index fff6864e93f092bcedc3f663bf508833f6796d25..74be12c7a0394aa9659448315158c9bf5f7a825d 100644 --- a/middleware.go +++ b/middleware.go @@ -126,7 +126,7 @@ func (r *oauthProxy) authenticationMiddleware(resource *Resource) func(http.Hand next.ServeHTTP(w, req.WithContext(r.redirectToAuthorization(w, req))) return } - } else { + } else { //nolint:gocritic if err := verifyToken(r.client, user.token); err != nil { // step: if the error post verification is anything other than a token // expired error we immediately throw an access forbidden - as there is diff --git a/middleware_test.go b/middleware_test.go index 94e8f9a53f35a51dc47d03c56124a17484a3e16b..86bf2defbff75597a6bb002bdb0da0ae45f4649a 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -310,6 +310,7 @@ func (f *fakeProxy) performUserLogin(uri string) error { } } } + defer resp.Body.Close() return nil } diff --git a/oauth.go b/oauth.go index 87ab8ced7a70e63fc81d4d7d58318a6e91a773c2..9c1f8760debcb0632a2d4585a020893a2e9b310d 100644 --- a/oauth.go +++ b/oauth.go @@ -124,6 +124,7 @@ func getUserinfo(client *oauth2.Client, endpoint string, token string) (jose.Cla if err := json.Unmarshal(content, &claims); err != nil { return nil, err } + defer resp.Body.Close() return claims, nil } diff --git a/server.go b/server.go index c156a7e58b68647016b9bfc525035220e23713dd..b169579ff0b5c4074c9204bc1eb6afb9e4125628 100644 --- a/server.go +++ b/server.go @@ -296,6 +296,7 @@ func (r *oauthProxy) createForwardingProxy() error { if err := r.createUpstreamProxy(nil); err != nil { return err } + //nolint:bodyclose forwardingHandler := r.forwardProxyHandler() // set the http handler @@ -453,7 +454,7 @@ func (r *oauthProxy) createHTTPListener(config listenerConfig) (net.Listener, er if listener, err = net.Listen("unix", socket); err != nil { return nil, err } - } else { + } else { //nolint:gocritic if listener, err = net.Listen("tcp", config.listen); err != nil { return nil, err }