MCPcopy Create free account
hub / github.com/devploit/nomore403 / TestOutputWriter_JSON

Function TestOutputWriter_JSON

cmd/output_test.go:73–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestOutputWriter_JSON(t *testing.T) {
74 dir := t.TempDir()
75 outPath := filepath.Join(dir, "output.json")
76
77 // Enable JSON mode
78 oldJSON := jsonOutput
79 jsonOutput = true
80 defer func() { jsonOutput = oldJSON }()
81
82 // Reset jsonResults
83 jsonResultsMutex.Lock()
84 jsonResults = nil
85 jsonResultsMutex.Unlock()
86
87 if err := initOutputWriter(outPath); err != nil {
88 t.Fatalf("initOutputWriter: %v", err)
89 }
90
91 writeResultToOutput(Result{line: "GET /admin", statusCode: 200, contentLength: 1234, score: 90, likelihood: "high", reproCurl: "curl ..."}, "verb-tampering")
92 writeResultToOutput(Result{line: "X-Forwarded-For: 127.0.0.1", statusCode: 403, contentLength: 500, score: 20, likelihood: "low"}, "headers")
93
94 closeOutputWriter()
95
96 data, err := os.ReadFile(outPath)
97 if err != nil {
98 t.Fatalf("read output: %v", err)
99 }
100
101 var results []JSONResult
102 if err := json.Unmarshal(data, &results); err != nil {
103 t.Fatalf("unmarshal JSON: %v (content: %s)", err, string(data))
104 }
105
106 if len(results) != 2 {
107 t.Fatalf("expected 2 results, got %d", len(results))
108 }
109
110 if results[0].StatusCode != 200 || results[0].Technique != "verb-tampering" {
111 t.Errorf("unexpected first result: %+v", results[0])
112 }
113 if results[0].Score != 90 || results[0].Likelihood != "high" || results[0].ReproCurl != "curl ..." {
114 t.Errorf("expected enriched fields in first result, got %+v", results[0])
115 }
116 if results[1].StatusCode != 403 || results[1].Technique != "headers" {
117 t.Errorf("unexpected second result: %+v", results[1])
118 }
119}
120
121func TestOutputWriter_JSONL(t *testing.T) {
122 dir := t.TempDir()

Callers

nothing calls this directly

Calls 3

initOutputWriterFunction · 0.85
writeResultToOutputFunction · 0.85
closeOutputWriterFunction · 0.85

Tested by

no test coverage detected