Harden scan robustness and tests

This commit is contained in:
ZacharyZcR
2026-06-14 22:23:48 +08:00
parent 5ad914a1bb
commit c49c23c7f0
100 changed files with 4483 additions and 412 deletions
+33
View File
@@ -0,0 +1,33 @@
package portfinger
import "testing"
func TestProbeParserRejectsShortInputs(t *testing.T) {
tests := []string{
"",
"T",
"TCP",
"TCP ",
"TCP Q",
"TCP GetRequest q",
}
for _, input := range tests {
t.Run(input, func(t *testing.T) {
var probe Probe
if err := probe.fromString(input); err == nil {
t.Fatalf("fromString(%q) error = nil, want malformed input error", input)
}
})
}
}
func TestProbeParserAcceptsMinimalValidProbe(t *testing.T) {
var probe Probe
if err := probe.fromString(`TCP GetRequest q|GET / HTTP/1.0\r\n\r\n|`); err != nil {
t.Fatalf("fromString valid probe error = %v", err)
}
if probe.Name != "GetRequest" || probe.Protocol != "tcp" || probe.Data == "" {
t.Fatalf("probe parsed incorrectly: %#v", probe)
}
}