mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-21 03:45:26 +00:00
* refactor(vardump): use `godump` lib also increate limit char to `255`. Signed-off-by: Dwi Siswanto <git@dw1.io> * feat(vardump): add global var `Limit` Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(protocols): rm newline Signed-off-by: Dwi Siswanto <git@dw1.io> * feat(types): add `VarDumpLimit` option Signed-off-by: Dwi Siswanto <git@dw1.io> * test(vardump): add test cases Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: tidy up mod Signed-off-by: Dwi Siswanto <git@dw1.io> --------- Signed-off-by: Dwi Siswanto <git@dw1.io>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package vardump
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestDumpVariables(t *testing.T) {
|
|
// Enable var dump for testing
|
|
EnableVarDump = true
|
|
|
|
// Test case
|
|
testVars := variables{
|
|
"string": "test",
|
|
"int": 42,
|
|
"bool": true,
|
|
"slice": []string{"a", "b", "c"},
|
|
}
|
|
|
|
result := DumpVariables(testVars)
|
|
|
|
// Assertions
|
|
assert.NotEmpty(t, result)
|
|
assert.Contains(t, result, "string")
|
|
assert.Contains(t, result, "test")
|
|
assert.Contains(t, result, "int")
|
|
assert.Contains(t, result, "42")
|
|
assert.Contains(t, result, "bool")
|
|
assert.Contains(t, result, "true")
|
|
assert.Contains(t, result, "slice")
|
|
assert.Contains(t, result, "a")
|
|
assert.Contains(t, result, "b")
|
|
assert.Contains(t, result, "c")
|
|
|
|
// Test with EnableVarDump set to false
|
|
EnableVarDump = false
|
|
result = DumpVariables(testVars)
|
|
assert.Empty(t, result)
|
|
}
|
|
|
|
func TestProcess(t *testing.T) {
|
|
testVars := variables{
|
|
"short": "short string",
|
|
"long": strings.Repeat("a", 300),
|
|
"number": 42,
|
|
}
|
|
|
|
processed := process(testVars, 255)
|
|
|
|
assert.Equal(t, "short string", processed["short"])
|
|
assert.Equal(t, strings.Repeat("a", 255)+" [...]", processed["long"])
|
|
assert.Equal(t, "42", processed["number"])
|
|
}
|