Skip to content

Commit e472868

Browse files
committed
Reuse installed ginkgo and use cleaner binary check
Also: * Replace golang.org/x/net/context with context * Ignore G115 numOfRoutes is never negative anyway * Ignore gosec G117 ClientSecret is not exposed to outside. * Ignore G704 URI address is not provided by user but by server-side config. * Ignore G704 SSRF via taint analysis in tests There is no user controlled input * Prefer nolint over nosec everywhere
1 parent 7ccb6cc commit e472868

18 files changed

Lines changed: 39 additions & 43 deletions

scripts/subtests/lint

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ set -o pipefail
55

66
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
77

8-
set +e
9-
golangci_lint_executable=$(which golangci-lint)
10-
set -e
11-
if [ -z "${golangci_lint_executable}" ] || [ ! -x "${golangci_lint_executable}" ]; then
8+
if ! command -v golangci-lint &> /dev/null; then
129
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
1310
fi
1411

1512
pushd "${SCRIPT_DIR}/../../src" > /dev/null
1613
golangci-lint run ./...
17-
popd > /dev/null
18-
14+
popd > /dev/null

scripts/subtests/spec-test

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ set -o pipefail
55

66
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
77

8-
set +e
9-
bundler_executable=$(which bundle)
10-
set -e
11-
if [ -z "${bundler_executable}" ] || [ ! -x "${bundler_executable}" ]; then
8+
if ! command -v bundle &> /dev/null; then
129
gem install bundler
1310
fi
1411

scripts/subtests/unit-test

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ if [ "${CI:-false}" = 'false' ]; then
1111
fi
1212

1313
pushd "${SCRIPT_DIR}/../../src" > /dev/null
14-
go run github.com/onsi/ginkgo/v2/ginkgo $flags
15-
popd > /dev/null
16-
14+
if ! command -v ginkgo &> /dev/null; then
15+
go install github.com/onsi/ginkgo/v2/ginkgo@latest
16+
fi
17+
ginkgo $flags
18+
popd > /dev/null

src/cmd/cf-auth-proxy/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type CAPI struct {
1515

1616
type UAA struct {
1717
ClientID string `env:"UAA_CLIENT_ID,"`
18-
ClientSecret string `env:"UAA_CLIENT_SECRET,"`
18+
ClientSecret string `env:"UAA_CLIENT_SECRET,"` //nolint:gosec
1919
Addr string `env:"UAA_ADDR, required, report"`
2020
CAPath string `env:"UAA_CA_PATH, report"`
2121
}

src/internal/auth/capi_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (c *CAPIClient) IsAuthorized(sourceId string, clientToken string) bool {
9696
}
9797

9898
func (c *CAPIClient) HasApp(sourceID, authToken string) bool {
99-
req, err := http.NewRequest(http.MethodGet, c.addr+"/v3/apps/"+sourceID, nil)
99+
req, err := http.NewRequest(http.MethodGet, c.addr+"/v3/apps/"+sourceID, nil) //nolint:gosec
100100
if err != nil {
101101
c.log.Printf("failed to build authorize log access request: %s", err)
102102
return false
@@ -130,7 +130,7 @@ func (c *CAPIClient) GetRelatedSourceIds(appNames []string, authToken string) ma
130130
return map[string][]string{}
131131
}
132132

133-
req, err := http.NewRequest(http.MethodGet, c.addr+"/v3/apps", nil)
133+
req, err := http.NewRequest(http.MethodGet, c.addr+"/v3/apps", nil) //nolint:gosec
134134
if err != nil {
135135
c.log.Printf("failed to build app list request: %s", err)
136136
return map[string][]string{}

src/internal/cache/log_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cache
22

33
import (
4+
"context"
45
"log"
56
"net"
67
"strconv"
@@ -9,7 +10,6 @@ import (
910

1011
metrics "code.cloudfoundry.org/go-metric-registry"
1112

12-
"golang.org/x/net/context"
1313
"google.golang.org/grpc"
1414
"google.golang.org/grpc/credentials/insecure"
1515

src/internal/cfauthproxy/cf_auth_proxy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func makeTLSReq(addr string) (*http.Response, error) {
287287
}
288288
client := &http.Client{Transport: tr}
289289

290-
return client.Do(req)
290+
return client.Do(req) //nolint:gosec
291291
}
292292

293293
func makeReq(addr string) (*http.Response, error) {
@@ -296,5 +296,5 @@ func makeReq(addr string) (*http.Response, error) {
296296

297297
client := &http.Client{}
298298

299-
return client.Do(req)
299+
return client.Do(req) //nolint:gosec
300300
}

src/internal/gateway/gateway.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gateway
22

33
import (
4+
"context"
45
"fmt"
56
"io"
67
"log"
@@ -10,7 +11,6 @@ import (
1011

1112
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
1213
"github.com/shirou/gopsutil/v4/host"
13-
"golang.org/x/net/context"
1414
"google.golang.org/grpc"
1515
"google.golang.org/grpc/status"
1616
"google.golang.org/protobuf/encoding/protojson"
@@ -187,7 +187,7 @@ func (g *Gateway) handleInfoEndpoint(w http.ResponseWriter, r *http.Request) {
187187

188188
func uptimeInSeconds() int64 {
189189
hostStats, _ := host.Info()
190-
return int64(hostStats.Uptime) //#nosec G115
190+
return int64(hostStats.Uptime) //nolint:gosec
191191
}
192192

193193
type errorBody struct {

src/internal/gateway/gateway_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func makeTLSReq(addr string) (*http.Response, error) {
226226
}
227227
client := &http.Client{Transport: tr}
228228

229-
return client.Do(req)
229+
return client.Do(req) // nolint:gosec
230230
}
231231

232232
func makeReq(addr string) (*http.Response, error) {
@@ -235,5 +235,5 @@ func makeReq(addr string) (*http.Response, error) {
235235

236236
client := &http.Client{}
237237

238-
return client.Do(req)
238+
return client.Do(req) // nolint:gosec
239239
}

src/internal/nozzle/nozzle.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package nozzle
22

33
import (
4+
"context"
45
"log"
56
"runtime"
67
"time"
@@ -11,7 +12,6 @@ import (
1112
diodes "code.cloudfoundry.org/go-diodes"
1213
"code.cloudfoundry.org/go-log-cache/v3/rpc/logcache_v1"
1314
"code.cloudfoundry.org/go-loggregator/v10/rpc/loggregator_v2"
14-
"golang.org/x/net/context"
1515
"google.golang.org/grpc"
1616
"google.golang.org/grpc/credentials/insecure"
1717
)
@@ -177,7 +177,7 @@ func (n *Nozzle) envelopeWriter(ch chan []*loggregator_v2.Envelope, client logca
177177
for {
178178
envelopes := <-ch
179179

180-
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
180+
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
181181
_, err := client.Send(ctx, &logcache_v1.SendRequest{
182182
Envelopes: &loggregator_v2.EnvelopeBatch{
183183
Batch: envelopes,
@@ -186,10 +186,12 @@ func (n *Nozzle) envelopeWriter(ch chan []*loggregator_v2.Envelope, client logca
186186

187187
if err != nil {
188188
n.errCounter.Add(1)
189+
cancel()
189190
continue
190191
}
191192

192193
n.egressCounter.Add(float64(len(envelopes)))
194+
cancel()
193195
}
194196
}
195197

0 commit comments

Comments
 (0)