diff options
| author | Shulhan <ms@kilabit.info> | 2021-09-19 01:42:06 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-09-19 01:42:06 +0700 |
| commit | 29c3898ec03adaf7f6e1dd80f82d02b032f3979b (patch) | |
| tree | a3daf2eb6a79e1dd0c3de84970f013b01ba948e2 /example | |
| parent | 8fa18a28d3f378dba8b5fddf19021c9849b7de7e (diff) | |
| download | gorankusu-29c3898ec03adaf7f6e1dd80f82d02b032f3979b.tar.xz | |
all: add option to set description (Hint) on any inputs element
This changes refactor the KeyValue from map[string]string into
map[string]FormInput, where FormInput is a struct with Label, Hint,
Kind, Value, Max, and Min.
With the available of Hint field, the web user interface can render it
as description of input.
This changes also make all input hint to be displayed on the first render.
Diffstat (limited to 'example')
| -rw-r--r-- | example/example.go | 86 |
1 files changed, 67 insertions, 19 deletions
diff --git a/example/example.go b/example/example.go index 64d16a5..9ec156d 100644 --- a/example/example.go +++ b/example/example.go @@ -138,8 +138,12 @@ func (ex *Example) registerTargets() (err error) { Duration: 300 * time.Second, RatePerSecond: 1, }, - Vars: map[string]string{ - "A": "1", + Vars: trunks.KeyFormInput{ + "A": trunks.FormInput{ + Label: "A", + Kind: trunks.FormInputKindNumber, + Value: "1", + }, }, HttpTargets: []*trunks.HttpTarget{{ Name: "HTTP Get", @@ -147,11 +151,21 @@ func (ex *Example) registerTargets() (err error) { Method: libhttp.RequestMethodGet, Path: pathExample, RequestType: libhttp.RequestTypeQuery, - Headers: trunks.KeyValue{ - "X-Get": "1", + Headers: trunks.KeyFormInput{ + "X-Get": trunks.FormInput{ + Label: "X-Get", + Hint: "Custom HTTP header to be send.", + Kind: trunks.FormInputKindNumber, + Value: "1.1", + }, }, - Params: trunks.KeyValue{ - "Param1": "1", + Params: trunks.KeyFormInput{ + "Param1": trunks.FormInput{ + Label: "Param1", + Hint: "Parameter with number.", + Kind: trunks.FormInputKindNumber, + Value: "1", + }, }, Run: ex.runExampleGet, AllowAttack: true, @@ -163,12 +177,27 @@ func (ex *Example) registerTargets() (err error) { Method: libhttp.RequestMethodPost, Path: pathExample, RequestType: libhttp.RequestTypeForm, - Headers: trunks.KeyValue{ - "X-PostForm": "1", + Headers: trunks.KeyFormInput{ + "X-PostForm": trunks.FormInput{ + Label: "X-PostForm", + Hint: "Custom HTTP header to be send.", + Kind: trunks.FormInputKindNumber, + Value: "1", + }, }, - Params: trunks.KeyValue{ - "Param1": "1", - "Param2": "a string", + Params: trunks.KeyFormInput{ + "Param1": trunks.FormInput{ + Label: "Param1", + Hint: "Parameter with number.", + Kind: trunks.FormInputKindNumber, + Value: "1", + }, + "Param2": trunks.FormInput{ + Label: "Param2", + Hint: "Parameter with string.", + Kind: trunks.FormInputKindString, + Value: "a string", + }, }, Run: ex.runExamplePostForm, AllowAttack: true, @@ -180,11 +209,21 @@ func (ex *Example) registerTargets() (err error) { Method: libhttp.RequestMethodGet, Path: pathExample, RequestType: libhttp.RequestTypeForm, - Headers: trunks.KeyValue{ - "X-FreeForm": "1", + Headers: trunks.KeyFormInput{ + "X-FreeForm": trunks.FormInput{ + Label: "X-FreeForm", + Hint: "Custom HTTP header to be send.", + Kind: trunks.FormInputKindString, + Value: "1", + }, }, - Params: trunks.KeyValue{ - "Param1": "123", + Params: trunks.KeyFormInput{ + "Param1": trunks.FormInput{ + Label: "X-FreeForm", + Hint: "Parameter with number.", + Kind: trunks.FormInputKindNumber, + Value: "123", + }, }, IsCustomizable: true, }}, @@ -200,14 +239,23 @@ func (ex *Example) registerTargets() (err error) { Hint: "This section provide an example of WebSocket endpoints that can be tested.", BaseUrl: fmt.Sprintf("ws://%s", websocketAddress), Opts: &trunks.AttackOptions{}, - Vars: trunks.KeyValue{ - "WebSocketVar": "hello", + Vars: trunks.KeyFormInput{ + "WebSocketVar": trunks.FormInput{ + Label: "WebSocketVar", + Kind: trunks.FormInputKindString, + Value: "hello", + }, }, WebSocketTargets: []*trunks.WebSocketTarget{{ Name: "Similar to HTTP GET", Hint: "Test WebSocket endpoint with parameters.", - Params: trunks.KeyValue{ - "Param1": "123", + Params: trunks.KeyFormInput{ + "Param1": trunks.FormInput{ + Label: "Param1", + Hint: "Parameter with kind is number.", + Kind: "number", + Value: "123", + }, }, Run: ex.runWebSocketGet, }}, |
