mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 23:05:26 +00:00
* perf(*): replace `encoding/json` w/ sonic Signed-off-by: Dwi Siswanto <git@dw1.io> * feat(utils): add `json` pkg (sonic wrapper) Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(*): use `sonic` wrapper instead Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(*): replace `sonic.ConfigStd` -> `json` (wrapper) Signed-off-by: Dwi Siswanto <git@dw1.io> * test(model): adjust expected marshal'd JSON Signed-off-by: Dwi Siswanto <git@dw1.io> * feat(json): dynamic backend; `sonic` -> `go-json` (fallback) Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(json): merge config - as its not usable Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(json): rm go version constraints Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: go mod tidy Signed-off-by: Dwi Siswanto <git@dw1.io> --------- Signed-off-by: Dwi Siswanto <git@dw1.io>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package variables
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/utils/json"
|
|
"github.com/stretchr/testify/require"
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
func TestVariablesEvaluate(t *testing.T) {
|
|
data := `a2: "{{md5('test')}}"
|
|
a3: "this_is_random_text"
|
|
a4: "{{date_time('%Y-%M-%D')}}"
|
|
a5: "{{reverse(hostname)}}"
|
|
a6: "123456"`
|
|
|
|
variables := Variable{}
|
|
err := yaml.Unmarshal([]byte(data), &variables)
|
|
require.NoError(t, err, "could not unmarshal variables")
|
|
|
|
result := variables.Evaluate(map[string]interface{}{"hostname": "google.com"})
|
|
a4 := time.Now().Format("2006-01-02")
|
|
require.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")
|
|
|
|
// json
|
|
data = `{
|
|
"a2": "{{md5('test')}}",
|
|
"a3": "this_is_random_text",
|
|
"a4": "{{date_time('%Y-%M-%D')}}",
|
|
"a5": "{{reverse(hostname)}}",
|
|
"a6": "123456"
|
|
}`
|
|
variables = Variable{}
|
|
err = json.Unmarshal([]byte(data), &variables)
|
|
require.NoError(t, err, "could not unmarshal json variables")
|
|
|
|
result = variables.Evaluate(map[string]interface{}{"hostname": "google.com"})
|
|
a4 = time.Now().Format("2006-01-02")
|
|
require.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")
|
|
|
|
}
|