Path: blob/dev/pkg/protocols/common/variables/variables_test.go
2073 views
package variables12import (3"testing"4"time"56"github.com/projectdiscovery/nuclei/v3/pkg/utils/json"7"github.com/stretchr/testify/require"8"gopkg.in/yaml.v2"9)1011func TestVariablesEvaluate(t *testing.T) {12data := `a2: "{{md5('test')}}"13a3: "this_is_random_text"14a4: "{{date_time('%Y-%M-%D')}}"15a5: "{{reverse(hostname)}}"16a6: "123456"`1718variables := Variable{}19err := yaml.Unmarshal([]byte(data), &variables)20require.NoError(t, err, "could not unmarshal variables")2122result := variables.Evaluate(map[string]interface{}{"hostname": "google.com"})23a4 := time.Now().Format("2006-01-02")24require.Equal(t, map[string]interface{}{"a2": "098f6bcd4621d373cade4e832627b4f6", "a3": "this_is_random_text", "a4": a4, "a5": "moc.elgoog", "a6": "123456"}, result, "could not get correct elements")2526// json27data = `{28"a2": "{{md5('test')}}",29"a3": "this_is_random_text",30"a4": "{{date_time('%Y-%M-%D')}}",31"a5": "{{reverse(hostname)}}",32"a6": "123456"33}`34variables = Variable{}35err = json.Unmarshal([]byte(data), &variables)36require.NoError(t, err, "could not unmarshal json variables")3738result = variables.Evaluate(map[string]interface{}{"hostname": "google.com"})39a4 = time.Now().Format("2006-01-02")40require.Equal(t, map[string]interface{}{"a2": "098f6bcd4621d373cade4e832627b4f6", "a3": "this_is_random_text", "a4": a4, "a5": "moc.elgoog", "a6": "123456"}, result, "could not get correct elements")4142}434445