nuclei/v2/pkg/protocols/common/expressions/expressions_test.go
Ice3man543 616ed342ed Misc
2021-02-26 14:45:48 +05:30

29 lines
1.1 KiB
Go

package expressions
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestEvaluate(t *testing.T) {
items := []struct {
input string
expected string
extra map[string]interface{}
}{
{input: "{{hex_encode('PING')}}", expected: "50494e47", extra: map[string]interface{}{}},
{input: "test", expected: "test", extra: map[string]interface{}{}},
{input: "{{hex_encode(Item)}}", expected: "50494e47", extra: map[string]interface{}{"Item": "PING"}},
{input: "{{hex_encode(Item)}}\r\n", expected: "50494e47\r\n", extra: map[string]interface{}{"Item": "PING"}},
{input: "{{someTestData}}{{hex_encode('PING')}}", expected: "{{someTestData}}50494e47", extra: map[string]interface{}{}},
// {input: `_IWP_JSON_PREFIX_{{base64('{"iwp_action":"add_site","params":{"username":""}}')}}`, expected: "_IWP_JSON_PREFIX_eyJpd3BfYWN0aW9uIjoiYWRkX3NpdGUiLCJwYXJhbXMiOnsidXNlcm5hbWUiOiIifX0=", extra: map[string]interface{}{}},
}
for _, item := range items {
value, err := Evaluate(item.input, item.extra)
require.Nil(t, err, "could not evaluate helper")
require.Equal(t, item.expected, value, "could not get correct expression")
}
}