diff --git a/cmd/crowdsec-cli/bouncers.go b/cmd/crowdsec-cli/clibouncer/bouncers.go similarity index 96% rename from cmd/crowdsec-cli/bouncers.go rename to cmd/crowdsec-cli/clibouncer/bouncers.go index 68ce1a2fa05..0d1484bcc6b 100644 --- a/cmd/crowdsec-cli/bouncers.go +++ b/cmd/crowdsec-cli/clibouncer/bouncers.go @@ -1,4 +1,4 @@ -package main +package clibouncer import ( "encoding/csv" @@ -21,6 +21,7 @@ import ( "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cstable" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require" middlewares "github.com/crowdsecurity/crowdsec/pkg/apiserver/middlewares/v1" + "github.com/crowdsecurity/crowdsec/pkg/csconfig" "github.com/crowdsecurity/crowdsec/pkg/database" "github.com/crowdsecurity/crowdsec/pkg/database/ent" "github.com/crowdsecurity/crowdsec/pkg/database/ent/bouncer" @@ -28,12 +29,14 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/types" ) +type configGetter = func() *csconfig.Config + type cliBouncers struct { db *database.Client cfg configGetter } -func NewCLIBouncers(cfg configGetter) *cliBouncers { +func New(cfg configGetter) *cliBouncers { return &cliBouncers{ cfg: cfg, } @@ -156,8 +159,11 @@ func (cli *cliBouncers) listCSV(out io.Writer, bouncers ent.Bouncers) error { return nil } -func (cli *cliBouncers) list(out io.Writer) error { - bouncers, err := cli.db.ListBouncers() +func (cli *cliBouncers) List(out io.Writer, db *database.Client) error { + // XXX: must use the provided db object, the one in the struct might be nil + // (calling List directly skips the PersistentPreRunE) + + bouncers, err := db.ListBouncers() if err != nil { return fmt.Errorf("unable to list bouncers: %w", err) } @@ -194,7 +200,7 @@ func (cli *cliBouncers) newListCmd() *cobra.Command { Args: cobra.ExactArgs(0), DisableAutoGenTag: true, RunE: func(_ *cobra.Command, _ []string) error { - return cli.list(color.Output) + return cli.List(color.Output, cli.db) }, } diff --git a/cmd/crowdsec-cli/clicapi/capi.go b/cmd/crowdsec-cli/clicapi/capi.go index bf45613c776..4d658e3a602 100644 --- a/cmd/crowdsec-cli/clicapi/capi.go +++ b/cmd/crowdsec-cli/clicapi/capi.go @@ -4,9 +4,11 @@ import ( "context" "errors" "fmt" + "io" "net/url" "os" + "github.com/fatih/color" "github.com/go-openapi/strfmt" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -23,7 +25,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/types" ) -type configGetter func() *csconfig.Config +type configGetter = func() *csconfig.Config type cliCapi struct { cfg configGetter @@ -147,11 +149,11 @@ func (cli *cliCapi) newRegisterCmd() *cobra.Command { return cmd } -// QueryCAPIStatus checks if the Local API is reachable, and if the credentials are correct. It then checks if the instance is enrolle in the console. -func QueryCAPIStatus(hub *cwhub.Hub, credURL string, login string, password string) (bool, bool, error) { +// queryCAPIStatus checks if the Central API is reachable, and if the credentials are correct. It then checks if the instance is enrolle in the console. +func queryCAPIStatus(hub *cwhub.Hub, credURL string, login string, password string) (bool, bool, error) { apiURL, err := url.Parse(credURL) if err != nil { - return false, false, fmt.Errorf("parsing api url: %w", err) + return false, false, err } itemsForAPI := hub.GetInstalledListForAPI() @@ -176,7 +178,7 @@ func QueryCAPIStatus(hub *cwhub.Hub, credURL string, login string, password stri }, }) if err != nil { - return false, false, fmt.Errorf("new client api: %w", err) + return false, false, err } pw := strfmt.Password(password) @@ -197,10 +199,11 @@ func QueryCAPIStatus(hub *cwhub.Hub, credURL string, login string, password stri if client.IsEnrolled() { return true, true, nil } + return true, false, nil } -func (cli *cliCapi) status() error { +func (cli *cliCapi) Status(out io.Writer, hub *cwhub.Hub) error { cfg := cli.cfg() if err := require.CAPIRegistered(cfg); err != nil { @@ -209,24 +212,22 @@ func (cli *cliCapi) status() error { cred := cfg.API.Server.OnlineClient.Credentials - hub, err := require.Hub(cfg, nil, nil) - if err != nil { - return err - } - - log.Infof("Loaded credentials from %s", cfg.API.Server.OnlineClient.CredentialsFilePath) - log.Infof("Trying to authenticate with username %s on %s", cred.Login, cred.URL) + fmt.Fprintf(out, "Loaded credentials from %s\n", cfg.API.Server.OnlineClient.CredentialsFilePath) + fmt.Fprintf(out, "Trying to authenticate with username %s on %s\n", cred.Login, cred.URL) - auth, enrolled, err := QueryCAPIStatus(hub, cred.URL, cred.Login, cred.Password) + auth, enrolled, err := queryCAPIStatus(hub, cred.URL, cred.Login, cred.Password) if err != nil { - return fmt.Errorf("CAPI: failed to authenticate to Central API (CAPI): %s", err) + return fmt.Errorf("failed to authenticate to Central API (CAPI): %w", err) } + if auth { - log.Info("You can successfully interact with Central API (CAPI)") + fmt.Fprint(out, "You can successfully interact with Central API (CAPI)\n") } + if enrolled { - log.Info("Your instance is enrolled in the console") + fmt.Fprint(out, "Your instance is enrolled in the console\n") } + return nil } @@ -237,7 +238,12 @@ func (cli *cliCapi) newStatusCmd() *cobra.Command { Args: cobra.MinimumNArgs(0), DisableAutoGenTag: true, RunE: func(_ *cobra.Command, _ []string) error { - return cli.status() + hub, err := require.Hub(cli.cfg(), nil, nil) + if err != nil { + return err + } + + return cli.Status(color.Output, hub) }, } diff --git a/cmd/crowdsec-cli/clilapi/lapi.go b/cmd/crowdsec-cli/clilapi/lapi.go index ec66daf16a4..2de962d896d 100644 --- a/cmd/crowdsec-cli/clilapi/lapi.go +++ b/cmd/crowdsec-cli/clilapi/lapi.go @@ -4,12 +4,14 @@ import ( "context" "errors" "fmt" + "io" "net/url" "os" "slices" "sort" "strings" + "github.com/fatih/color" "github.com/go-openapi/strfmt" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -30,10 +32,10 @@ import ( const LAPIURLPrefix = "v1" -type configGetter func() *csconfig.Config +type configGetter = func() *csconfig.Config type cliLapi struct { - cfg configGetter + cfg configGetter } func New(cfg configGetter) *cliLapi { @@ -42,11 +44,11 @@ func New(cfg configGetter) *cliLapi { } } -// QueryLAPIStatus checks if the Local API is reachable, and if the credentials are correct -func QueryLAPIStatus(hub *cwhub.Hub, credURL string, login string, password string) error { +// queryLAPIStatus checks if the Local API is reachable, and if the credentials are correct. +func queryLAPIStatus(hub *cwhub.Hub, credURL string, login string, password string) (bool, error) { apiURL, err := url.Parse(credURL) if err != nil { - return fmt.Errorf("parsing api url: %w", err) + return false, err } client, err := apiclient.NewDefaultClient(apiURL, @@ -54,7 +56,7 @@ func QueryLAPIStatus(hub *cwhub.Hub, credURL string, login string, password stri cwversion.UserAgent(), nil) if err != nil { - return fmt.Errorf("init default client: %w", err) + return false, err } pw := strfmt.Password(password) @@ -69,30 +71,26 @@ func QueryLAPIStatus(hub *cwhub.Hub, credURL string, login string, password stri _, _, err = client.Auth.AuthenticateWatcher(context.Background(), t) if err != nil { - return err + return false, err } - return nil + return true, nil } -func (cli *cliLapi) status() error { +func (cli *cliLapi) Status(out io.Writer, hub *cwhub.Hub) error { cfg := cli.cfg() cred := cfg.API.Client.Credentials - hub, err := require.Hub(cfg, nil, nil) - if err != nil { - return err - } - - log.Infof("Loaded credentials from %s", cfg.API.Client.CredentialsFilePath) - log.Infof("Trying to authenticate with username %s on %s", cred.Login, cred.URL) + fmt.Fprintf(out, "Loaded credentials from %s\n", cfg.API.Client.CredentialsFilePath) + fmt.Fprintf(out, "Trying to authenticate with username %s on %s\n", cred.Login, cred.URL) - if err := QueryLAPIStatus(hub, cred.URL, cred.Login, cred.Password); err != nil { + _, err := queryLAPIStatus(hub, cred.URL, cred.Login, cred.Password) + if err != nil { return fmt.Errorf("failed to authenticate to Local API (LAPI): %w", err) } - log.Infof("You can successfully interact with Local API (LAPI)") + fmt.Fprintf(out, "You can successfully interact with Local API (LAPI)\n") return nil } @@ -197,7 +195,12 @@ func (cli *cliLapi) newStatusCmd() *cobra.Command { Args: cobra.MinimumNArgs(0), DisableAutoGenTag: true, RunE: func(_ *cobra.Command, _ []string) error { - return cli.status() + hub, err := require.Hub(cli.cfg(), nil, nil) + if err != nil { + return err + } + + return cli.Status(color.Output, hub) }, } diff --git a/cmd/crowdsec-cli/flag.go b/cmd/crowdsec-cli/climachine/flag.go similarity index 96% rename from cmd/crowdsec-cli/flag.go rename to cmd/crowdsec-cli/climachine/flag.go index 1780d08e5f7..c3fefd896e1 100644 --- a/cmd/crowdsec-cli/flag.go +++ b/cmd/crowdsec-cli/climachine/flag.go @@ -1,4 +1,4 @@ -package main +package climachine // Custom types for flag validation and conversion. diff --git a/cmd/crowdsec-cli/machines.go b/cmd/crowdsec-cli/climachine/machines.go similarity index 98% rename from cmd/crowdsec-cli/machines.go rename to cmd/crowdsec-cli/climachine/machines.go index 8b35245405f..bf8656105aa 100644 --- a/cmd/crowdsec-cli/machines.go +++ b/cmd/crowdsec-cli/climachine/machines.go @@ -1,4 +1,4 @@ -package main +package climachine import ( "encoding/csv" @@ -49,12 +49,14 @@ func getLastHeartbeat(m *ent.Machine) (string, bool) { return hb, true } +type configGetter = func() *csconfig.Config + type cliMachines struct { db *database.Client cfg configGetter } -func NewCLIMachines(cfg configGetter) *cliMachines { +func New(cfg configGetter) *cliMachines { return &cliMachines{ cfg: cfg, } @@ -208,8 +210,11 @@ func (cli *cliMachines) listCSV(out io.Writer, machines ent.Machines) error { return nil } -func (cli *cliMachines) list(out io.Writer) error { - machines, err := cli.db.ListMachines() +func (cli *cliMachines) List(out io.Writer, db *database.Client) error { + // XXX: must use the provided db object, the one in the struct might be nil + // (calling List directly skips the PersistentPreRunE) + + machines, err := db.ListMachines() if err != nil { return fmt.Errorf("unable to list machines: %w", err) } @@ -247,7 +252,7 @@ func (cli *cliMachines) newListCmd() *cobra.Command { Args: cobra.NoArgs, DisableAutoGenTag: true, RunE: func(_ *cobra.Command, _ []string) error { - return cli.list(color.Output) + return cli.List(color.Output, cli.db) }, } diff --git a/cmd/crowdsec-cli/support.go b/cmd/crowdsec-cli/clisupport/support.go similarity index 90% rename from cmd/crowdsec-cli/support.go rename to cmd/crowdsec-cli/clisupport/support.go index c48c84668ea..55f0ec4b03e 100644 --- a/cmd/crowdsec-cli/support.go +++ b/cmd/crowdsec-cli/clisupport/support.go @@ -1,4 +1,4 @@ -package main +package clisupport import ( "archive/zip" @@ -22,9 +22,11 @@ import ( "github.com/crowdsecurity/go-cs-lib/trace" + "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clibouncer" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clicapi" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clihub" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clilapi" + "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/climachine" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/climetrics" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require" "github.com/crowdsecurity/crowdsec/pkg/csconfig" @@ -165,15 +167,15 @@ func (cli *cliSupport) dumpOSInfo(zw *zip.Writer) error { } func (cli *cliSupport) dumpHubItems(zw *zip.Writer, hub *cwhub.Hub) error { + log.Infof("Collecting hub") + if hub == nil { return errors.New("no hub connection") } - log.Infof("Collecting hub") - out := new(bytes.Buffer) - ch := clihub.New(cli.cfg) + if err := ch.List(out, hub, false); err != nil { return err } @@ -193,10 +195,9 @@ func (cli *cliSupport) dumpBouncers(zw *zip.Writer, db *database.Client) error { } out := new(bytes.Buffer) + cm := clibouncer.New(cli.cfg) - // call the "cscli bouncers list" command directly, skip any preRun - cm := cliBouncers{db: db, cfg: cli.cfg} - if err := cm.list(out); err != nil { + if err := cm.List(out, db); err != nil { return err } @@ -215,10 +216,9 @@ func (cli *cliSupport) dumpAgents(zw *zip.Writer, db *database.Client) error { } out := new(bytes.Buffer) + cm := climachine.New(cli.cfg) - // call the "cscli machines list" command directly, skip any preRun - cm := cliMachines{db: db, cfg: cli.cfg} - if err := cm.list(out); err != nil { + if err := cm.List(out, db); err != nil { return err } @@ -232,22 +232,17 @@ func (cli *cliSupport) dumpAgents(zw *zip.Writer, db *database.Client) error { func (cli *cliSupport) dumpLAPIStatus(zw *zip.Writer, hub *cwhub.Hub) error { log.Info("Collecting LAPI status") - cfg := cli.cfg() - cred := cfg.API.Client.Credentials - out := new(bytes.Buffer) + cl := clilapi.New(cli.cfg) - fmt.Fprintf(out, "LAPI credentials file: %s\n", cfg.API.Client.CredentialsFilePath) - fmt.Fprintf(out, "LAPI URL: %s\n", cred.URL) - fmt.Fprintf(out, "LAPI username: %s\n", cred.Login) - - if err := clilapi.QueryLAPIStatus(hub, cred.URL, cred.Login, cred.Password); err != nil { - return fmt.Errorf("could not authenticate to Local API (LAPI): %w", err) + err := cl.Status(out, hub) + if err != nil { + fmt.Fprintf(out, "%s\n", err) } - fmt.Fprintln(out, "You can successfully interact with Local API (LAPI)") + stripped := stripAnsiString(out.String()) - cli.writeToZip(zw, SUPPORT_LAPI_STATUS_PATH, time.Now(), out) + cli.writeToZip(zw, SUPPORT_LAPI_STATUS_PATH, time.Now(), strings.NewReader(stripped)) return nil } @@ -255,28 +250,17 @@ func (cli *cliSupport) dumpLAPIStatus(zw *zip.Writer, hub *cwhub.Hub) error { func (cli *cliSupport) dumpCAPIStatus(zw *zip.Writer, hub *cwhub.Hub) error { log.Info("Collecting CAPI status") - cfg := cli.cfg() - cred := cfg.API.Server.OnlineClient.Credentials - out := new(bytes.Buffer) + cc := clicapi.New(cli.cfg) - fmt.Fprintf(out, "CAPI credentials file: %s\n", cfg.API.Server.OnlineClient.CredentialsFilePath) - fmt.Fprintf(out, "CAPI URL: %s\n", cred.URL) - fmt.Fprintf(out, "CAPI username: %s\n", cred.Login) - - auth, enrolled, err := clicapi.QueryCAPIStatus(hub, cred.URL, cred.Login, cred.Password) + err := cc.Status(out, hub) if err != nil { - return fmt.Errorf("could not authenticate to Central API (CAPI): %w", err) - } - if auth { - fmt.Fprintln(out, "You can successfully interact with Central API (CAPI)") + fmt.Fprintf(out, "%s\n", err) } - if enrolled { - fmt.Fprintln(out, "Your instance is enrolled in the console") - } + stripped := stripAnsiString(out.String()) - cli.writeToZip(zw, SUPPORT_CAPI_STATUS_PATH, time.Now(), out) + cli.writeToZip(zw, SUPPORT_CAPI_STATUS_PATH, time.Now(), strings.NewReader(stripped)) return nil } @@ -389,11 +373,13 @@ func (cli *cliSupport) dumpCrash(zw *zip.Writer) error { return nil } +type configGetter func() *csconfig.Config + type cliSupport struct { cfg configGetter } -func NewCLISupport(cfg configGetter) *cliSupport { +func New(cfg configGetter) *cliSupport { return &cliSupport{ cfg: cfg, } diff --git a/cmd/crowdsec-cli/main.go b/cmd/crowdsec-cli/main.go index 2153ebfb7bb..2a1f5ac7ebe 100644 --- a/cmd/crowdsec-cli/main.go +++ b/cmd/crowdsec-cli/main.go @@ -14,17 +14,20 @@ import ( "github.com/crowdsecurity/go-cs-lib/trace" + "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clibouncer" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clicapi" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cliconsole" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cliexplain" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clihub" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clihubtest" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clilapi" + "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/climachine" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/climetrics" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clinotifications" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clipapi" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clisetup" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clisimulation" + "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clisupport" "github.com/crowdsecurity/crowdsec/pkg/csconfig" "github.com/crowdsecurity/crowdsec/pkg/fflag" ) @@ -256,8 +259,8 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall cmd.AddCommand(NewCLIDecisions(cli.cfg).NewCommand()) cmd.AddCommand(NewCLIAlerts(cli.cfg).NewCommand()) cmd.AddCommand(clisimulation.New(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLIBouncers(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLIMachines(cli.cfg).NewCommand()) + cmd.AddCommand(clibouncer.New(cli.cfg).NewCommand()) + cmd.AddCommand(climachine.New(cli.cfg).NewCommand()) cmd.AddCommand(clicapi.New(cli.cfg).NewCommand()) cmd.AddCommand(clilapi.New(cli.cfg).NewCommand()) cmd.AddCommand(NewCompletionCmd()) @@ -265,7 +268,7 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall cmd.AddCommand(cliexplain.New(cli.cfg, ConfigFilePath).NewCommand()) cmd.AddCommand(clihubtest.New(cli.cfg).NewCommand()) cmd.AddCommand(clinotifications.New(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLISupport(cli.cfg).NewCommand()) + cmd.AddCommand(clisupport.New(cli.cfg).NewCommand()) cmd.AddCommand(clipapi.New(cli.cfg).NewCommand()) cmd.AddCommand(NewCLICollection(cli.cfg).NewCommand()) cmd.AddCommand(NewCLIParser(cli.cfg).NewCommand()) diff --git a/test/bats/01_cscli.bats b/test/bats/01_cscli.bats index 27cfe53212b..bda2362c02a 100644 --- a/test/bats/01_cscli.bats +++ b/test/bats/01_cscli.bats @@ -213,9 +213,9 @@ teardown() { rune -0 ./instance-crowdsec start rune -0 cscli lapi status - assert_stderr --partial "Loaded credentials from" - assert_stderr --partial "Trying to authenticate with username" - assert_stderr --partial "You can successfully interact with Local API (LAPI)" + assert_output --partial "Loaded credentials from" + assert_output --partial "Trying to authenticate with username" + assert_output --partial "You can successfully interact with Local API (LAPI)" } @test "cscli - missing LAPI credentials file" { @@ -260,7 +260,7 @@ teardown() { rune -0 ./instance-crowdsec start rune -0 cscli lapi status - assert_stderr --partial "You can successfully interact with Local API (LAPI)" + assert_output --partial "You can successfully interact with Local API (LAPI)" rm "$LOCAL_API_CREDENTIALS".local @@ -272,7 +272,7 @@ teardown() { config_set "$LOCAL_API_CREDENTIALS" '.password="$PASSWORD"' rune -0 cscli lapi status - assert_stderr --partial "You can successfully interact with Local API (LAPI)" + assert_output --partial "You can successfully interact with Local API (LAPI)" # but if a variable is not defined, there is no specific error message unset URL @@ -299,7 +299,7 @@ teardown() { rune -1 cscli lapi status -o json rune -0 jq -r '.msg' <(stderr) - assert_output 'failed to authenticate to Local API (LAPI): parsing api url: parse "http://127.0.0.1:-80/": invalid port ":-80" after host' + assert_output 'failed to authenticate to Local API (LAPI): parse "http://127.0.0.1:-80/": invalid port ":-80" after host' } @test "cscli - bad LAPI password" { diff --git a/test/bats/03_noagent.bats b/test/bats/03_noagent.bats index 60731b90713..6be5101cee2 100644 --- a/test/bats/03_noagent.bats +++ b/test/bats/03_noagent.bats @@ -76,7 +76,7 @@ teardown() { config_disable_agent ./instance-crowdsec start rune -0 cscli lapi status - assert_stderr --partial "You can successfully interact with Local API (LAPI)" + assert_output --partial "You can successfully interact with Local API (LAPI)" } @test "cscli metrics" { diff --git a/test/bats/04_capi.bats b/test/bats/04_capi.bats index 830d0668cbb..f17ce376d62 100644 --- a/test/bats/04_capi.bats +++ b/test/bats/04_capi.bats @@ -55,10 +55,10 @@ setup() { rune -0 cscli scenarios install crowdsecurity/ssh-bf rune -0 cscli capi status - assert_stderr --partial "Loaded credentials from" - assert_stderr --partial "Trying to authenticate with username" - assert_stderr --partial " on https://api.crowdsec.net/" - assert_stderr --partial "You can successfully interact with Central API (CAPI)" + assert_output --partial "Loaded credentials from" + assert_output --partial "Trying to authenticate with username" + assert_output --partial " on https://api.crowdsec.net/" + assert_output --partial "You can successfully interact with Central API (CAPI)" } @test "cscli alerts list: receive a community pull when capi is enabled" { @@ -85,7 +85,7 @@ setup() { config_disable_agent ./instance-crowdsec start rune -0 cscli capi status - assert_stderr --partial "You can successfully interact with Central API (CAPI)" + assert_output --partial "You can successfully interact with Central API (CAPI)" } @test "capi register must be run from lapi" { diff --git a/test/bats/04_nocapi.bats b/test/bats/04_nocapi.bats index c02a75810b9..d22a6f0a953 100644 --- a/test/bats/04_nocapi.bats +++ b/test/bats/04_nocapi.bats @@ -66,7 +66,7 @@ teardown() { config_disable_capi ./instance-crowdsec start rune -0 cscli lapi status - assert_stderr --partial "You can successfully interact with Local API (LAPI)" + assert_output --partial "You can successfully interact with Local API (LAPI)" } @test "cscli metrics" { diff --git a/test/bats/09_socket.bats b/test/bats/09_socket.bats index f770abaad2e..f861d8a40dc 100644 --- a/test/bats/09_socket.bats +++ b/test/bats/09_socket.bats @@ -37,22 +37,22 @@ teardown() { ./instance-crowdsec start rune -0 cscli lapi status - assert_stderr --regexp "Trying to authenticate with username .* on $socket" - assert_stderr --partial "You can successfully interact with Local API (LAPI)" + assert_output --regexp "Trying to authenticate with username .* on $socket" + assert_output --partial "You can successfully interact with Local API (LAPI)" } @test "crowdsec - listen on both socket and TCP" { ./instance-crowdsec start rune -0 cscli lapi status - assert_stderr --regexp "Trying to authenticate with username .* on http://127.0.0.1:8080/" - assert_stderr --partial "You can successfully interact with Local API (LAPI)" + assert_output --regexp "Trying to authenticate with username .* on http://127.0.0.1:8080/" + assert_output --partial "You can successfully interact with Local API (LAPI)" config_set "$LOCAL_API_CREDENTIALS" ".url=strenv(socket)" rune -0 cscli lapi status - assert_stderr --regexp "Trying to authenticate with username .* on $socket" - assert_stderr --partial "You can successfully interact with Local API (LAPI)" + assert_output --regexp "Trying to authenticate with username .* on $socket" + assert_output --partial "You can successfully interact with Local API (LAPI)" } @test "cscli - authenticate new machine with socket" {