mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-11-09 12:21:25 -10:00
* chore(deps): strip dependencies Signed-off-by: Dwi Siswanto <[email protected]> * chore: drop stripped dependencies Signed-off-by: Dwi Siswanto <[email protected]> * tests(integration): reduce external service flakiness Signed-off-by: Dwi Siswanto <[email protected]> * refactor(types): replace govalidator ASCII check Signed-off-by: Dwi Siswanto <[email protected]> * chore(trackers): update go-github import path Signed-off-by: Dwi Siswanto <[email protected]> * chore: use our PD wrapper Signed-off-by: Dwi Siswanto <[email protected]> * chore: use our PD cache packages Signed-off-by: Dwi Siswanto <[email protected]> * chore(utils): use x/net publicsuffix Signed-off-by: Dwi Siswanto <[email protected]> * chore(input): decode YAML without invopop/yaml Signed-off-by: Dwi Siswanto <[email protected]> * refactor(yaml): route callers through pkg/utils/yaml Signed-off-by: Dwi Siswanto <[email protected]> * refactor(json): route callers through pkg/utils/json Signed-off-by: Dwi Siswanto <[email protected]> * refactpr(scan): replace Echo handlers with net/http Signed-off-by: Dwi Siswanto <[email protected]> * refactor(server): replace Echo with net/http Signed-off-by: Dwi Siswanto <[email protected]> * refactor(fuzzplayground): replace Echo server with net/http Signed-off-by: Dwi Siswanto <[email protected]> * test: update subdomains testdata Signed-off-by: Dwi Siswanto <[email protected]> * chore(yaml): satisfy lints Signed-off-by: Dwi Siswanto <[email protected]> * fix codeql --------- Signed-off-by: Dwi Siswanto <[email protected]> Co-authored-by: Mzack9999 <[email protected]>
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package json
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type logRequestShape struct {
|
|
Template string `json:"template"`
|
|
Type string `json:"type"`
|
|
Input string `json:"input"`
|
|
Timestamp *string `json:"timestamp,omitempty"`
|
|
Address string `json:"address"`
|
|
Error string `json:"error"`
|
|
Kind string `json:"kind,omitempty"`
|
|
Attrs interface{} `json:"attrs,omitempty"`
|
|
}
|
|
|
|
func TestMarshalPreservesStructFieldOutputShape(t *testing.T) {
|
|
output, err := Marshal(logRequestShape{
|
|
Template: "path",
|
|
Type: "http",
|
|
Input: "input",
|
|
Address: "input:",
|
|
Error: "none",
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, `{"template":"path","type":"http","input":"input","address":"input:","error":"none"}`, string(output))
|
|
}
|
|
|
|
func TestEncoderAddsTrailingNewline(t *testing.T) {
|
|
var buffer bytes.Buffer
|
|
err := NewEncoder(&buffer).Encode(logRequestShape{
|
|
Template: "path",
|
|
Type: "http",
|
|
Input: "input",
|
|
Address: "input:",
|
|
Error: "none",
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, "{\"template\":\"path\",\"type\":\"http\",\"input\":\"input\",\"address\":\"input:\",\"error\":\"none\"}\n", buffer.String())
|
|
}
|
|
|
|
func TestMarshalEscapesHTML(t *testing.T) {
|
|
output, err := Marshal(map[string]string{"value": "<tag>&"})
|
|
require.NoError(t, err)
|
|
require.Equal(t, `{"value":"\u003ctag\u003e\u0026"}`, string(output))
|
|
}
|
|
|
|
func TestMapRoundTripPreservesDecodedValues(t *testing.T) {
|
|
output, err := Marshal(map[string]interface{}{
|
|
"foo": "bar",
|
|
"number": float64(2),
|
|
"nested": map[string]interface{}{"ok": true},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
var decoded map[string]interface{}
|
|
require.NoError(t, Unmarshal(output, &decoded))
|
|
require.Equal(t, "bar", decoded["foo"])
|
|
require.Equal(t, float64(2), decoded["number"])
|
|
require.Equal(t, map[string]interface{}{"ok": true}, decoded["nested"])
|
|
}
|