Skip to content

Commit 25b4121

Browse files
committed
chore(lint): updated linting [TAU-298]
chore(deps): udpated deps test: enabled -race tests, fix: fixed race conditions in forwarding middleware NOTE: boltDB does not support race testing Signed-off-by: Frédéric BIDON <[email protected]>
1 parent 02608d7 commit 25b4121

30 files changed

+1355
-323
lines changed

.circleci/config.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ jobs:
1616
name: Run linter
1717
environment:
1818
command: |
19-
golangci-lint run --timeout 10m --new-from-rev oneconcern-release
19+
golangci-lint run --timeout 2m --new-from-rev oneconcern-release
2020
2121
test:
2222
working_directory: /go/src/github.com/oneconcern/keycloak-gatekeeper
2323
docker:
24-
- image: circleci/golang:latest
24+
- image: golang:1.19
2525
steps:
2626
- checkout
2727
- run:
2828
name: Run unit tests
29-
command: GO111MODULE=on go test -v -covermode=atomic -coverprofile=cover.out
29+
command: go test -v -race -covermode=atomic -coverprofile=cover.out
3030
no_output_timeout: 30m
3131

3232
build_image:
@@ -44,7 +44,6 @@ jobs:
4444
echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
4545
gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
4646
gcloud --quiet config set compute/region ${GOOGLE_COMPUTE_REGION}
47-
#gcloud --quiet config set container/new_scopes_behavior true
4847
gcloud --quiet container clusters get-credentials ${CLUSTER} --region ${GOOGLE_COMPUTE_REGION}
4948
- checkout
5049
- setup_remote_docker:

.golangci.yml

+40-7
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,56 @@ linters-settings:
2121

2222
linters:
2323
enable:
24-
- gofmt
25-
- goimports
24+
#- nolintlint
25+
#- unparam
2626
- bodyclose
2727
- dupl
2828
- forbidigo
2929
- gocognit
3030
- gocritic
31+
- gofmt
32+
- goimports
3133
- goimports
3234
- gosec
3335
- nakedret
34-
- nolintlint
3536
- revive
3637
- stylecheck
3738
- unconvert
38-
#- unparam
3939
disable:
40-
- maligned
41-
- lll
42-
- gochecknoinits
40+
#- gocognit
41+
- errorlint
42+
- exhaustive
43+
- exhaustivestruct
44+
- exhaustruct
45+
- funlen
46+
- gci
4347
- gochecknoglobals
48+
- gochecknoinits
49+
- gocyclo
50+
- godot
51+
- godox
52+
- goerr113
53+
- gofumpt
54+
- golint
55+
- gomnd
56+
- gomoddirectives
57+
- ifshort
58+
- interfacer
59+
- ireturn
60+
- lll
61+
- maintidx
62+
- maligned
63+
- nestif
64+
- nlreturn
65+
- nolintlint
66+
- nonamedreturns
67+
- paralleltest
68+
- scopelint
69+
- tagliatelle
70+
- testpackage
71+
- thelper
72+
- unparam
73+
- varnamelen
74+
- whitespace
75+
- wrapcheck
76+
- wsl

admin_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616
package main
1717

