agent: fix message when -dsn is provided without -type (#2009)

This commit is contained in:
mmetc 2023-01-20 16:14:26 +01:00 committed by GitHub
parent e5833699c0
commit d369656b26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 14 deletions

View file

@ -100,10 +100,7 @@ func LoadBuckets(cConfig *csconfig.Config) error {
func LoadAcquisition(cConfig *csconfig.Config) error {
var err error
if flags.SingleFileType != "" || flags.OneShotDSN != "" {
if flags.OneShotDSN == "" || flags.SingleFileType == "" {
return fmt.Errorf("-type requires a -dsn argument")
}
if flags.SingleFileType != "" && flags.OneShotDSN != "" {
flags.Labels = labels
flags.Labels["type"] = flags.SingleFileType
@ -248,6 +245,14 @@ func LoadConfig(cConfig *csconfig.Config) error {
cConfig.Crowdsec.LintOnly = true
}
if flags.OneShotDSN != "" && flags.SingleFileType == "" {
return errors.New("-dsn requires a -type argument")
}
if flags.SingleFileType != "" && flags.OneShotDSN == "" {
return errors.New("-type requires a -dsn argument")
}
if flags.SingleFileType != "" && flags.OneShotDSN != "" {
if cConfig.API != nil && cConfig.API.Server != nil {
cConfig.API.Server.OnlineClient = nil

View file

@ -28,36 +28,43 @@ setup() {
#----------
@test "-type and -dsn are required together" {
rune -1 "${CROWDSEC}" -no-api -type syslog
assert_stderr --partial "-type requires a -dsn argument"
rune -1 "${CROWDSEC}" -no-api -dsn file:///dev/fd/0
assert_stderr --partial "-dsn requires a -type argument"
}
@test "we have one decision" {
run -0 --separate-stderr cscli decisions list -o json
run -0 jq '. | length' <(output)
rune -0 cscli decisions list -o json
rune -0 jq '. | length' <(output)
assert_output 1
}
@test "1.1.1.172 has been banned" {
run -0 --separate-stderr cscli decisions list -o json
run -0 jq -r '.[].decisions[0].value' <(output)
rune -0 cscli decisions list -o json
rune -0 jq -r '.[].decisions[0].value' <(output)
assert_output '1.1.1.172'
}
@test "1.1.1.172 has been banned (range/contained: -r 1.1.1.0/24 --contained)" {
run -0 --separate-stderr cscli decisions list -r 1.1.1.0/24 --contained -o json
run -0 jq -r '.[].decisions[0].value' <(output)
rune -0 cscli decisions list -r 1.1.1.0/24 --contained -o json
rune -0 jq -r '.[].decisions[0].value' <(output)
assert_output '1.1.1.172'
}
@test "1.1.1.172 has not been banned (range/NOT-contained: -r 1.1.2.0/24)" {
run -0 --separate-stderr cscli decisions list -r 1.1.2.0/24 -o json
rune -0 cscli decisions list -r 1.1.2.0/24 -o json
assert_output 'null'
}
@test "1.1.1.172 has been banned (exact: -i 1.1.1.172)" {
run -0 --separate-stderr cscli decisions list -i 1.1.1.172 -o json
run -0 jq -r '.[].decisions[0].value' <(output)
rune -0 cscli decisions list -i 1.1.1.172 -o json
rune -0 jq -r '.[].decisions[0].value' <(output)
assert_output '1.1.1.172'
}
@test "1.1.1.173 has not been banned (exact: -i 1.1.1.173)" {
run -0 --separate-stderr cscli decisions list -i 1.1.1.173 -o json
rune -0 cscli decisions list -i 1.1.1.173 -o json
assert_output 'null'
}