diff --git a/cmd/cscti/smokeip.go b/cmd/cscti/smokeip.go index b2b050993acd..6c507f11cc2b 100644 --- a/cmd/cscti/smokeip.go +++ b/cmd/cscti/smokeip.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "errors" "fmt" "os" "time" @@ -36,7 +37,8 @@ func (cli *cliSmokeIP) smokeip(ip string) error { return err } - ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() resp, err := client.GetSmokeIpWithResponse(ctx, ip) if err != nil { @@ -45,15 +47,15 @@ func (cli *cliSmokeIP) smokeip(ip string) error { switch { case resp.JSON404 != nil: - return fmt.Errorf("ip not found") + return errors.New("ip not found") case resp.JSON403 != nil: - return fmt.Errorf("forbidden") + return errors.New("forbidden") case resp.JSON500 != nil: - return fmt.Errorf("internal server error") + return errors.New("internal server error") case resp.JSON429 != nil: - return fmt.Errorf("too many requests") + return errors.New("too many requests") case resp.JSON400 != nil: - return fmt.Errorf("bad request") + return errors.New("bad request") case resp.JSON200 == nil: return fmt.Errorf("unexpected error %d", resp.StatusCode()) } diff --git a/pkg/exprhelpers/crowdsec_cti_test.go b/pkg/exprhelpers/crowdsec_cti_test.go index 44b5b29a44b1..81b97cb0adc9 100644 --- a/pkg/exprhelpers/crowdsec_cti_test.go +++ b/pkg/exprhelpers/crowdsec_cti_test.go @@ -119,7 +119,7 @@ func TestNillClient(t *testing.T) { item, err := CrowdsecCTI("1.2.3.4") assert.Equal(t, err, cti.ErrDisabled) - assert.Equal(t, item, &cti.CTIObject{}) + assert.Equal(t, &cti.CTIObject{}, item) } func TestInvalidAuth(t *testing.T) { @@ -156,7 +156,7 @@ func TestInvalidAuth(t *testing.T) { require.NoError(t, err) item, err = CrowdsecCTI("1.2.3.4") - assert.Equal(t, item, &cti.CTIObject{}) + assert.Equal(t, &cti.CTIObject{}, item) assert.False(t, CTIApiEnabled) assert.Equal(t, err, cti.ErrDisabled) } @@ -178,7 +178,7 @@ func TestNoKey(t *testing.T) { require.NoError(t, err) item, err := CrowdsecCTI("1.2.3.4") - assert.Equal(t, item, &cti.CTIObject{}) + assert.Equal(t, &cti.CTIObject{}, item) assert.False(t, CTIApiEnabled) assert.Equal(t, err, cti.ErrDisabled) }