From 29c3898ec03adaf7f6e1dd80f82d02b032f3979b Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 19 Sep 2021 01:42:06 +0700 Subject: 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. --- example/example.go | 86 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 19 deletions(-) (limited to 'example/example.go') 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, }}, -- cgit v1.3