2021-02-24 12:07:16 +05:30
|
|
|
package expressions
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestEvaluate(t *testing.T) {
|
|
|
|
|
items := []struct {
|
|
|
|
|
input string
|
|
|
|
|
expected string
|
|
|
|
|
extra map[string]interface{}
|
|
|
|
|
}{
|
2022-01-09 12:52:04 +01:00
|
|
|
{input: "{{url_encode('test}aaa')}}", expected: "test%7Daaa", extra: map[string]interface{}{}},
|
2021-02-24 12:07:16 +05:30
|
|
|
{input: "{{hex_encode('PING')}}", expected: "50494e47", extra: map[string]interface{}{}},
|
2022-01-17 13:32:15 +02:00
|
|
|
// TODO #1501
|
|
|
|
|
//{input: "{{hex_encode('{{')}}", expected: "7b7b", extra: map[string]interface{}{}},
|
|
|
|
|
//{input: `{{concat("{{", 123, "*", 123, "}}")}}`, expected: "{{123*123}}", extra: map[string]interface{}{}},
|
|
|
|
|
//{input: `{{concat("{{", "123*123", "}}")}}`, expected: "{{123*123}}", extra: map[string]interface{}{}},
|
2022-01-17 14:04:09 +02:00
|
|
|
//{input: `{{"{{" + '123*123' + "}}"}}`, expected: "{{123*123}}", extra: map[string]interface{}{}},
|
2022-01-17 13:32:15 +02:00
|
|
|
{input: `{{concat(123,'*',123)}}`, expected: "123*123", extra: map[string]interface{}{}},
|
|
|
|
|
{input: `{{1+1}}`, expected: "2", extra: map[string]interface{}{}},
|
2022-01-17 14:04:09 +02:00
|
|
|
{input: `{{"1"+"1"}}`, expected: "11", extra: map[string]interface{}{}},
|
|
|
|
|
{input: `{{"1" + '*' + "1"}}`, expected: "1*1", extra: map[string]interface{}{}},
|
|
|
|
|
{input: `{{"a" + 'b' + "c"}}`, expected: "abc", extra: map[string]interface{}{}},
|
2022-01-17 13:32:15 +02:00
|
|
|
{input: `{{10*2}}`, expected: "20", extra: map[string]interface{}{}},
|
|
|
|
|
{input: `{{10/2}}`, expected: "5", extra: map[string]interface{}{}},
|
|
|
|
|
{input: `{{10-2}}`, expected: "8", extra: map[string]interface{}{}},
|
2021-02-24 12:07:16 +05:30
|
|
|
{input: "test", expected: "test", extra: map[string]interface{}{}},
|
|
|
|
|
{input: "{{hex_encode(Item)}}", expected: "50494e47", extra: map[string]interface{}{"Item": "PING"}},
|
2021-02-24 20:11:21 +05:30
|
|
|
{input: "{{hex_encode(Item)}}\r\n", expected: "50494e47\r\n", extra: map[string]interface{}{"Item": "PING"}},
|
2021-02-26 13:31:10 +05:30
|
|
|
{input: "{{someTestData}}{{hex_encode('PING')}}", expected: "{{someTestData}}50494e47", extra: map[string]interface{}{}},
|
2021-03-05 19:25:09 +05:30
|
|
|
{input: `_IWP_JSON_PREFIX_{{base64("{\"iwp_action\":\"add_site\",\"params\":{\"username\":\"\"}}")}}`, expected: "_IWP_JSON_PREFIX_eyJpd3BfYWN0aW9uIjoiYWRkX3NpdGUiLCJwYXJhbXMiOnsidXNlcm5hbWUiOiIifX0=", extra: map[string]interface{}{}},
|
2022-01-09 12:52:04 +01:00
|
|
|
{input: "{{}}", expected: "{{}}", extra: map[string]interface{}{}},
|
|
|
|
|
{input: `"{{hex_encode('PING')}}"`, expected: `"50494e47"`, extra: map[string]interface{}{}},
|
2021-02-24 12:07:16 +05:30
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
|
}
|
|
|
|
|
}
|