Skip to content
Snippets Groups Projects
Commit 4023a75c authored by Bruno Oliveira da Silva's avatar Bruno Oliveira da Silva
Browse files

[KEYCLOAK-11183] Fix linting errors reported by GolangCI on Gatekeeper

 - Replace gometalinter by golangci-lint in the Makefile
 - Fix linting errors reported by golangci-lint
parent d8745344
No related branches found
No related tags found
No related merge requests found
...@@ -97,9 +97,9 @@ vet: ...@@ -97,9 +97,9 @@ vet:
fi fi
lint: lint:
@echo "--> Running golint" @echo "--> Running golangci-lint"
@which golint 2>/dev/null ; if [ $$? -eq 1 ]; then \ @which golangci-lint 2>/dev/null ; if [ $$? -eq 1 ]; then \
go get -u github.com/golang/lint/golint; \ go get -u github.com/golangci/golangci-lint/cmd/golangci-lint; \
fi fi
@golint . @golint .
...@@ -114,7 +114,7 @@ gofmt: ...@@ -114,7 +114,7 @@ gofmt:
verify: verify:
@echo "--> Verifying the code" @echo "--> Verifying the code"
gometalinter --disable=errcheck --disable=gocyclo --disable=gas --disable=aligncheck --errors golangci-lint run
format: format:
@echo "--> Running go fmt" @echo "--> Running go fmt"
......
...@@ -36,13 +36,16 @@ func TestCookieDomainHostHeader(t *testing.T) { ...@@ -36,13 +36,16 @@ func TestCookieDomainHostHeader(t *testing.T) {
cookie = c cookie = c
} }
} }
defer resp.Body.Close()
assert.NotNil(t, cookie) assert.NotNil(t, cookie)
assert.Equal(t, cookie.Domain, "127.0.0.1") assert.Equal(t, cookie.Domain, "127.0.0.1")
} }
func TestCookieBasePath(t *testing.T) { func TestCookieBasePath(t *testing.T) {
const baseURI = "/base-uri"
cfg := newFakeKeycloakConfig() cfg := newFakeKeycloakConfig()
cfg.BaseURI = "/base-uri" cfg.BaseURI = baseURI
_, _, svc := newTestProxyService(cfg) _, _, svc := newTestProxyService(cfg)
...@@ -52,12 +55,14 @@ func TestCookieBasePath(t *testing.T) { ...@@ -52,12 +55,14 @@ func TestCookieBasePath(t *testing.T) {
var cookie *http.Cookie var cookie *http.Cookie
for _, c := range resp.Cookies() { for _, c := range resp.Cookies() {
if c.Name == "kc-access" { if c.Name == accessCookie {
cookie = c cookie = c
} }
} }
defer resp.Body.Close()
assert.NotNil(t, cookie) assert.NotNil(t, cookie)
assert.Equal(t, "/base-uri", cookie.Path) assert.Equal(t, baseURI, cookie.Path)
} }
func TestCookieWithoutBasePath(t *testing.T) { func TestCookieWithoutBasePath(t *testing.T) {
...@@ -71,10 +76,12 @@ func TestCookieWithoutBasePath(t *testing.T) { ...@@ -71,10 +76,12 @@ func TestCookieWithoutBasePath(t *testing.T) {
var cookie *http.Cookie var cookie *http.Cookie
for _, c := range resp.Cookies() { for _, c := range resp.Cookies() {
if c.Name == "kc-access" { if c.Name == accessCookie {
cookie = c cookie = c
} }
} }
defer resp.Body.Close()
assert.NotNil(t, cookie) assert.NotNil(t, cookie)
assert.Equal(t, "/", cookie.Path) assert.Equal(t, "/", cookie.Path)
} }
...@@ -92,6 +99,8 @@ func TestCookieDomain(t *testing.T) { ...@@ -92,6 +99,8 @@ func TestCookieDomain(t *testing.T) {
cookie = c cookie = c
} }
} }
defer resp.Body.Close()
assert.NotNil(t, cookie) assert.NotNil(t, cookie)
assert.Equal(t, cookie.Domain, "domain.com") assert.Equal(t, cookie.Domain, "domain.com")
} }
......
...@@ -45,10 +45,12 @@ func checkListenOrBail(endpoint string) bool { ...@@ -45,10 +45,12 @@ func checkListenOrBail(endpoint string) bool {
waitTime = 100 * time.Millisecond waitTime = 100 * time.Millisecond
) )
checkListen := http.Client{} checkListen := http.Client{}
//nolint:bodyclose
_, err := checkListen.Get(endpoint) _, err := checkListen.Get(endpoint)
limit := 0 limit := 0
for err != nil && limit < maxWaitCycles { for err != nil && limit < maxWaitCycles {
time.Sleep(waitTime) time.Sleep(waitTime)
//nolint:bodyclose
_, err = checkListen.Get(endpoint) _, err = checkListen.Get(endpoint)
limit++ limit++
} }
...@@ -161,4 +163,5 @@ func TestCorsWithUpstream(t *testing.T) { ...@@ -161,4 +163,5 @@ func TestCorsWithUpstream(t *testing.T) {
// check the returned upstream response after proxying contains CORS headers // check the returned upstream response after proxying contains CORS headers
assert.Equal(t, []string{"*"}, resp.Header["Access-Control-Allow-Origin"]) assert.Equal(t, []string{"*"}, resp.Header["Access-Control-Allow-Origin"])
} }
defer resp.Body.Close()
} }
...@@ -401,6 +401,7 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) { ...@@ -401,6 +401,7 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) {
zap.Int("status", response.StatusCode), zap.Int("status", response.StatusCode),
zap.String("response", fmt.Sprintf("%s", content))) zap.String("response", fmt.Sprintf("%s", content)))
} }
defer response.Body.Close()
} }
// step: should we redirect the user // step: should we redirect the user
if redirectURL != "" { if redirectURL != "" {
......
...@@ -126,7 +126,7 @@ func (r *oauthProxy) authenticationMiddleware(resource *Resource) func(http.Hand ...@@ -126,7 +126,7 @@ func (r *oauthProxy) authenticationMiddleware(resource *Resource) func(http.Hand
next.ServeHTTP(w, req.WithContext(r.redirectToAuthorization(w, req))) next.ServeHTTP(w, req.WithContext(r.redirectToAuthorization(w, req)))
return return
} }
} else { } else { //nolint:gocritic
if err := verifyToken(r.client, user.token); err != nil { if err := verifyToken(r.client, user.token); err != nil {
// step: if the error post verification is anything other than a token // step: if the error post verification is anything other than a token
// expired error we immediately throw an access forbidden - as there is // expired error we immediately throw an access forbidden - as there is
......
...@@ -310,6 +310,7 @@ func (f *fakeProxy) performUserLogin(uri string) error { ...@@ -310,6 +310,7 @@ func (f *fakeProxy) performUserLogin(uri string) error {
} }
} }
} }
defer resp.Body.Close()
return nil return nil
} }
......
...@@ -124,6 +124,7 @@ func getUserinfo(client *oauth2.Client, endpoint string, token string) (jose.Cla ...@@ -124,6 +124,7 @@ func getUserinfo(client *oauth2.Client, endpoint string, token string) (jose.Cla
if err := json.Unmarshal(content, &claims); err != nil { if err := json.Unmarshal(content, &claims); err != nil {
return nil, err return nil, err
} }
defer resp.Body.Close()
return claims, nil return claims, nil
} }
......
...@@ -296,6 +296,7 @@ func (r *oauthProxy) createForwardingProxy() error { ...@@ -296,6 +296,7 @@ func (r *oauthProxy) createForwardingProxy() error {
if err := r.createUpstreamProxy(nil); err != nil { if err := r.createUpstreamProxy(nil); err != nil {
return err return err
} }
//nolint:bodyclose
forwardingHandler := r.forwardProxyHandler() forwardingHandler := r.forwardProxyHandler()
// set the http handler // set the http handler
...@@ -453,7 +454,7 @@ func (r *oauthProxy) createHTTPListener(config listenerConfig) (net.Listener, er ...@@ -453,7 +454,7 @@ func (r *oauthProxy) createHTTPListener(config listenerConfig) (net.Listener, er
if listener, err = net.Listen("unix", socket); err != nil { if listener, err = net.Listen("unix", socket); err != nil {
return nil, err return nil, err
} }
} else { } else { //nolint:gocritic
if listener, err = net.Listen("tcp", config.listen); err != nil { if listener, err = net.Listen("tcp", config.listen); err != nil {
return nil, err return nil, err
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment