Skip to content

Commit

Permalink
Add interactive shell check (#230)
Browse files Browse the repository at this point in the history
* Vendor new dependecies

* Add new check for interactive shell
  • Loading branch information
svkirillov authored Feb 29, 2024
1 parent 45f26cd commit dd970c6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/sirupsen/logrus"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
"golang.org/x/crypto/ssh/terminal"

"github.com/wallarm/gotestwaf/internal/config"
"github.com/wallarm/gotestwaf/internal/helpers"
Expand Down Expand Up @@ -128,6 +129,16 @@ func parseFlags() (args []string, err error) {
return nil, errors.New("--url flag is not set")
}

if !terminal.IsTerminal(int(os.Stdin.Fd())) {
if *noEmailReport == false && *email == "" {
return nil, errors.New(
"GoTestWAF is running in a non-interactive session. " +
"Please use the '-it' flag if you are running GTW in Docker or use the " +
"'--email' (or '--noEmailReport') and '--includePayloads' ('true' or 'false') options",
)
}
}

if *noEmailReport == false && *email != "" {
*email, err = helpers.ValidateEmail(*email)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/sirupsen/logrus v1.9.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
golang.org/x/crypto v0.18.0
golang.org/x/net v0.17.0
golang.org/x/text v0.14.0
google.golang.org/grpc v1.59.0
Expand Down Expand Up @@ -49,7 +50,6 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
Expand Down
76 changes: 76 additions & 0 deletions vendor/golang.org/x/crypto/ssh/terminal/terminal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ github.com/subosito/gotenv
# golang.org/x/crypto v0.18.0
## explicit; go 1.18
golang.org/x/crypto/sha3
golang.org/x/crypto/ssh/terminal
# golang.org/x/net v0.17.0
## explicit; go 1.17
golang.org/x/net/http/httpguts
Expand Down

0 comments on commit dd970c6

Please sign in to comment.