@@ -2,7 +2,9 @@ package main
22
33import (
44 "flag"
5+ "fmt"
56 "os"
7+ "strings"
68 "time"
79
810 "github.com/OWASP/OFFAT/src/pkg/http"
@@ -28,14 +30,46 @@ type FlagConfig struct {
2830 BaseUrl * string
2931
3032 // HTTP
31- RequestsPerSecond * int
32- SkipTlsVerfication * bool
33+ RequestsPerSecond * int
34+ SkipTlsVerification * bool
35+ Headers KeyValueMap
36+ QueryParams KeyValueMap
3337
3438 // Report
3539 AvoidImmuneFilter * bool
3640 OutputFilePath * string
3741}
3842
43+ // Custom type for headers
44+ type KeyValueMap map [string ]string
45+
46+ // Implement the String method for headers
47+ func (h * KeyValueMap ) String () string {
48+ var keyValueList []string
49+ for k , v := range * h {
50+ keyValueList = append (keyValueList , fmt .Sprintf ("%s=%s" , k , v ))
51+ }
52+ return strings .Join (keyValueList , ", " )
53+ }
54+
55+ // Implement the Set method for headers
56+ func (h * KeyValueMap ) Set (value string ) error {
57+ if * h == nil {
58+ * h = make (KeyValueMap )
59+ }
60+
61+ parts := strings .SplitN (value , "=" , 2 )
62+ if len (parts ) != 2 {
63+ return fmt .Errorf ("invalid key value format, expected key=value but got %s" , value )
64+ }
65+ (* h )[parts [0 ]] = parts [1 ]
66+ return nil
67+ }
68+
69+ func (h * KeyValueMap ) ToMap () map [string ]string {
70+ return * h
71+ }
72+
3973func main () {
4074
4175 // Parse CLI args
@@ -50,7 +84,9 @@ func main() {
5084 config .DisableSchemaPatternValidation = flag .Bool ("dp" , false , "disable schema patterns validation for OAS files" )
5185
5286 config .RequestsPerSecond = flag .Int ("r" , 60 , "number of requests per second" )
53- config .SkipTlsVerfication = flag .Bool ("ns" , false , "disable TLS/SSL Verfication" )
87+ config .SkipTlsVerification = flag .Bool ("ns" , false , "disable TLS/SSL Verfication" )
88+ flag .Var (& config .Headers , "H" , "HTTP headers in the format key=value" )
89+ flag .Var (& config .QueryParams , "q" , "HTTP query parameter in the format key=value" )
5490
5591 config .OutputFilePath = flag .String ("o" , "output.json" , "JSON report output file path. default: output.json" )
5692 config .AvoidImmuneFilter = flag .Bool ("ai" , true , "does not filter immune endpoint from results if used" )
@@ -99,7 +135,7 @@ func main() {
99135 // log.Info().Msgf("%v", parser.Doc.GetDocHttpParams())
100136
101137 // http client
102- httpCfg := http .NewConfig (config .RequestsPerSecond , config .SkipTlsVerfication )
138+ httpCfg := http .NewConfig (config .RequestsPerSecond , config .SkipTlsVerification )
103139 hc := http .NewHttp (httpCfg )
104140
105141 url := * parser .Doc .GetBaseUrl ()
@@ -117,7 +153,9 @@ func main() {
117153
118154 // generate and run tests
119155 apiTestHandler := tgen.TGenHandler {
120- Doc : parser .Doc .GetDocHttpParams (),
156+ Doc : parser .Doc .GetDocHttpParams (),
157+ DefaultHeaders : config .Headers .ToMap (),
158+ DefaultQueryParams : config .QueryParams .ToMap (),
121159
122160 // Tests
123161 RunUnrestrictedHttpMethodTest : true ,
0 commit comments