Files
spray/core/format_test.go
T
M09IcandClaude Opus 4.6 729dee3d06 feat: enhance extract system with severity, context capture, matchers, and new rules
- parsers.Extracted: add Severity and Items (ExtractItem with ctx/line/offset)
- ProtonExtract: preserve severity from templates, capture N-char context around matches
- Add --extract-context CLI flag (default 0, e.g. --extract-context 50)
- Add word matchers pre-filtering to 14 existing templates for performance
- Add 9 new HaE-inspired rules: lfi-indicator, upload-form, url-as-value,
  location-redirect, mac-address, sensitive-field, linkfinder, url-schemes,
  authorization-header
- Total proton templates: 45 (was 35)
- Update ColorString/TreeString to render severity and context
- Comprehensive tests for severity, context, new templates, tag mappings

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-06-01 01:44:48 -07:00

40 lines
782 B
Go

package core
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
"github.com/chainreactors/logs"
)
func TestFormatParsesResultFile(t *testing.T) {
dir := t.TempDir()
input := filepath.Join(dir, "results.json")
content := `{"url":"http://127.0.0.1:80","host":"127.0.0.1","title":"home","status":200}
`
if err := os.WriteFile(input, []byte(content), 0o644); err != nil {
t.Fatal(err)
}
var out bytes.Buffer
oldLog := logs.Log
logs.Log = logs.NewLogger(oldLog.Level)
logs.Log.SetOutput(&out)
defer func() {
logs.Log = oldLog
}()
opt := Option{}
opt.Format = input
opt.OutputProbe = "url,title"
Format(opt)
if got := strings.TrimSpace(out.String()); got != "http://127.0.0.1:80\thome" {
t.Fatalf("unexpected formatted output: got %q", got)
}
}