diff --git a/Gemfile b/Gemfile index ef25cc20..657780f0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,13 @@ # frozen_string_literal: true source 'https://rubygems.org' -ruby '~> 3.2.0' +ruby '~> 3.3.0' gem 'bosh-template' gem 'guard-rspec' gem 'rake' gem 'rspec' gem 'rspec-its' -gem 'rubocop' +gem 'rubocop', '>=1.52.1' gem 'rubocop-rake' gem 'rubocop-rspec' diff --git a/Gemfile.lock b/Gemfile.lock index 18b7c917..4ba0a516 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,7 +22,8 @@ GEM guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) - json (2.6.2) + json (2.8.2) + language_server-protocol (3.17.0.3) listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -32,19 +33,20 @@ GEM notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) - parallel (1.22.1) - parser (3.1.2.1) + parallel (1.26.3) + parser (3.3.6.0) ast (~> 2.4.1) + racc pry (0.14.1) coderay (~> 1.1) method_source (~> 1.0) + racc (1.8.1) rainbow (3.1.1) rake (13.0.6) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - regexp_parser (2.6.0) - rexml (3.2.5) + regexp_parser (2.9.2) rspec (3.11.0) rspec-core (~> 3.11.0) rspec-expectations (~> 3.11.0) @@ -61,31 +63,32 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-support (3.11.1) - rubocop (1.36.0) + rubocop (1.68.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.20.1, < 2.0) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.22.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.36.1) + parser (>= 3.3.1.0) rubocop-rake (0.6.0) rubocop (~> 1.0) rubocop-rspec (2.13.2) rubocop (~> 1.33) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) semi_semantic (1.2.0) shellany (0.0.1) thor (1.2.1) - unicode-display_width (2.3.0) + unicode-display_width (2.6.0) PLATFORMS universal-darwin-22 x86_64-darwin-21 + x86_64-linux DEPENDENCIES bosh-template @@ -93,12 +96,12 @@ DEPENDENCIES rake rspec rspec-its - rubocop + rubocop (>= 1.52.1) rubocop-rake rubocop-rspec RUBY VERSION - ruby 3.2.2p53 + ruby 3.3.6p108 BUNDLED WITH 2.3.22 diff --git a/acceptance-tests/go.mod b/acceptance-tests/go.mod index d9efde4e..c975b39f 100644 --- a/acceptance-tests/go.mod +++ b/acceptance-tests/go.mod @@ -1,6 +1,8 @@ module acceptance_tests -go 1.20 +go 1.22 + +toolchain go1.22.3 require ( github.com/bramvdbogaerde/go-scp v1.5.0 diff --git a/acceptance-tests/go.sum b/acceptance-tests/go.sum index 6b03e7fb..8a80d214 100644 --- a/acceptance-tests/go.sum +++ b/acceptance-tests/go.sum @@ -1,6 +1,7 @@ github.com/bramvdbogaerde/go-scp v1.5.0 h1:a9BinAjTfQh273eh7vd3qUgmBC+bx+3TRDtkZWmIpzM= github.com/bramvdbogaerde/go-scp v1.5.0/go.mod h1:on2aH5AxaFb2G0N5Vsdy6B0Ml7k9HuHSwfo1y0QzAbQ= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= @@ -14,7 +15,9 @@ github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5co github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= @@ -24,11 +27,13 @@ golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= +golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/src/pcap/.golangci.yml b/src/pcap/.golangci.yml index 12e4b8b3..c04f189c 100644 --- a/src/pcap/.golangci.yml +++ b/src/pcap/.golangci.yml @@ -84,7 +84,7 @@ linters-settings: # Default: true skipRecvDeref: false - gomnd: + mnd: # List of function patterns to exclude from analysis. # Values always ignored: `time.Date`, # `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`, @@ -184,9 +184,8 @@ linters: - durationcheck # checks for two durations multiplied together - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 - - execinquery # checks query string in Query function which reads your Go src files and warning it finds - exhaustive # checks exhaustiveness of enum switch statements - - exportloopref # checks for pointers to enclosing loop variables + - copyloopvar # checks for pointers to enclosing loop variables - forbidigo # forbids identifiers - funlen # tool for detection of long functions - gci # controls golang package import order and makes it always deterministic @@ -197,7 +196,7 @@ linters: - godot # checks if comments end in a period - gofmt # checks whether code was gofmt-ed - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt - - gomnd # detects magic numbers + - mnd # detects magic numbers - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod - gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations - goprintffuncname # checks that printf-like functions are named with f at the end diff --git a/src/pcap/agent.go b/src/pcap/agent.go index 554fb023..fd5a9445 100644 --- a/src/pcap/agent.go +++ b/src/pcap/agent.go @@ -115,7 +115,7 @@ func (a *Agent) Capture(stream Agent_CaptureServer) (err error) { return errorf(codes.InvalidArgument, "%w", err) } - opts := req.Payload.(*AgentRequest_Start).Start.Capture + opts := req.Payload.(*AgentRequest_Start).Start.Capture //nolint:errcheck //this only returns one value log.Info("starting capture", zap.String("device", opts.Device), zap.Uint32("snapLen", opts.SnapLen), zap.String("filter", opts.Filter)) handle, err := openHandle(opts) @@ -196,7 +196,7 @@ func validateAgentStartRequest(req *AgentRequest) error { // openHandle is a helper function to open the packet capturing handle that reads from the // network interface and returns the data. Puts the network interface into promiscuous mode. func openHandle(opts *CaptureOptions) (*pcap.Handle, error) { - handle, err := pcap.OpenLive(opts.Device, int32(opts.SnapLen), true, readPacketTimeout) + handle, err := pcap.OpenLive(opts.Device, int32(opts.SnapLen), true, readPacketTimeout) //nolint:gosec //size in relation to packets, well within int32 if err != nil { return nil, errorf(codes.Internal, "open handle: %w", err) } diff --git a/src/pcap/api_test.go b/src/pcap/api_test.go index 25962803..127fbdf6 100644 --- a/src/pcap/api_test.go +++ b/src/pcap/api_test.go @@ -306,7 +306,7 @@ func TestCapture(t *testing.T) { t.Errorf("capture() unexpected error during api creation: %v", err) } - var connectToTargetFn = func(ctx context.Context, req *CaptureOptions, target AgentEndpoint, creds credentials.TransportCredentials, log *zap.Logger) (captureStream, error) { + var connectToTargetFn = func(ctx context.Context, req *CaptureOptions, target AgentEndpoint, creds credentials.TransportCredentials, log *zap.Logger) (captureStream, error) { //nolint:revive //keep vars even if unused for better context return tt.stream, tt.err } diff --git a/src/pcap/bosh.go b/src/pcap/bosh.go index a9d5dd28..53e54ade 100644 --- a/src/pcap/bosh.go +++ b/src/pcap/bosh.go @@ -221,7 +221,7 @@ func (br *BoshResolver) Validate(endpointRequest *EndpointRequest) error { func (br *BoshResolver) setup() error { br.logger.Debug("setting up BoshResolver", zap.Any("resolver-config", br.Config)) - timeout := 500 * time.Millisecond //nolint:gomnd // reasonable value. + timeout := 500 * time.Millisecond //nolint:mnd // reasonable value. br.client = &http.Client{ Transport: &http.Transport{ @@ -385,7 +385,7 @@ func (br *BoshResolver) verifyJWT(tokenString string) error { scopes, ok := claims["scope"].([]interface{}) if ok { for _, scope := range scopes { - if scope.(string) == br.Config.TokenScope { + if scope.(string) == br.Config.TokenScope { //nolint:errcheck //fine to panic if not string return nil } } @@ -406,7 +406,7 @@ func (br *BoshResolver) parseKey(token *jwt.Token) (interface{}, error) { return nil, fmt.Errorf("header 'jku' missing from token, cannot verify signature: %w", ErrTokenUnsupported) } - jkuURL, err := url.Parse(jku.(string)) + jkuURL, err := url.Parse(jku.(string)) //nolint:errcheck //fine to panic if not string if err != nil { return nil, err } diff --git a/src/pcap/client.go b/src/pcap/client.go index 411aa7d0..e66a4bb7 100644 --- a/src/pcap/client.go +++ b/src/pcap/client.go @@ -313,7 +313,7 @@ func (c *Client) logProgress(ctx context.Context, logger *zap.Logger) { logger.Debug("could not inspect output file", zap.Error(err)) return } - logger.Debug(fmt.Sprintf("%s bytes written to disk (total).", bytefmt.ByteSize(uint64(info.Size())))) + logger.Debug(fmt.Sprintf("%s bytes written to disk (total).", bytefmt.ByteSize(uint64(info.Size())))) //nolint:gosec //file size is non negative case <-ctx.Done(): return } diff --git a/src/pcap/cmd/pcap-agent/config.go b/src/pcap/cmd/pcap-agent/config.go index 337c8edc..bd406e0a 100644 --- a/src/pcap/cmd/pcap-agent/config.go +++ b/src/pcap/cmd/pcap-agent/config.go @@ -12,11 +12,11 @@ import ( var DefaultConfig = Config{ pcap.NodeConfig{ - Listen: pcap.Listen{Port: 9494}, //nolint:gomnd // default value used for testing + Listen: pcap.Listen{Port: 9494}, //nolint:mnd // default value used for testing Buffer: pcap.BufferConf{ - Size: 1000, //nolint:gomnd // default value used for testing - UpperLimit: 995, //nolint:gomnd // default value used for testing - LowerLimit: 900, //nolint:gomnd // default value used for testing + Size: 1000, //nolint:mnd // default value used for testing + UpperLimit: 995, //nolint:mnd // default value used for testing + LowerLimit: 900, //nolint:mnd // default value used for testing }, LogLevel: "debug", ID: "test-agent", diff --git a/src/pcap/cmd/pcap-agent/main.go b/src/pcap/cmd/pcap-agent/main.go index ff2ed292..06c831ac 100644 --- a/src/pcap/cmd/pcap-agent/main.go +++ b/src/pcap/cmd/pcap-agent/main.go @@ -35,7 +35,7 @@ func main() { switch len(os.Args) { case 1: config = DefaultConfig - case 2: //nolint:gomnd // two arguments mean parse the config. + case 2: //nolint:mnd // two arguments mean parse the config. config, err = parseConfig(os.Args[1]) default: err = fmt.Errorf("invalid number of arguments, expected 1 or 2 but got %d", len(os.Args)) diff --git a/src/pcap/cmd/pcap-api/config.go b/src/pcap/cmd/pcap-api/config.go index 6bfe586f..b34f41ef 100644 --- a/src/pcap/cmd/pcap-api/config.go +++ b/src/pcap/cmd/pcap-api/config.go @@ -13,18 +13,18 @@ import ( var DefaultAPIConfig = APIConfig{ NodeConfig: pcap.NodeConfig{ - Listen: pcap.Listen{Port: 8080}, //nolint:gomnd // default port + Listen: pcap.Listen{Port: 8080}, //nolint:mnd // default port Buffer: pcap.BufferConf{ - Size: 100, //nolint:gomnd // default size - UpperLimit: 95, //nolint:gomnd // default size - LowerLimit: 60, //nolint:gomnd // default size + Size: 100, //nolint:mnd // default size + UpperLimit: 95, //nolint:mnd // default size + LowerLimit: 60, //nolint:mnd // default size }, LogLevel: "debug", ID: "test-api", }, AgentsMTLS: nil, - DrainTimeout: 10 * time.Second, //nolint:gomnd // default configuration - ConcurrentCaptures: 5, //nolint:gomnd // default configuration + DrainTimeout: 10 * time.Second, //nolint:mnd // default configuration + ConcurrentCaptures: 5, //nolint:mnd // default configuration } type APIConfig struct { diff --git a/src/pcap/cmd/pcap-api/main.go b/src/pcap/cmd/pcap-api/main.go index 84892267..68430fe5 100644 --- a/src/pcap/cmd/pcap-api/main.go +++ b/src/pcap/cmd/pcap-api/main.go @@ -36,7 +36,7 @@ func main() { switch len(os.Args) { case 1: config = DefaultAPIConfig - case 2: //nolint:gomnd // two arguments mean parse the config. + case 2: //nolint:mnd // two arguments mean parse the config. config, err = parseAPIConfig(os.Args[1]) default: err = fmt.Errorf("invalid number of arguments, expected 1 or 2 but got %d", len(os.Args)) diff --git a/src/pcap/cmd/pcap-bosh-cli/main.go b/src/pcap/cmd/pcap-bosh-cli/main.go index c9c652b8..962438db 100644 --- a/src/pcap/cmd/pcap-bosh-cli/main.go +++ b/src/pcap/cmd/pcap-bosh-cli/main.go @@ -46,7 +46,7 @@ type options struct { BoshEnvironment string `short:"e" long:"bosh-environment" description:"The BOSH environment to use for retrieving the BOSH UAA token from the BOSH config file" env:"BOSH_ENVIRONMENT" required:"true"` Deployment string `short:"d" long:"deployment" description:"The name of the deployment in which you would like to capture." required:"true"` InstanceGroups []string `short:"g" long:"instance-group" description:"The name of an instance group in the deployment in which you would like to capture. Can be defined multiple times." required:"true"` - InstanceIds []string `positional-arg-name:"ids" description:"The instance IDs of the deployment to capture." required:"false"` + InstanceIds []string `positional-arg-name:"ids" description:"The instance IDs of the deployment to capture." required:"false"` //nolint:revive //keep InstanceIds name (not IDs) SnapLength uint16 `short:"l" long:"snaplen" description:"Snap Length, defining the captured length of the packet, with the remainder truncated. The real packet length is recorded." default:"65535"` Verbose bool `short:"v" long:"verbose" description:"Show verbose debug information"` Insecure bool `short:"k" long:"insecure" description:"Allow insecure server connections" required:"false"` @@ -433,7 +433,7 @@ func (e *Environment) setup() error { return nil } logger.Info("using TLS-encrypted connection to bosh-director", zap.String("bosh-director-url", e.DirectorURL.String())) - transport := http.DefaultTransport.(*http.Transport).Clone() + transport := http.DefaultTransport.(*http.Transport).Clone() //nolint:errcheck //Clone returns only one value if e.CaCert != "" { boshCA := x509.NewCertPool() diff --git a/src/pcap/cmd/pcap-bosh-cli/main_test.go b/src/pcap/cmd/pcap-bosh-cli/main_test.go index 3ca2480f..b556dff8 100644 --- a/src/pcap/cmd/pcap-bosh-cli/main_test.go +++ b/src/pcap/cmd/pcap-bosh-cli/main_test.go @@ -63,7 +63,7 @@ func TestParseAPIURL(t *testing.T) { func TestEnvironment_Connect(t *testing.T) { mux := http.NewServeMux() - mux.HandleFunc("/info", func(writer http.ResponseWriter, request *http.Request) { + mux.HandleFunc("/info", func(writer http.ResponseWriter, _ *http.Request) { info := pcap.BoshInfo{} info.UserAuthentication.Type = BoshAuthTypeUAA info.UserAuthentication.Options.URL = "https://uaa.fakebosh.com" diff --git a/src/pcap/devtools/pcap-agent-cli/main.go b/src/pcap/devtools/pcap-agent-cli/main.go index 9f9d7ade..bf689064 100644 --- a/src/pcap/devtools/pcap-agent-cli/main.go +++ b/src/pcap/devtools/pcap-agent-cli/main.go @@ -70,7 +70,7 @@ func main() { Capture: &pcap.CaptureOptions{ Device: "en0", Filter: "", - SnapLen: 65000, //nolint:gomnd // default value used for testing + SnapLen: 65000, //nolint:mnd // default value used for testing }, }, }, @@ -80,7 +80,7 @@ func main() { return } - devtools.ReadN(10, stream) //nolint:gomnd // default value used for testing + devtools.ReadN(10, stream) //nolint:mnd // default value used for testing err = stream.Send(&pcap.AgentRequest{ Payload: &pcap.AgentRequest_Stop{}, @@ -90,5 +90,5 @@ func main() { return } - devtools.ReadN(10_000, stream) //nolint:gomnd // default value used for testing + devtools.ReadN(10_000, stream) //nolint:mnd // default value used for testing } diff --git a/src/pcap/devtools/pcap-api-cli/main.go b/src/pcap/devtools/pcap-api-cli/main.go index 249790c9..36a5d391 100644 --- a/src/pcap/devtools/pcap-api-cli/main.go +++ b/src/pcap/devtools/pcap-api-cli/main.go @@ -74,7 +74,7 @@ func main() { Options: &pcap.CaptureOptions{ Device: "en0", Filter: "", - SnapLen: 65000, //nolint:gomnd // default value used for testing + SnapLen: 65000, //nolint:mnd // default value used for testing }, }, }, @@ -88,8 +88,8 @@ func main() { // keep receiving some data long enough to start a manual drain for i := 0; i < 10000; i++ { - devtools.ReadN(1000, stream) //nolint:gomnd // default value used for testing - time.Sleep(200 * time.Millisecond) //nolint:gomnd // default value used for testing + devtools.ReadN(1000, stream) //nolint:mnd // default value used for testing + time.Sleep(200 * time.Millisecond) //nolint:mnd // default value used for testing } err = stream.Send(pcap.MakeStopRequest()) @@ -98,5 +98,5 @@ func main() { return } - devtools.ReadN(10_000, stream) //nolint:gomnd // default value used for testing + devtools.ReadN(10_000, stream) //nolint:mnd // default value used for testing } diff --git a/src/pcap/pcap.go b/src/pcap/pcap.go index 84a31745..814cd4ef 100644 --- a/src/pcap/pcap.go +++ b/src/pcap/pcap.go @@ -74,7 +74,7 @@ func newPacketResponse(data []byte, captureInfo gopacket.CaptureInfo) *CaptureRe Packet: &Packet{ Data: data, Timestamp: timestamppb.New(captureInfo.Timestamp), - Length: int32(captureInfo.Length), + Length: int32(captureInfo.Length), //nolint:gosec //this is a size of network packet, well within int32 }, }, } diff --git a/src/pcap/test/bosh_test.go b/src/pcap/test/bosh_test.go index 6b5d2b06..8effe9ec 100644 --- a/src/pcap/test/bosh_test.go +++ b/src/pcap/test/bosh_test.go @@ -74,7 +74,7 @@ func TestNewBoshResolver(t *testing.T) { func TestAuthenticate(t *testing.T) { bar, _, _, err := mock.NewResolverWithMockBoshAPI(nil) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } validToken, err := mock.GetValidToken(bar.UaaURLs[0]) diff --git a/src/pcap/test/integration/agent_api_client.go b/src/pcap/test/integration/agent_api_client.go index 94050869..65c52069 100644 --- a/src/pcap/test/integration/agent_api_client.go +++ b/src/pcap/test/integration/agent_api_client.go @@ -1,4 +1,4 @@ -//nolint:gomnd // These tests include a lot of magic numbers that are part of the test scenarios. +//nolint:mnd // These tests include a lot of magic numbers that are part of the test scenarios. package integration import ( @@ -59,13 +59,13 @@ var _ = Describe("Using LocalResolver", func() { agentServer2, agentTarget2, _ = createAgent(9494, agentID2, nil) targets = append(targets, agentTarget2) - apiBuffConf := pcap.BufferConf{Size: 200, UpperLimit: 198, LowerLimit: 180} //nolint:gomnd // Values for a test + apiBuffConf := pcap.BufferConf{Size: 200, UpperLimit: 198, LowerLimit: 180} //nolint:mnd // Values for a test apiClient, apiServer, api, _ = createAPIwithLocalResolver(targets, apiBuffConf, nil, apiID) defaultOptions = &pcap.CaptureOptions{ Device: loopback, Filter: "", - SnapLen: 65000, //nolint:gomnd // Value for a test + SnapLen: 65000, //nolint:mnd // Value for a test } }) diff --git a/src/pcap/test/integration/bosh_resolver.go b/src/pcap/test/integration/bosh_resolver.go index a50cd055..9b568172 100644 --- a/src/pcap/test/integration/bosh_resolver.go +++ b/src/pcap/test/integration/bosh_resolver.go @@ -1,4 +1,4 @@ -//nolint:gomnd // These tests include a lot of magic numbers that are part of the test scenarios. +//nolint:mnd // These tests include a lot of magic numbers that are part of the test scenarios. package integration import ( diff --git a/src/pcap/test/integration/ginkgo_integration_test.go b/src/pcap/test/integration/ginkgo_integration_test.go index d24f6d9f..e2df534c 100644 --- a/src/pcap/test/integration/ginkgo_integration_test.go +++ b/src/pcap/test/integration/ginkgo_integration_test.go @@ -3,8 +3,8 @@ package integration_test import ( "testing" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //nolint:revive // this is the common way to import ginkgo and gomega + . "github.com/onsi/gomega" //nolint:revive // this is the common way to import ginkgo and gomega ) func TestIntegrationTests(t *testing.T) { diff --git a/src/pcap/test/integration/helpers.go b/src/pcap/test/integration/helpers.go index 7f7209cb..f1dd9455 100644 --- a/src/pcap/test/integration/helpers.go +++ b/src/pcap/test/integration/helpers.go @@ -1,4 +1,4 @@ -//nolint:gomnd // These test tools include a lot of magic numbers that are part of the test scenarios. +//nolint:mnd // These test tools include a lot of magic numbers that are part of the test scenarios. package integration import ( @@ -13,6 +13,7 @@ import ( "errors" "fmt" "io" + "io/fs" "math/big" "net" "os" @@ -173,20 +174,21 @@ func generateCerts(commonName string, dir string) (string, string, string, error return "", "", "", err } + certPerms := fs.FileMode(0600) certPath := path.Join(dir, "cert.pem") keyPath := path.Join(dir, "private.key") caPath := path.Join(dir, "ca.pem") - err = os.WriteFile(certPath, certPEM.Bytes(), os.ModePerm) + err = os.WriteFile(certPath, certPEM.Bytes(), certPerms) if err != nil { return "", "", "", err } - err = os.WriteFile(keyPath, certPrivKeyPEM.Bytes(), os.ModePerm) + err = os.WriteFile(keyPath, certPrivKeyPEM.Bytes(), certPerms) if err != nil { return "", "", "", err } - err = os.WriteFile(caPath, caPEM.Bytes(), os.ModePerm) + err = os.WriteFile(caPath, caPEM.Bytes(), certPerms) if err != nil { return "", "", "", err } @@ -345,7 +347,7 @@ func containsMsgTypeWithOrigin(messages []*pcap.CaptureResponse, msgType pcap.Me } func NewMemoryMessageWriter() *MemoryMessageWriter { - return &MemoryMessageWriter{Messages: make([]*pcap.Message, 0, 10)} //nolint:gomnd // Default configuration + return &MemoryMessageWriter{Messages: make([]*pcap.Message, 0, 10)} //nolint:mnd // Default configuration } type MemoryMessageWriter struct { diff --git a/src/pcap/test/integration/local_agent.go b/src/pcap/test/integration/local_agent.go index 5235da65..5f1ae328 100644 --- a/src/pcap/test/integration/local_agent.go +++ b/src/pcap/test/integration/local_agent.go @@ -15,8 +15,8 @@ var TestNodeIndex = 0 // localNodeListener gives each mock gorouter a separate local IP address, so gorouters can be distinguished based on their IP address in tests. func localNodeListener(port int) net.Listener { // exclude .0 and .255 as they may have special meaning. - node := (TestNodeIndex % 254) + 1 //nolint:gomnd // default IP range - subnet := TestNodeIndex / 254 //nolint:gomnd // default IP range + node := (TestNodeIndex % 254) + 1 //nolint:mnd // default IP range + subnet := TestNodeIndex / 254 //nolint:mnd // default IP range TestNodeIndex++ diff --git a/src/pcap/test/mock/mocks.go b/src/pcap/test/mock/mocks.go index 3486f998..e7932d55 100644 --- a/src/pcap/test/mock/mocks.go +++ b/src/pcap/test/mock/mocks.go @@ -1,4 +1,4 @@ -//nolint:gomnd // These tests include a lot of magic numbers that are part of the test scenarios. +//nolint:mnd // These tests include a lot of magic numbers that are part of the test scenarios. package mock import ( @@ -46,7 +46,7 @@ func NewMockJWTAPI() (*httptest.Server, string) { jsonString := fmt.Sprintf(`{"keys":[{"kty": "RSA","e": "AQAB","use": "sig","kid": "uaa-jwt-key-1","alg": "RS256","value": "%v","n": ""}]}`, publicPemKeyNoLineBreak) - mux.HandleFunc("/token_keys", func(writer http.ResponseWriter, request *http.Request) { + mux.HandleFunc("/token_keys", func(writer http.ResponseWriter, _ *http.Request) { writer.Header().Set("Content-Type", "application/json") _, err := writer.Write([]byte(jsonString)) @@ -55,7 +55,7 @@ func NewMockJWTAPI() (*httptest.Server, string) { } }) - mux.HandleFunc("/oauth/token", func(writer http.ResponseWriter, request *http.Request) { + mux.HandleFunc("/oauth/token", func(writer http.ResponseWriter, _ *http.Request) { response := fmt.Sprintf(`{"access_token": "%v","refresh_token": "%v","token_type": "bearer"}`, token, token) _, err := writer.Write([]byte(response)) if err != nil { @@ -159,7 +159,7 @@ func NewMockBoshDirectorAPI(responses map[string]string, url string) *httptest.S responseTemplate := template.Must(template.New("boshapi").Parse(jsonTemplate)) mux := http.NewServeMux() - mux.HandleFunc("/info", func(writer http.ResponseWriter, request *http.Request) { + mux.HandleFunc("/info", func(writer http.ResponseWriter, _ *http.Request) { writer.Header().Set("Content-Type", "application/json") err := responseTemplate.Execute(writer, boshapi) if err != nil {