mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 09:55:25 +00:00
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
|
|
package runner
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/projectdiscovery/goflags"
|
||
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestParseHeadlessOptionalArguments(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
input string
|
||
|
|
want map[string]string
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "single value",
|
||
|
|
input: "a=b",
|
||
|
|
want: map[string]string{"a": "b"},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "empty string",
|
||
|
|
input: "",
|
||
|
|
want: map[string]string{},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "empty key",
|
||
|
|
input: "=b",
|
||
|
|
want: map[string]string{},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "empty value",
|
||
|
|
input: "a=",
|
||
|
|
want: map[string]string{},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "double input",
|
||
|
|
input: "a=b,c=d",
|
||
|
|
want: map[string]string{"a": "b", "c": "d"},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "duplicated input",
|
||
|
|
input: "a=b,a=b",
|
||
|
|
want: map[string]string{"a": "b"},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
strsl := goflags.StringSlice{}
|
||
|
|
for _, v := range strings.Split(tt.input, ",") {
|
||
|
|
//nolint
|
||
|
|
strsl.Set(v)
|
||
|
|
}
|
||
|
|
opt := types.Options{HeadlessOptionalArguments: strsl}
|
||
|
|
got := opt.ParseHeadlessOptionalArguments()
|
||
|
|
require.Equal(t, tt.want, got)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|