1818
import (
19-
"io/ioutil"
19+
"io"
2020
"log"
2121
"net/http"
2222
"net/url"
@@ -72,14 +72,14 @@ func testBuildAdminConfig() *Config {
7272
config.Resources = []*Resource{
7373
{
7474
URL: "/fake",
75-
Methods: []string{"GET", "POST", "DELETE"},
75+
Methods: []string{http.MethodGet, http.MethodPost, http.MethodDelete},
7676
WhiteListed: false,
7777
EnableCSRF: false,
7878
},
7979
}
8080
config.Resources = append(config.Resources, &Resource{
8181
URL: "/another-fake",
82-
Methods: []string{"GET", "POST", "DELETE"},
82+
Methods: []string{http.MethodGet, http.MethodPost, http.MethodDelete},
8383
WhiteListed: false,
8484
EnableCSRF: false,
8585
})
@@ -88,7 +88,7 @@ func testBuildAdminConfig() *Config {
8888
}
8989

9090
func TestAdmin(t *testing.T) {
91-
log.SetOutput(ioutil.Discard)
91+
log.SetOutput(io.Discard)
9292
config := testBuildAdminConfig()
9393
if !assert.NoError(t, config.isValid()) {
9494
t.FailNow()
@@ -127,7 +127,7 @@ func TestAdmin(t *testing.T) {
127127
h.Set("Content-Type", "application/json")
128128
h.Add("Accept", "application/json")
129129
req := &http.Request{
130-
Method: "GET",
130+
Method: http.MethodGet,
131131
URL: u,
132132
Header: h,
133133
}
@@ -139,14 +139,14 @@ func TestAdmin(t *testing.T) {
139139
}()
140140

141141
assert.Equal(t, http.StatusOK, resp.StatusCode)
142-
buf, erb := ioutil.ReadAll(resp.Body)
142+
buf, erb := io.ReadAll(resp.Body)
143143
assert.NoError(t, erb)
144144
assert.Equal(t, `{"status":"OK"}`, string(buf)) // check this is our test resource being called
145145

146146
// test prometheus metrics endpoint
147147
u, _ = url.Parse("http://" + e2eAdminEndpointListener + "/oauth/metrics")
148148
req = &http.Request{
149-
Method: "GET",
149+
Method: http.MethodGet,
150150
URL: u,
151151
Header: h,
152152
}
@@ -157,14 +157,14 @@ func TestAdmin(t *testing.T) {
157157
}
158158

159159
assert.Equal(t, http.StatusOK, resp.StatusCode)
160-
buf, erb = ioutil.ReadAll(resp.Body)
160+
buf, erb = io.ReadAll(resp.Body)
161161
assert.NoError(t, erb)
162162
assert.Contains(t, string(buf), `proxy_request_duration_seconds`)
163163

164164
// test profiling/debug endpoint
165165
u, _ = url.Parse("http://" + e2eAdminEndpointListener + debugURL + "/symbol")
166166
req = &http.Request{
167-
Method: "GET",
167+
Method: http.MethodGet,
168168
URL: u,
169169
Header: h,
170170
}
@@ -176,7 +176,7 @@ func TestAdmin(t *testing.T) {
176176
}()
177177

178178
assert.Equal(t, http.StatusOK, resp.StatusCode)
179-
buf, erb = ioutil.ReadAll(resp.Body)
179+
buf, erb = io.ReadAll(resp.Body)
180180
assert.NoError(t, erb)
181181
assert.Contains(t, string(buf), "num_symbols: 1\n")
182182

@@ -194,7 +194,7 @@ func TestAdmin(t *testing.T) {
194194
// test health status endpoint, unauthenticated
195195
u, _ = url.Parse("http://" + e2eAdminProxyListener2 + "/oauth/health")
196196
req = &http.Request{
197-
Method: "GET",
197+
Method: http.MethodGet,
198198
URL: u,
199199
Header: h,
200200
}
@@ -205,14 +205,14 @@ func TestAdmin(t *testing.T) {
205205
}()
206206

207207
assert.Equal(t, http.StatusOK, resp.StatusCode)
208-
buf, erb = ioutil.ReadAll(resp.Body)
208+
buf, erb = io.ReadAll(resp.Body)
209209
assert.NoError(t, erb)
210210
assert.Contains(t, string(buf), `OK`)
211211

212212
// test metrics
213213
u, _ = url.Parse("http://" + e2eAdminProxyListener2 + "/oauth/metrics")
214214
req = &http.Request{
215-
Method: "GET",
215+
Method: http.MethodGet,
216216
URL: u,
217217
Header: h,
218218
}
@@ -223,7 +223,7 @@ func TestAdmin(t *testing.T) {
223223
}
224224

225225
assert.Equal(t, http.StatusOK, resp.StatusCode)
226-
buf, erb = ioutil.ReadAll(resp.Body)
226+
buf, erb = io.ReadAll(resp.Body)
227227
assert.NoError(t, erb)
228228
assert.Contains(t, string(buf), `proxy_request_duration_seconds`)
229229
}

config.go

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func checkTLSVersion(config *tlsAdvancedConfig, parsed *tlsSettings) error {
199199
return nil
200200
}
201201

202+
//nolint:nosnakecase
202203
func checkTLSCipher(config *tlsAdvancedConfig, parsed *tlsSettings) error {
203204
if !config.tlsUseModernSettings && len(config.tlsCipherSuites) == 0 {
204205
return nil
@@ -249,6 +250,7 @@ func checkTLSCipher(config *tlsAdvancedConfig, parsed *tlsSettings) error {
249250
return nil
250251
}
251252

253+
//nolint:nosnakecase
252254
func parseTLSCipher(cipher string) (uint16, error) {
253255
switch cipher {
254256
case "TLS_FALLBACK_SCSV":

config_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ func TestIsConfigValid(t *testing.T) {
383383
}
384384
}
385385

386+
//nolint:nosnakecase
386387
func TestParseTLS(t *testing.T) {
387388
tlsConfigFixture := tlsAdvancedConfig{
388389
tlsPreferServerCipherSuites: true,

cors_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616
package main
1717

1818
import (
19-
"io/ioutil"
19+
"io"
2020
"log"
2121
"net/http"
2222
"net/url"
@@ -47,15 +47,15 @@ func testBuildCorsConfig() *Config {
4747
config.Resources = []*Resource{
4848
{
4949
URL: e2eCorsUpstreamURL,
50-
Methods: []string{"GET"},
50+
Methods: []string{http.MethodGet},
5151
WhiteListed: true,
5252
},
5353
}
5454
return config
5555
}
5656

5757
func TestCorsWithUpstream(t *testing.T) {
58-
log.SetOutput(ioutil.Discard)
58+
log.SetOutput(io.Discard)
5959

6060
config := testBuildCorsConfig()
6161

@@ -76,7 +76,7 @@ func TestCorsWithUpstream(t *testing.T) {
7676
h.Add("Origin", "myorigin.com")
7777

7878
resp, err := client.Do(&http.Request{
79-
Method: "GET",
79+
Method: http.MethodGet,
8080
URL: u,
8181
Header: h,
8282
})
@@ -85,7 +85,7 @@ func TestCorsWithUpstream(t *testing.T) {
8585
_ = resp.Body.Close()
8686
}()
8787

88-
buf, erb := ioutil.ReadAll(resp.Body)
88+
buf, erb := io.ReadAll(resp.Body)
8989
assert.NoError(t, erb)
9090
assert.Contains(t, string(buf), `"message": "test"`) // check this is our test resource
9191
if assert.NotEmpty(t, resp.Header) && assert.Contains(t, resp.Header, "Access-Control-Allow-Origin") {

csrf_test.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"errors"
2020
"fmt"
2121
"io"
22-
"io/ioutil"
2322
"net/http"
2423
"net/url"
2524
"path"
@@ -163,7 +162,7 @@ func getUpstreamTest(t *testing.T, config *Config, cookies []*http.Cookie, expec
163162
h := make(http.Header, 10)
164163
h.Set("Content-Type", "application/json")
165164
req := &http.Request{
166-
Method: "GET",
165+
Method: http.MethodGet,
167166
URL: u,
168167
Header: h,
169168
}
@@ -173,7 +172,7 @@ func getUpstreamTest(t *testing.T, config *Config, cookies []*http.Cookie, expec
173172

174173
assert.NoError(t, err)
175174
assert.Equal(t, http.StatusOK, resp.StatusCode)
176-
buf, erb := ioutil.ReadAll(resp.Body)
175+
buf, erb := io.ReadAll(resp.Body)
177176
assert.NoError(t, erb)
178177
assert.JSONEq(t, `{"message":"test"}`, string(buf)) // check this is our test resource being called
179178

@@ -224,7 +223,7 @@ func getTokenTest(t *testing.T, config *Config, cookies []*http.Cookie, expectCS
224223
h := make(http.Header, 10)
225224
h.Set("Content-Type", "application/json")
226225
req := &http.Request{
227-
Method: "GET",
226+
Method: http.MethodGet,
228227
URL: u,
229228
Header: h,
230229
}
@@ -234,7 +233,7 @@ func getTokenTest(t *testing.T, config *Config, cookies []*http.Cookie, expectCS
234233

235234
assert.NoError(t, err)
236235
assert.Equal(t, http.StatusOK, resp.StatusCode)
237-
buf, erb := ioutil.ReadAll(resp.Body)
236+
buf, erb := io.ReadAll(resp.Body)
238237
assert.NoError(t, erb)
239238
assert.NotEmpty(t, buf)
240239

@@ -274,7 +273,7 @@ func postUpstreamTest(t *testing.T, config *Config, cookies []*http.Cookie, csrf
274273
h.Set("Content-Type", "application/json")
275274
h.Add(config.CSRFHeader, csrfToken)
276275
req := &http.Request{
277-
Method: "POST",
276+
Method: http.MethodPost,
278277
URL: u,
279278
Header: h,
280279
}
@@ -287,7 +286,7 @@ func postUpstreamTest(t *testing.T, config *Config, cookies []*http.Cookie, csrf
287286
var csrfNewToken string
288287
if !expectedFailure {
289288
assert.Equal(t, http.StatusOK, resp.StatusCode)
290-
buf, erb := ioutil.ReadAll(resp.Body)
289+
buf, erb := io.ReadAll(resp.Body)
291290

292291
// checking response to POST
293292
assert.NoError(t, erb)
@@ -317,7 +316,7 @@ func postUpstreamWithAccessTokenTest(t *testing.T, config *Config, cookies []*ht
317316
h.Set("Content-Type", "application/json")
318317
h.Add("Authorization", "Bearer "+accessToken)
319318
req := &http.Request{
320-
Method: "POST",
319+
Method: http.MethodPost,
321320
URL: u,
322321
Header: h,
323322
}
@@ -329,7 +328,7 @@ func postUpstreamWithAccessTokenTest(t *testing.T, config *Config, cookies []*ht
329328

330329
var csrfNewToken string
331330
assert.Equal(t, http.StatusOK, resp.StatusCode)
332-
buf, erb := ioutil.ReadAll(resp.Body)
331+
buf, erb := io.ReadAll(resp.Body)
333332

334333
// checking response to POST
335334
assert.NoError(t, erb)
@@ -351,7 +350,7 @@ func postUpstream2Test(t *testing.T, config *Config, cookies []*http.Cookie) (st
351350
h := make(http.Header, 10)
352351
h.Set("Content-Type", "application/json")
353352
req := &http.Request{
354-
Method: "POST",
353+
Method: http.MethodPost,
355354
URL: u,
356355
Header: h,
357356
}
@@ -363,7 +362,7 @@ func postUpstream2Test(t *testing.T, config *Config, cookies []*http.Cookie) (st
363362

364363
var csrfNewToken string
365364
assert.Equal(t, http.StatusOK, resp.StatusCode)
366-
buf, erb := ioutil.ReadAll(resp.Body)
365+
buf, erb := io.ReadAll(resp.Body)
367366

368367
// checking response to POST
369368
assert.NoError(t, erb)
@@ -404,7 +403,7 @@ func TestCSRF(t *testing.T) {
404403
config.Resources = []*Resource{
405404
{
406405
URL: e2eCsrfUpstreamURL2,
407-
Methods: []string{"GET", "POST", "DELETE"},
406+
Methods: []string{http.MethodGet, http.MethodPost, http.MethodDelete},
408407
WhiteListed: false,
409408
EnableCSRF: false,
410409
},
@@ -416,7 +415,7 @@ func TestCSRF(t *testing.T) {
416415

417416
config.Resources = append(config.Resources, &Resource{
418417
URL: e2eCsrfUpstreamURL,
419-
Methods: []string{"GET", "POST", "DELETE"},
418+
Methods: []string{http.MethodGet, http.MethodPost, http.MethodDelete},
420419
WhiteListed: false,
421420
EnableCSRF: true,
422421
})

0 commit comments

Comments
 (0)