mirror of https://github.com/daffainfo/nuclei.git
adds missing json tags and unit test
parent
10693efa05
commit
8cdc1338fc
|
@ -113,7 +113,7 @@ func (severityHolder *Holder) UnmarshalJSON(data []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (severityHolder *Holder) MarshalJSON() ([]byte, error) {
|
||||
func (severityHolder Holder) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(severityHolder.Severity.String())
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ type Extractor struct {
|
|||
|
||||
// description: |
|
||||
// Extracts using DSL expressions.
|
||||
DSL []string `yaml:"dsl,omitempty" jsonschema:"title=dsl expressions to extract,description=Optional attribute to extract from response dsl"`
|
||||
DSL []string `yaml:"dsl,omitempty" json:"dsl,omitempty" jsonschema:"title=dsl expressions to extract,description=Optional attribute to extract from response dsl"`
|
||||
dslCompiled []*govaluate.EvaluableExpression
|
||||
|
||||
// description: |
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
// Request contains a http request to be made from a template
|
||||
type Request struct {
|
||||
// Operators for the current request go here.
|
||||
operators.Operators `yaml:",inline"`
|
||||
operators.Operators `yaml:",inline" json:",inline"`
|
||||
// description: |
|
||||
// Path contains the path/s for the HTTP requests. It supports variables
|
||||
// as placeholders.
|
||||
|
|
|
@ -1 +1,28 @@
|
|||
package templates
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
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")
|
||||
bin, err := os.ReadFile(templatePath)
|
||||
require.Nil(t, err, "failed to load example template")
|
||||
var yamlTemplate Template
|
||||
err = yaml.Unmarshal(bin, &yamlTemplate)
|
||||
require.Nil(t, err, "failed to unmarshal yaml template")
|
||||
jsonBin, err := json.Marshal(yamlTemplate)
|
||||
require.Nil(t, err, "failed to marshal template to json")
|
||||
var jsonTemplate Template
|
||||
err = json.Unmarshal(jsonBin, &jsonTemplate)
|
||||
require.Nil(t, err, "failed to unmarshal json template")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue