Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/crowdsec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func LoadBuckets(cConfig *csconfig.Config, hub *cwhub.Hub) error {

holders, outputEventChan, err = leakybucket.LoadBuckets(cConfig.Crowdsec, hub, scenarios, &bucketsTomb, buckets, flags.OrderEvent)
if err != nil {
return fmt.Errorf("scenario loading failed: %w", err)
return err
}

if cConfig.Prometheus != nil && cConfig.Prometheus.Enabled {
Expand Down
5 changes: 2 additions & 3 deletions pkg/leakybucket/manager_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ func loadBucketFactoriesFromFile(item *cwhub.Item, hub *cwhub.Hub, buckets *Buck

err = LoadBucket(&bucketFactory, tomb)
if err != nil {
log.Errorf("Failed to load bucket %s: %v", bucketFactory.Name, err)
return nil, fmt.Errorf("loading of %s failed: %w", bucketFactory.Name, err)
return nil, fmt.Errorf("bucket %s: %w", bucketFactory.Name, err)
}

bucketFactory.orderEvent = orderEvent
Expand Down Expand Up @@ -375,7 +374,7 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error {

if bucketFactory.Filter == "" {
bucketFactory.logger.Warning("Bucket without filter, abort.")
return errors.New("bucket without filter directive")
return errors.New("missing filter directive")
}

bucketFactory.RunTimeFilter, err = expr.Compile(bucketFactory.Filter, exprhelpers.GetExprOptions(map[string]any{"evt": &pipeline.Event{}})...)
Expand Down
34 changes: 34 additions & 0 deletions test/bats/scenarios.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bats

set -u

setup_file() {
load "../lib/setup_file.sh"
}

teardown_file() {
load "../lib/teardown_file.sh"
}

setup() {
load "../lib/setup.sh"
./instance-data load
}

teardown() {
./instance-crowdsec stop
}

#----------

@test "misconfigured scenario" {
CONFIG_DIR=$(dirname "$CONFIG_YAML")
mkdir -p "$CONFIG_DIR/scenarios/local"
echo "name: foo" >"$CONFIG_DIR/scenarios/local/foo.yaml"
config_set '.common.log_media="stdout"'
rune -1 "$CROWDSEC"
# XXX:
assert_stderr --partial "Bucket without filter, abort."
assert_stderr --partial "crowdsec init: while loading scenarios: bucket foo: missing filter directive"
refute_output
}