mirror of https://github.com/daffainfo/nuclei.git
add unit test
parent
27fefe59d3
commit
46c0822ee4
|
@ -62,6 +62,7 @@ require (
|
|||
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.2
|
||||
github.com/docker/go-units v0.5.0
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/go-faker/faker/v4 v4.0.0
|
||||
github.com/go-git/go-git/v5 v5.5.2
|
||||
github.com/h2non/filetype v1.1.3
|
||||
github.com/hashicorp/go-version v1.6.0
|
||||
|
|
|
@ -396,6 +396,8 @@ github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4x
|
|||
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
|
||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||
github.com/go-faker/faker/v4 v4.0.0 h1:tfgFaeizVlYGOS1tVo/vcWcKhkNgG1NWm8ibRG0f+aQ=
|
||||
github.com/go-faker/faker/v4 v4.0.0/go.mod h1:uuNc0PSRxF8nMgjGrrrU4Nw5cF30Jc6Kd0/FUTTYbhg=
|
||||
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
|
||||
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
|
||||
github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
|
||||
|
|
|
@ -3,7 +3,6 @@ package templates
|
|||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -11,10 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func TestTemplateStruct(t *testing.T) {
|
||||
// Unit test to check/validate template Marshal/Unmarshal
|
||||
// load a test template
|
||||
home, _ := os.UserHomeDir()
|
||||
templatePath := filepath.Join(home, "nuclei-templates", "fuzzing/valid-gmail-check.yaml")
|
||||
templatePath := "./tests/match-1.yaml"
|
||||
bin, err := os.ReadFile(templatePath)
|
||||
require.Nil(t, err, "failed to load example template")
|
||||
var yamlTemplate Template
|
||||
|
@ -25,4 +21,16 @@ func TestTemplateStruct(t *testing.T) {
|
|||
var jsonTemplate Template
|
||||
err = json.Unmarshal(jsonBin, &jsonTemplate)
|
||||
require.Nil(t, err, "failed to unmarshal json template")
|
||||
|
||||
templatePath = "./tests/json-template.json"
|
||||
bin, err = os.ReadFile(templatePath)
|
||||
require.Nil(t, err, "failed to load example template")
|
||||
jsonTemplate = Template{}
|
||||
err = json.Unmarshal(bin, &jsonTemplate)
|
||||
require.Nil(t, err, "failed to unmarshal json template")
|
||||
yamlBin, err := yaml.Marshal(jsonTemplate)
|
||||
require.Nil(t, err, "failed to marshal template to yaml")
|
||||
yamlTemplate = Template{}
|
||||
err = yaml.Unmarshal(yamlBin, &yamlTemplate)
|
||||
require.Nil(t, err, "failed to unmarshal yaml template")
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"id": "go-integration-test",
|
||||
"info": {
|
||||
"name": "Basic Go Integration Test",
|
||||
"author": "pdteam",
|
||||
"severity": "info"
|
||||
},
|
||||
"requests": [
|
||||
{
|
||||
"method": "GET",
|
||||
"path": [
|
||||
"{{BaseURL}}"
|
||||
],
|
||||
"headers": {
|
||||
"test": "nuclei"
|
||||
},
|
||||
"matchers": [
|
||||
{
|
||||
"type": "word",
|
||||
"words": [
|
||||
"This is test headers matcher text"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue