|
@@ -20,10 +20,12 @@ import (
|
|
|
"github.com/stretchr/testify/require"
|
|
|
"gopkg.in/tomb.v2"
|
|
|
|
|
|
+ "github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
|
|
+ "github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
|
|
+ "github.com/crowdsecurity/go-cs-lib/pkg/version"
|
|
|
+
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
|
|
- "github.com/crowdsecurity/crowdsec/pkg/cstest"
|
|
|
- "github.com/crowdsecurity/crowdsec/pkg/cwversion"
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database"
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/decision"
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/machine"
|
|
@@ -59,10 +61,10 @@ func getAPIC(t *testing.T) *apic {
|
|
|
metricsTomb: tomb.Tomb{},
|
|
|
scenarioList: make([]string, 0),
|
|
|
consoleConfig: &csconfig.ConsoleConfig{
|
|
|
- ShareManualDecisions: types.BoolPtr(false),
|
|
|
- ShareTaintedScenarios: types.BoolPtr(false),
|
|
|
- ShareCustomScenarios: types.BoolPtr(false),
|
|
|
- ShareContext: types.BoolPtr(false),
|
|
|
+ ShareManualDecisions: ptr.Of(false),
|
|
|
+ ShareTaintedScenarios: ptr.Of(false),
|
|
|
+ ShareCustomScenarios: ptr.Of(false),
|
|
|
+ ShareContext: ptr.Of(false),
|
|
|
},
|
|
|
isPulling: make(chan bool, 1),
|
|
|
}
|
|
@@ -205,7 +207,7 @@ func TestNewAPIC(t *testing.T) {
|
|
|
action: func() {},
|
|
|
args: args{
|
|
|
dbClient: getDBClient(t),
|
|
|
- consoleConfig: LoadTestConfig().API.Server.ConsoleConfig,
|
|
|
+ consoleConfig: LoadTestConfig(t).API.Server.ConsoleConfig,
|
|
|
},
|
|
|
},
|
|
|
{
|
|
@@ -213,7 +215,7 @@ func TestNewAPIC(t *testing.T) {
|
|
|
action: func() { testConfig.Credentials.URL = "foobar http://" },
|
|
|
args: args{
|
|
|
dbClient: getDBClient(t),
|
|
|
- consoleConfig: LoadTestConfig().API.Server.ConsoleConfig,
|
|
|
+ consoleConfig: LoadTestConfig(t).API.Server.ConsoleConfig,
|
|
|
},
|
|
|
expectedErr: "first path segment in URL cannot contain colon",
|
|
|
},
|
|
@@ -265,11 +267,11 @@ func TestAPICHandleDeletedDecisions(t *testing.T) {
|
|
|
assertTotalDecisionCount(t, api.dbClient, 2)
|
|
|
|
|
|
nbDeleted, err := api.HandleDeletedDecisions([]*models.Decision{{
|
|
|
- Value: types.StrPtr("1.2.3.4"),
|
|
|
- Origin: types.StrPtr(types.CAPIOrigin),
|
|
|
+ Value: ptr.Of("1.2.3.4"),
|
|
|
+ Origin: ptr.Of(types.CAPIOrigin),
|
|
|
Type: &decision1.Type,
|
|
|
- Scenario: types.StrPtr("crowdsec/test"),
|
|
|
- Scope: types.StrPtr("IP"),
|
|
|
+ Scenario: ptr.Of("crowdsec/test"),
|
|
|
+ Scope: ptr.Of("IP"),
|
|
|
}}, deleteCounters)
|
|
|
|
|
|
assert.NoError(t, err)
|
|
@@ -293,7 +295,7 @@ func TestAPICGetMetrics(t *testing.T) {
|
|
|
machineIDs: []string{},
|
|
|
bouncers: []string{},
|
|
|
expectedMetric: &models.Metrics{
|
|
|
- ApilVersion: types.StrPtr(cwversion.VersionStr()),
|
|
|
+ ApilVersion: ptr.Of(version.String()),
|
|
|
Bouncers: []*models.MetricsBouncerInfo{},
|
|
|
Machines: []*models.MetricsAgentInfo{},
|
|
|
},
|
|
@@ -303,7 +305,7 @@ func TestAPICGetMetrics(t *testing.T) {
|
|
|
machineIDs: []string{"a", "b", "c"},
|
|
|
bouncers: []string{"1", "2", "3"},
|
|
|
expectedMetric: &models.Metrics{
|
|
|
- ApilVersion: types.StrPtr(cwversion.VersionStr()),
|
|
|
+ ApilVersion: ptr.Of(version.String()),
|
|
|
Bouncers: []*models.MetricsBouncerInfo{
|
|
|
{
|
|
|
CustomName: "1",
|
|
@@ -374,23 +376,23 @@ func TestAPICGetMetrics(t *testing.T) {
|
|
|
|
|
|
func TestCreateAlertsForDecision(t *testing.T) {
|
|
|
httpBfDecisionList := &models.Decision{
|
|
|
- Origin: types.StrPtr(types.ListOrigin),
|
|
|
- Scenario: types.StrPtr("crowdsecurity/http-bf"),
|
|
|
+ Origin: ptr.Of(types.ListOrigin),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/http-bf"),
|
|
|
}
|
|
|
|
|
|
sshBfDecisionList := &models.Decision{
|
|
|
- Origin: types.StrPtr(types.ListOrigin),
|
|
|
- Scenario: types.StrPtr("crowdsecurity/ssh-bf"),
|
|
|
+ Origin: ptr.Of(types.ListOrigin),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/ssh-bf"),
|
|
|
}
|
|
|
|
|
|
httpBfDecisionCommunity := &models.Decision{
|
|
|
- Origin: types.StrPtr(types.CAPIOrigin),
|
|
|
- Scenario: types.StrPtr("crowdsecurity/http-bf"),
|
|
|
+ Origin: ptr.Of(types.CAPIOrigin),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/http-bf"),
|
|
|
}
|
|
|
|
|
|
sshBfDecisionCommunity := &models.Decision{
|
|
|
- Origin: types.StrPtr(types.CAPIOrigin),
|
|
|
- Scenario: types.StrPtr("crowdsecurity/ssh-bf"),
|
|
|
+ Origin: ptr.Of(types.CAPIOrigin),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/ssh-bf"),
|
|
|
}
|
|
|
type args struct {
|
|
|
decisions []*models.Decision
|
|
@@ -453,27 +455,27 @@ func TestCreateAlertsForDecision(t *testing.T) {
|
|
|
|
|
|
func TestFillAlertsWithDecisions(t *testing.T) {
|
|
|
httpBfDecisionCommunity := &models.Decision{
|
|
|
- Origin: types.StrPtr(types.CAPIOrigin),
|
|
|
- Scenario: types.StrPtr("crowdsecurity/http-bf"),
|
|
|
- Scope: types.StrPtr("ip"),
|
|
|
+ Origin: ptr.Of(types.CAPIOrigin),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/http-bf"),
|
|
|
+ Scope: ptr.Of("ip"),
|
|
|
}
|
|
|
|
|
|
sshBfDecisionCommunity := &models.Decision{
|
|
|
- Origin: types.StrPtr(types.CAPIOrigin),
|
|
|
- Scenario: types.StrPtr("crowdsecurity/ssh-bf"),
|
|
|
- Scope: types.StrPtr("ip"),
|
|
|
+ Origin: ptr.Of(types.CAPIOrigin),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/ssh-bf"),
|
|
|
+ Scope: ptr.Of("ip"),
|
|
|
}
|
|
|
|
|
|
httpBfDecisionList := &models.Decision{
|
|
|
- Origin: types.StrPtr(types.ListOrigin),
|
|
|
- Scenario: types.StrPtr("crowdsecurity/http-bf"),
|
|
|
- Scope: types.StrPtr("ip"),
|
|
|
+ Origin: ptr.Of(types.ListOrigin),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/http-bf"),
|
|
|
+ Scope: ptr.Of("ip"),
|
|
|
}
|
|
|
|
|
|
sshBfDecisionList := &models.Decision{
|
|
|
- Origin: types.StrPtr(types.ListOrigin),
|
|
|
- Scenario: types.StrPtr("crowdsecurity/ssh-bf"),
|
|
|
- Scope: types.StrPtr("ip"),
|
|
|
+ Origin: ptr.Of(types.ListOrigin),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/ssh-bf"),
|
|
|
+ Scope: ptr.Of("ip"),
|
|
|
}
|
|
|
type args struct {
|
|
|
alerts []*models.Alert
|
|
@@ -572,58 +574,58 @@ func TestAPICWhitelists(t *testing.T) {
|
|
|
"9.9.9.9", // This is already present in DB
|
|
|
"9.1.9.9", // This not present in DB
|
|
|
},
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
}, // This is already present in DB
|
|
|
},
|
|
|
New: modelscapi.GetDecisionsStreamResponseNew{
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/test1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/test1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("13.2.3.4"), //wl by cidr
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("13.2.3.4"), //wl by cidr
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/test1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/test1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("2.2.3.4"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("2.2.3.4"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/test2"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/test2"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("13.2.3.5"), //wl by cidr
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("13.2.3.5"), //wl by cidr
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
}, // These two are from community list.
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/test1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/test1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("6.2.3.4"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("6.2.3.4"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/test1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/test1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("9.2.3.4"), //wl by ip
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("9.2.3.4"), //wl by ip
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -631,18 +633,18 @@ func TestAPICWhitelists(t *testing.T) {
|
|
|
Links: &modelscapi.GetDecisionsStreamResponseLinks{
|
|
|
Blocklists: []*modelscapi.BlocklistLink{
|
|
|
{
|
|
|
- URL: types.StrPtr("http://api.crowdsec.net/blocklist1"),
|
|
|
- Name: types.StrPtr("blocklist1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
- Remediation: types.StrPtr("ban"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ URL: ptr.Of("http://api.crowdsec.net/blocklist1"),
|
|
|
+ Name: ptr.Of("blocklist1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
+ Remediation: ptr.Of("ban"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
{
|
|
|
- URL: types.StrPtr("http://api.crowdsec.net/blocklist2"),
|
|
|
- Name: types.StrPtr("blocklist2"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
- Remediation: types.StrPtr("ban"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ URL: ptr.Of("http://api.crowdsec.net/blocklist2"),
|
|
|
+ Name: ptr.Of("blocklist2"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
+ Remediation: ptr.Of("ban"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -661,7 +663,7 @@ func TestAPICWhitelists(t *testing.T) {
|
|
|
apic, err := apiclient.NewDefaultClient(
|
|
|
url,
|
|
|
"/api",
|
|
|
- fmt.Sprintf("crowdsec/%s", cwversion.VersionStr()),
|
|
|
+ fmt.Sprintf("crowdsec/%s", version.String()),
|
|
|
nil,
|
|
|
)
|
|
|
require.NoError(t, err)
|
|
@@ -734,27 +736,27 @@ func TestAPICPullTop(t *testing.T) {
|
|
|
"9.9.9.9", // This is already present in DB
|
|
|
"9.1.9.9", // This not present in DB
|
|
|
},
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
}, // This is already present in DB
|
|
|
},
|
|
|
New: modelscapi.GetDecisionsStreamResponseNew{
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/test1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/test1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("1.2.3.4"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("1.2.3.4"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/test2"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/test2"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("1.2.3.5"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("1.2.3.5"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
}, // These two are from community list.
|
|
@@ -762,18 +764,18 @@ func TestAPICPullTop(t *testing.T) {
|
|
|
Links: &modelscapi.GetDecisionsStreamResponseLinks{
|
|
|
Blocklists: []*modelscapi.BlocklistLink{
|
|
|
{
|
|
|
- URL: types.StrPtr("http://api.crowdsec.net/blocklist1"),
|
|
|
- Name: types.StrPtr("blocklist1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
- Remediation: types.StrPtr("ban"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ URL: ptr.Of("http://api.crowdsec.net/blocklist1"),
|
|
|
+ Name: ptr.Of("blocklist1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
+ Remediation: ptr.Of("ban"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
{
|
|
|
- URL: types.StrPtr("http://api.crowdsec.net/blocklist2"),
|
|
|
- Name: types.StrPtr("blocklist2"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
- Remediation: types.StrPtr("ban"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ URL: ptr.Of("http://api.crowdsec.net/blocklist2"),
|
|
|
+ Name: ptr.Of("blocklist2"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
+ Remediation: ptr.Of("ban"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -792,7 +794,7 @@ func TestAPICPullTop(t *testing.T) {
|
|
|
apic, err := apiclient.NewDefaultClient(
|
|
|
url,
|
|
|
"/api",
|
|
|
- fmt.Sprintf("crowdsec/%s", cwversion.VersionStr()),
|
|
|
+ fmt.Sprintf("crowdsec/%s", version.String()),
|
|
|
nil,
|
|
|
)
|
|
|
require.NoError(t, err)
|
|
@@ -840,12 +842,12 @@ func TestAPICPullTopBLCacheFirstCall(t *testing.T) {
|
|
|
modelscapi.GetDecisionsStreamResponse{
|
|
|
New: modelscapi.GetDecisionsStreamResponseNew{
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/test1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/test1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("1.2.3.4"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("1.2.3.4"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -853,11 +855,11 @@ func TestAPICPullTopBLCacheFirstCall(t *testing.T) {
|
|
|
Links: &modelscapi.GetDecisionsStreamResponseLinks{
|
|
|
Blocklists: []*modelscapi.BlocklistLink{
|
|
|
{
|
|
|
- URL: types.StrPtr("http://api.crowdsec.net/blocklist1"),
|
|
|
- Name: types.StrPtr("blocklist1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
- Remediation: types.StrPtr("ban"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ URL: ptr.Of("http://api.crowdsec.net/blocklist1"),
|
|
|
+ Name: ptr.Of("blocklist1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
+ Remediation: ptr.Of("ban"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -874,7 +876,7 @@ func TestAPICPullTopBLCacheFirstCall(t *testing.T) {
|
|
|
apic, err := apiclient.NewDefaultClient(
|
|
|
url,
|
|
|
"/api",
|
|
|
- fmt.Sprintf("crowdsec/%s", cwversion.VersionStr()),
|
|
|
+ fmt.Sprintf("crowdsec/%s", version.String()),
|
|
|
nil,
|
|
|
)
|
|
|
require.NoError(t, err)
|
|
@@ -883,7 +885,7 @@ func TestAPICPullTopBLCacheFirstCall(t *testing.T) {
|
|
|
err = api.PullTop(false)
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
- blocklistConfigItemName := fmt.Sprintf("blocklist:%s:last_pull", *types.StrPtr("blocklist1"))
|
|
|
+ blocklistConfigItemName := "blocklist:blocklist1:last_pull"
|
|
|
lastPullTimestamp, err := api.dbClient.GetConfigItem(blocklistConfigItemName)
|
|
|
require.NoError(t, err)
|
|
|
assert.NotEqual(t, "", *lastPullTimestamp)
|
|
@@ -927,12 +929,12 @@ func TestAPICPullTopBLCacheForceCall(t *testing.T) {
|
|
|
modelscapi.GetDecisionsStreamResponse{
|
|
|
New: modelscapi.GetDecisionsStreamResponseNew{
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/test1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/test1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("1.2.3.4"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("1.2.3.4"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -940,11 +942,11 @@ func TestAPICPullTopBLCacheForceCall(t *testing.T) {
|
|
|
Links: &modelscapi.GetDecisionsStreamResponseLinks{
|
|
|
Blocklists: []*modelscapi.BlocklistLink{
|
|
|
{
|
|
|
- URL: types.StrPtr("http://api.crowdsec.net/blocklist1"),
|
|
|
- Name: types.StrPtr("blocklist1"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
- Remediation: types.StrPtr("ban"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ URL: ptr.Of("http://api.crowdsec.net/blocklist1"),
|
|
|
+ Name: ptr.Of("blocklist1"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
+ Remediation: ptr.Of("ban"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -961,7 +963,7 @@ func TestAPICPullTopBLCacheForceCall(t *testing.T) {
|
|
|
apic, err := apiclient.NewDefaultClient(
|
|
|
url,
|
|
|
"/api",
|
|
|
- fmt.Sprintf("crowdsec/%s", cwversion.VersionStr()),
|
|
|
+ fmt.Sprintf("crowdsec/%s", version.String()),
|
|
|
nil,
|
|
|
)
|
|
|
require.NoError(t, err)
|
|
@@ -981,10 +983,10 @@ func TestAPICPush(t *testing.T) {
|
|
|
name: "simple single alert",
|
|
|
alerts: []*models.Alert{
|
|
|
{
|
|
|
- Scenario: types.StrPtr("crowdsec/test"),
|
|
|
- ScenarioHash: types.StrPtr("certified"),
|
|
|
- ScenarioVersion: types.StrPtr("v1.0"),
|
|
|
- Simulated: types.BoolPtr(false),
|
|
|
+ Scenario: ptr.Of("crowdsec/test"),
|
|
|
+ ScenarioHash: ptr.Of("certified"),
|
|
|
+ ScenarioVersion: ptr.Of("v1.0"),
|
|
|
+ Simulated: ptr.Of(false),
|
|
|
Source: &models.Source{},
|
|
|
},
|
|
|
},
|
|
@@ -994,10 +996,10 @@ func TestAPICPush(t *testing.T) {
|
|
|
name: "simulated alert is not pushed",
|
|
|
alerts: []*models.Alert{
|
|
|
{
|
|
|
- Scenario: types.StrPtr("crowdsec/test"),
|
|
|
- ScenarioHash: types.StrPtr("certified"),
|
|
|
- ScenarioVersion: types.StrPtr("v1.0"),
|
|
|
- Simulated: types.BoolPtr(true),
|
|
|
+ Scenario: ptr.Of("crowdsec/test"),
|
|
|
+ ScenarioHash: ptr.Of("certified"),
|
|
|
+ ScenarioVersion: ptr.Of("v1.0"),
|
|
|
+ Simulated: ptr.Of(true),
|
|
|
Source: &models.Source{},
|
|
|
},
|
|
|
},
|
|
@@ -1010,10 +1012,10 @@ func TestAPICPush(t *testing.T) {
|
|
|
alerts := make([]*models.Alert, 100)
|
|
|
for i := 0; i < 100; i++ {
|
|
|
alerts[i] = &models.Alert{
|
|
|
- Scenario: types.StrPtr("crowdsec/test"),
|
|
|
- ScenarioHash: types.StrPtr("certified"),
|
|
|
- ScenarioVersion: types.StrPtr("v1.0"),
|
|
|
- Simulated: types.BoolPtr(false),
|
|
|
+ Scenario: ptr.Of("crowdsec/test"),
|
|
|
+ ScenarioHash: ptr.Of("certified"),
|
|
|
+ ScenarioVersion: ptr.Of("v1.0"),
|
|
|
+ Simulated: ptr.Of(false),
|
|
|
Source: &models.Source{},
|
|
|
}
|
|
|
}
|
|
@@ -1036,7 +1038,7 @@ func TestAPICPush(t *testing.T) {
|
|
|
apic, err := apiclient.NewDefaultClient(
|
|
|
url,
|
|
|
"/api",
|
|
|
- fmt.Sprintf("crowdsec/%s", cwversion.VersionStr()),
|
|
|
+ fmt.Sprintf("crowdsec/%s", version.String()),
|
|
|
nil,
|
|
|
)
|
|
|
require.NoError(t, err)
|
|
@@ -1111,7 +1113,7 @@ func TestAPICSendMetrics(t *testing.T) {
|
|
|
apiClient, err := apiclient.NewDefaultClient(
|
|
|
url,
|
|
|
"/api",
|
|
|
- fmt.Sprintf("crowdsec/%s", cwversion.VersionStr()),
|
|
|
+ fmt.Sprintf("crowdsec/%s", version.String()),
|
|
|
nil,
|
|
|
)
|
|
|
require.NoError(t, err)
|
|
@@ -1179,7 +1181,7 @@ func TestAPICPull(t *testing.T) {
|
|
|
apic, err := apiclient.NewDefaultClient(
|
|
|
url,
|
|
|
"/api",
|
|
|
- fmt.Sprintf("crowdsec/%s", cwversion.VersionStr()),
|
|
|
+ fmt.Sprintf("crowdsec/%s", version.String()),
|
|
|
nil,
|
|
|
)
|
|
|
require.NoError(t, err)
|
|
@@ -1188,12 +1190,12 @@ func TestAPICPull(t *testing.T) {
|
|
|
modelscapi.GetDecisionsStreamResponse{
|
|
|
New: modelscapi.GetDecisionsStreamResponseNew{
|
|
|
&modelscapi.GetDecisionsStreamResponseNewItem{
|
|
|
- Scenario: types.StrPtr("crowdsecurity/ssh-bf"),
|
|
|
- Scope: types.StrPtr("Ip"),
|
|
|
+ Scenario: ptr.Of("crowdsecurity/ssh-bf"),
|
|
|
+ Scope: ptr.Of("Ip"),
|
|
|
Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
|
|
|
{
|
|
|
- Value: types.StrPtr("1.2.3.5"),
|
|
|
- Duration: types.StrPtr("24h"),
|
|
|
+ Value: ptr.Of("1.2.3.5"),
|
|
|
+ Duration: ptr.Of("24h"),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -1228,29 +1230,29 @@ func TestShouldShareAlert(t *testing.T) {
|
|
|
{
|
|
|
name: "custom alert should be shared if config enables it",
|
|
|
consoleConfig: &csconfig.ConsoleConfig{
|
|
|
- ShareCustomScenarios: types.BoolPtr(true),
|
|
|
+ ShareCustomScenarios: ptr.Of(true),
|
|
|
},
|
|
|
- alert: &models.Alert{Simulated: types.BoolPtr(false)},
|
|
|
+ alert: &models.Alert{Simulated: ptr.Of(false)},
|
|
|
expectedRet: true,
|
|
|
expectedTrust: "custom",
|
|
|
},
|
|
|
{
|
|
|
name: "custom alert should not be shared if config disables it",
|
|
|
consoleConfig: &csconfig.ConsoleConfig{
|
|
|
- ShareCustomScenarios: types.BoolPtr(false),
|
|
|
+ ShareCustomScenarios: ptr.Of(false),
|
|
|
},
|
|
|
- alert: &models.Alert{Simulated: types.BoolPtr(false)},
|
|
|
+ alert: &models.Alert{Simulated: ptr.Of(false)},
|
|
|
expectedRet: false,
|
|
|
expectedTrust: "custom",
|
|
|
},
|
|
|
{
|
|
|
name: "manual alert should be shared if config enables it",
|
|
|
consoleConfig: &csconfig.ConsoleConfig{
|
|
|
- ShareManualDecisions: types.BoolPtr(true),
|
|
|
+ ShareManualDecisions: ptr.Of(true),
|
|
|
},
|
|
|
alert: &models.Alert{
|
|
|
- Simulated: types.BoolPtr(false),
|
|
|
- Decisions: []*models.Decision{{Origin: types.StrPtr(types.CscliOrigin)}},
|
|
|
+ Simulated: ptr.Of(false),
|
|
|
+ Decisions: []*models.Decision{{Origin: ptr.Of(types.CscliOrigin)}},
|
|
|
},
|
|
|
expectedRet: true,
|
|
|
expectedTrust: "manual",
|
|
@@ -1258,11 +1260,11 @@ func TestShouldShareAlert(t *testing.T) {
|
|
|
{
|
|
|
name: "manual alert should not be shared if config disables it",
|
|
|
consoleConfig: &csconfig.ConsoleConfig{
|
|
|
- ShareManualDecisions: types.BoolPtr(false),
|
|
|
+ ShareManualDecisions: ptr.Of(false),
|
|
|
},
|
|
|
alert: &models.Alert{
|
|
|
- Simulated: types.BoolPtr(false),
|
|
|
- Decisions: []*models.Decision{{Origin: types.StrPtr(types.CscliOrigin)}},
|
|
|
+ Simulated: ptr.Of(false),
|
|
|
+ Decisions: []*models.Decision{{Origin: ptr.Of(types.CscliOrigin)}},
|
|
|
},
|
|
|
expectedRet: false,
|
|
|
expectedTrust: "manual",
|
|
@@ -1270,11 +1272,11 @@ func TestShouldShareAlert(t *testing.T) {
|
|
|
{
|
|
|
name: "manual alert should be shared if config enables it",
|
|
|
consoleConfig: &csconfig.ConsoleConfig{
|
|
|
- ShareTaintedScenarios: types.BoolPtr(true),
|
|
|
+ ShareTaintedScenarios: ptr.Of(true),
|
|
|
},
|
|
|
alert: &models.Alert{
|
|
|
- Simulated: types.BoolPtr(false),
|
|
|
- ScenarioHash: types.StrPtr("whateverHash"),
|
|
|
+ Simulated: ptr.Of(false),
|
|
|
+ ScenarioHash: ptr.Of("whateverHash"),
|
|
|
},
|
|
|
expectedRet: true,
|
|
|
expectedTrust: "tainted",
|
|
@@ -1282,11 +1284,11 @@ func TestShouldShareAlert(t *testing.T) {
|
|
|
{
|
|
|
name: "manual alert should not be shared if config disables it",
|
|
|
consoleConfig: &csconfig.ConsoleConfig{
|
|
|
- ShareTaintedScenarios: types.BoolPtr(false),
|
|
|
+ ShareTaintedScenarios: ptr.Of(false),
|
|
|
},
|
|
|
alert: &models.Alert{
|
|
|
- Simulated: types.BoolPtr(false),
|
|
|
- ScenarioHash: types.StrPtr("whateverHash"),
|
|
|
+ Simulated: ptr.Of(false),
|
|
|
+ ScenarioHash: ptr.Of("whateverHash"),
|
|
|
},
|
|
|
expectedRet: false,
|
|
|
expectedTrust: "tainted",
|