mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-20 07:00:58 +08:00
feat(server): upgrade the built-in traffic_get description once
It now says that traffic_get shows the originals of a rewritten exchange and that traffic_search never finds a value a rewrite rule wrote. As for traffic_search, only the original built-in text is replaced.
This commit is contained in:
@@ -29,6 +29,16 @@ func (s *Server) seedFindingWorkflowTools() {
|
||||
_ = s.m.pg.SetSetting(hostSearchDescriptionFlag, "true")
|
||||
}
|
||||
}
|
||||
const getRewriteDescriptionFlag = "traffic_get_rewrite_description_v1"
|
||||
if value, _, _ := s.m.pg.GetSetting(getRewriteDescriptionFlag); value != "true" {
|
||||
// Same rule: only the original built-in text is replaced.
|
||||
legacy := "Fetch the raw request/response of one captured traffic record by id (truncated when too large). Use together with traffic_search to avoid re-curling. A WebSocket (status 101) or SSE (text/event-stream) record shows only its handshake here; read its messages with traffic_messages."
|
||||
if _, err := s.m.pg.Exec(`UPDATE tools SET description=$1,updated_at=now() WHERE key='traffic_get' AND system AND description=$2`, traffic.TrafficGetDescription, legacy); err != nil {
|
||||
log.Printf("[evidence] upgrade traffic_get description: %v", err)
|
||||
} else {
|
||||
_ = s.m.pg.SetSetting(getRewriteDescriptionFlag, "true")
|
||||
}
|
||||
}
|
||||
const flag = "finding_workflow_tools_v2_reporter"
|
||||
if value, _, _ := s.m.pg.GetSetting(flag); value == "true" {
|
||||
return
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/Autumn-27/artex/traffic"
|
||||
)
|
||||
|
||||
// The traffic_get description that says traffic_search never finds a value a
|
||||
// rewrite rule wrote replaces the original built-in text once, and never a
|
||||
// description the user edited.
|
||||
func TestTrafficGetDescriptionUpgrade(t *testing.T) {
|
||||
s, _, _ := trafficEvidenceServer(t)
|
||||
pg := s.m.pg
|
||||
old, err := pg.GetTool("traffic_get")
|
||||
if err != nil || old == nil {
|
||||
t.Fatal("missing tool traffic_get", err)
|
||||
}
|
||||
bindings, _ := json.Marshal(old.Agents)
|
||||
t.Cleanup(func() { pg.UpdateTool("traffic_get", old.Description, old.Schema, bindings, old.Enabled) })
|
||||
const flag = "traffic_get_rewrite_description_v1"
|
||||
legacy := "Fetch the raw request/response of one captured traffic record by id (truncated when too large). Use together with traffic_search to avoid re-curling. A WebSocket (status 101) or SSE (text/event-stream) record shows only its handshake here; read its messages with traffic_messages."
|
||||
|
||||
for _, c := range []struct{ stored, want string }{
|
||||
{legacy, traffic.TrafficGetDescription},
|
||||
{"USER DESCRIPTION", "USER DESCRIPTION"},
|
||||
} {
|
||||
if err := pg.UpdateTool("traffic_get", c.stored, old.Schema, bindings, old.Enabled); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := pg.SetSetting(flag, "false"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.seedFindingWorkflowTools()
|
||||
row, _ := pg.GetTool("traffic_get")
|
||||
if row.Description != c.want {
|
||||
t.Fatalf("stored %q: description %q, want %q", c.stored, row.Description, c.want)
|
||||
}
|
||||
if v, _, _ := pg.GetSetting(flag); v != "true" {
|
||||
t.Fatal("flag not set")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user