@@ -2,9 +2,11 @@ package main
2
2
3
3
import (
4
4
"fmt"
5
+ "maps"
5
6
"os"
6
7
"path/filepath"
7
8
"regexp"
9
+ "slices"
8
10
"strings"
9
11
10
12
"github.com/hashicorp/go-multierror"
@@ -16,9 +18,36 @@ import (
16
18
17
19
"github.com/wallarm/gotestwaf/internal/config"
18
20
"github.com/wallarm/gotestwaf/internal/helpers"
21
+ "github.com/wallarm/gotestwaf/internal/report"
19
22
"github.com/wallarm/gotestwaf/internal/version"
20
23
)
21
24
25
+ const (
26
+ textLogFormat = "text"
27
+ jsonLogFormat = "json"
28
+ )
29
+
30
+ var (
31
+ logFormatsSet = map [string ]any {
32
+ textLogFormat : nil ,
33
+ jsonLogFormat : nil ,
34
+ }
35
+ logFormats = slices .Collect (maps .Keys (logFormatsSet ))
36
+ )
37
+
38
+ const (
39
+ chromeClient = "chrome"
40
+ gohttpClient = "gohttp"
41
+ )
42
+
43
+ var (
44
+ httpClientsSet = map [string ]any {
45
+ chromeClient : nil ,
46
+ gohttpClient : nil ,
47
+ }
48
+ httpClients = slices .Collect (maps .Keys (httpClientsSet ))
49
+ )
50
+
22
51
const (
23
52
maxReportFilenameLength = 249 // 255 (max length) - 5 (".html") - 1 (to be sure)
24
53
@@ -28,19 +57,16 @@ const (
28
57
defaultConfigPath = "config.yaml"
29
58
30
59
wafName = "generic"
60
+ )
31
61
32
- textLogFormat = "text"
33
- jsonLogFormat = "json"
34
-
35
- cliDescription = `GoTestWAF is a tool for API and OWASP attack simulation that supports a
62
+ const cliDescription = `GoTestWAF is a tool for API and OWASP attack simulation that supports a
36
63
wide range of API protocols including REST, GraphQL, gRPC, SOAP, XMLRPC, and others.
37
64
Homepage: https://github.com/wallarm/gotestwaf
38
65
39
66
Usage: %s [OPTIONS] --url <URL>
40
67
41
68
Options:
42
69
`
43
- )
44
70
45
71
var (
46
72
configPath string
@@ -69,7 +95,7 @@ func parseFlags() (args []string, err error) {
69
95
flag .StringVar (& configPath , "configPath" , defaultConfigPath , "Path to the config file" )
70
96
flag .BoolVar (& quiet , "quiet" , false , "If true, disable verbose logging" )
71
97
logLvl := flag .String ("logLevel" , "info" , "Logging level: panic, fatal, error, warn, info, debug, trace" )
72
- flag .StringVar (& logFormat , "logFormat" , textLogFormat , "Set logging format: text, json" )
98
+ flag .StringVar (& logFormat , "logFormat" , textLogFormat , "Set logging format: " + strings . Join ( logFormats , ", " ) )
73
99
showVersion := flag .Bool ("version" , false , "Show GoTestWAF version and exit" )
74
100
75
101
// Target settings
@@ -84,7 +110,7 @@ func parseFlags() (args []string, err error) {
84
110
flag .String ("testSet" , "" , "If set then only this test set's cases will be run" )
85
111
86
112
// HTTP client settings
87
- httpClient := flag .String ("httpClient" , "gohttp" , "Which HTTP client use to send requests: chrome, gohttp" )
113
+ httpClient := flag .String ("httpClient" , gohttpClient , "Which HTTP client use to send requests: " + strings . Join ( httpClients , ", " ) )
88
114
flag .Bool ("tlsVerify" , false , "If true, the received TLS certificate will be verified" )
89
115
flag .String ("proxy" , "" , "Proxy URL to use" )
90
116
flag .String ("addHeader" , "" , "An HTTP header to add to requests" )
@@ -121,7 +147,7 @@ func parseFlags() (args []string, err error) {
121
147
flag .Bool ("includePayloads" , false , "If true, payloads will be included in HTML/PDF report" )
122
148
flag .String ("reportPath" , reportPath , "A directory to store reports" )
123
149
reportName := flag .String ("reportName" , defaultReportName , "Report file name. Supports `time' package template format" )
124
- flag .String ("reportFormat" , "pdf" , "Export report to one of the following formats: none, pdf, html, json" )
150
+ reportFormat := flag .StringSlice ("reportFormat" , [] string { report . PdfFormat } , "Export report in the following formats: " + strings . Join ( report . ReportFormats , ", " ) )
125
151
noEmailReport := flag .Bool ("noEmailReport" , false , "Save report locally" )
126
152
email := flag .String ("email" , "" , "E-mail to which the report will be sent" )
127
153
@@ -166,8 +192,16 @@ func parseFlags() (args []string, err error) {
166
192
}
167
193
logLevel = logrusLogLvl
168
194
169
- if logFormat != textLogFormat && logFormat != jsonLogFormat {
170
- return nil , fmt .Errorf ("unknown logging format: %s" , logFormat )
195
+ if err = validateLogFormat (logFormat ); err != nil {
196
+ return nil , err
197
+ }
198
+
199
+ if err = validateHttpClient (* httpClient ); err != nil {
200
+ return nil , err
201
+ }
202
+
203
+ if err = report .ValidateReportFormat (* reportFormat ); err != nil {
204
+ return nil , err
171
205
}
172
206
173
207
validURL , err := validateURL (* urlParam , httpProto )
@@ -261,6 +295,11 @@ func normalizeArgs() ([]string, error) {
261
295
262
296
arg = fmt .Sprintf ("--%s=%s" , f .Name , value )
263
297
298
+ case "stringSlice" :
299
+ // remove square brackets: [pdf,json] -> pdf,json
300
+ value = strings .Trim (f .Value .String (), "[]" )
301
+ arg = fmt .Sprintf ("--%s=%s" , f .Name , value )
302
+
264
303
case "bool" :
265
304
arg = fmt .Sprintf ("--%s" , f .Name )
266
305
0 commit comments