Skip to content

Commit

Permalink
Merge pull request #82 from silinternational/golangci-lint
Browse files Browse the repository at this point in the history
run more checks in golangci-lint
  • Loading branch information
briskt authored Oct 29, 2024
2 parents ccaff48 + a72cd31 commit b5bb72f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
19 changes: 19 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
run:
timeout: 2m
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- bodyclose
- exhaustive
- gocheckcompilerdirectives
- godox
- gofmt
- goimports
- gosec
- whitespace
- usestdlibvars
2 changes: 1 addition & 1 deletion functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func sendRequest(url string, c *http.Cookie) error {
func weSendARequestWithAuthorizationDataAuthorizingAccess(where, level string) error {
var c *http.Cookie
url := p.Host
expires := time.Now().Add(1000 + time.Second*time.Duration(rand.Intn(1000)))
expires := time.Now().Add(1000 + time.Second*time.Duration(rand.Intn(1000))) // #nosec G404 weak random number is OK
token := makeTestJWT(p.Secret, level, expires)

if where == "cookie" {
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (p Proxy) getNewToken(w http.ResponseWriter, r *http.Request) error {

func (p Proxy) getTokenFromAPI(ipAddress string) string {
client := &http.Client{Timeout: time.Second * 10}
req, err := http.NewRequest("GET", p.ManagementAPI+p.TokenPath, nil)
req, err := http.NewRequest(http.MethodGet, p.ManagementAPI+p.TokenPath, nil)
if err != nil {
p.log.Error("error creating management API request", zap.Error(err))
return ""
Expand All @@ -356,6 +356,7 @@ func (p Proxy) getTokenFromAPI(ipAddress string) string {
return ""
}

defer resp.Body.Close()
token, err := io.ReadAll(resp.Body)
if err != nil {
p.log.Error("failed to read management API response", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func Test_AuthProxy(t *testing.T) {
const managementAPI = "http://management_api.example.com"
const tokenPath = "/auth/token"
const tokenPath = "/auth/token" // #nosec G101 this is not a hardcoded credential

cookieName := "_test"
tokenSecret := []byte("secret")
Expand Down

0 comments on commit b5bb72f

Please sign in to comment.