mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 20:36:12 +02:00
Add explicit configuration for signals sharing and blocklists pull (#3277)
This commit is contained in:
parent
94a2a586e4
commit
5d414f58e5
8 changed files with 165 additions and 24 deletions
|
@ -69,7 +69,10 @@ func getAPIC(t *testing.T, ctx context.Context) *apic {
|
|||
ShareCustomScenarios: ptr.Of(false),
|
||||
ShareContext: ptr.Of(false),
|
||||
},
|
||||
isPulling: make(chan bool, 1),
|
||||
isPulling: make(chan bool, 1),
|
||||
shareSignals: true,
|
||||
pullBlocklists: true,
|
||||
pullCommunity: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,6 +203,11 @@ func TestNewAPIC(t *testing.T) {
|
|||
Login: "foo",
|
||||
Password: "bar",
|
||||
},
|
||||
Sharing: ptr.Of(true),
|
||||
PullConfig: csconfig.CapiPullConfig{
|
||||
Community: ptr.Of(true),
|
||||
Blocklists: ptr.Of(true),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1193,6 +1201,7 @@ func TestShouldShareAlert(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
consoleConfig *csconfig.ConsoleConfig
|
||||
shareSignals bool
|
||||
alert *models.Alert
|
||||
expectedRet bool
|
||||
expectedTrust string
|
||||
|
@ -1203,6 +1212,7 @@ func TestShouldShareAlert(t *testing.T) {
|
|||
ShareCustomScenarios: ptr.Of(true),
|
||||
},
|
||||
alert: &models.Alert{Simulated: ptr.Of(false)},
|
||||
shareSignals: true,
|
||||
expectedRet: true,
|
||||
expectedTrust: "custom",
|
||||
},
|
||||
|
@ -1212,6 +1222,7 @@ func TestShouldShareAlert(t *testing.T) {
|
|||
ShareCustomScenarios: ptr.Of(false),
|
||||
},
|
||||
alert: &models.Alert{Simulated: ptr.Of(false)},
|
||||
shareSignals: true,
|
||||
expectedRet: false,
|
||||
expectedTrust: "custom",
|
||||
},
|
||||
|
@ -1220,6 +1231,7 @@ func TestShouldShareAlert(t *testing.T) {
|
|||
consoleConfig: &csconfig.ConsoleConfig{
|
||||
ShareManualDecisions: ptr.Of(true),
|
||||
},
|
||||
shareSignals: true,
|
||||
alert: &models.Alert{
|
||||
Simulated: ptr.Of(false),
|
||||
Decisions: []*models.Decision{{Origin: ptr.Of(types.CscliOrigin)}},
|
||||
|
@ -1232,6 +1244,7 @@ func TestShouldShareAlert(t *testing.T) {
|
|||
consoleConfig: &csconfig.ConsoleConfig{
|
||||
ShareManualDecisions: ptr.Of(false),
|
||||
},
|
||||
shareSignals: true,
|
||||
alert: &models.Alert{
|
||||
Simulated: ptr.Of(false),
|
||||
Decisions: []*models.Decision{{Origin: ptr.Of(types.CscliOrigin)}},
|
||||
|
@ -1244,6 +1257,7 @@ func TestShouldShareAlert(t *testing.T) {
|
|||
consoleConfig: &csconfig.ConsoleConfig{
|
||||
ShareTaintedScenarios: ptr.Of(true),
|
||||
},
|
||||
shareSignals: true,
|
||||
alert: &models.Alert{
|
||||
Simulated: ptr.Of(false),
|
||||
ScenarioHash: ptr.Of("whateverHash"),
|
||||
|
@ -1256,6 +1270,7 @@ func TestShouldShareAlert(t *testing.T) {
|
|||
consoleConfig: &csconfig.ConsoleConfig{
|
||||
ShareTaintedScenarios: ptr.Of(false),
|
||||
},
|
||||
shareSignals: true,
|
||||
alert: &models.Alert{
|
||||
Simulated: ptr.Of(false),
|
||||
ScenarioHash: ptr.Of("whateverHash"),
|
||||
|
@ -1263,11 +1278,24 @@ func TestShouldShareAlert(t *testing.T) {
|
|||
expectedRet: false,
|
||||
expectedTrust: "tainted",
|
||||
},
|
||||
{
|
||||
name: "manual alert should not be shared if global sharing is disabled",
|
||||
consoleConfig: &csconfig.ConsoleConfig{
|
||||
ShareManualDecisions: ptr.Of(true),
|
||||
},
|
||||
shareSignals: false,
|
||||
alert: &models.Alert{
|
||||
Simulated: ptr.Of(false),
|
||||
ScenarioHash: ptr.Of("whateverHash"),
|
||||
},
|
||||
expectedRet: false,
|
||||
expectedTrust: "manual",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
ret := shouldShareAlert(tc.alert, tc.consoleConfig)
|
||||
ret := shouldShareAlert(tc.alert, tc.consoleConfig, tc.shareSignals)
|
||||
assert.Equal(t, tc.expectedRet, ret)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue