ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)
Go aiai-agentsautonomous-agentsbug-bountydockergolanglinuxllmmcpnextjspenetration-testingpentestpostgresqlreareactred-teamsecuritysecurity-automationsqlitetypescript
test: stabilize the UDP control-close test and the sealed hook test
BaaRai7933df96f30b
diff --git a/db/traffic_tamper_hooks_test.go b/db/traffic_tamper_hooks_test.goindex 03c116d..8a347ad 100644--- a/db/traffic_tamper_hooks_test.go+++ b/db/traffic_tamper_hooks_test.go@@ -14,9 +14,6 @@ func TestTrafficTamperHookCRUDSealedAndVersions(t *testing.T) {SkipPGUnavailable(t, err)}t.Cleanup(func() { _ = d.Close() })- if err := d.InitSecrets(t.TempDir()); err != nil {- t.Fatalf("InitSecrets: %v", err)- }const srcV1 = `package hookconst apiSecret = "super-secret-hmac-key-v1"diff --git a/traffic/rewrite/trace.go b/traffic/rewrite/trace.goindex a7ed0ed..68f77d3 100644--- a/traffic/rewrite/trace.go+++ b/traffic/rewrite/trace.go@@ -44,11 +44,11 @@ const (// TraceLine is one row of an exchange's rewrite trace, in order. An exchange is// rewritten when it has at least one applied line.type TraceLine struct {- Phase Phase- SourceKind string // "rule" (default when empty) | "hook"- RuleID int64 // 0 on a global or hook line- HookID int64 // 0 on a rule or global line- HookVersion int // 0 on a rule or global line+ Phase Phase+ SourceKind string // "rule" (default when empty) | "hook"+ RuleID int64 // 0 on a global or hook line+ HookID int64 // 0 on a rule or global line+ HookVersion int // 0 on a rule or global line// RuleSnapshot is the rule or hook metadata as JSON, on its first line in the exchange only.RuleSnapshot stringAction stringdiff --git a/traffic/socks5_udp_test.go b/traffic/socks5_udp_test.goindex 57f9195..f0e934e 100644--- a/traffic/socks5_udp_test.go+++ b/traffic/socks5_udp_test.go@@ -9,7 +9,6 @@ import ("net""os""path/filepath"- "runtime""strconv""strings""sync/atomic"@@ -321,7 +320,6 @@ func TestSOCKS5UDPAssociateRelayStoreAndControlConnClose(t *testing.T) {}defer tr.Close()- baseG := runtime.NumGoroutine()proxyAddr, err := tr.StartSOCKS5(SOCKS5Config{Addr: "127.0.0.1:0",EnableUDP: true,@@ -422,23 +420,24 @@ func TestSOCKS5UDPAssociateRelayStoreAndControlConnClose(t *testing.T) {t.Fatalf("HTTP exchanges rows = (%d, %v), want 0", httpRows, err)}- // 4. Closing TCP control connection must tear down the UDP association promptly.+ // 4. Closing the TCP control connection must tear down the UDP association.+ // The close is processed asynchronously by the association goroutine, so a+ // single immediate probe races it: probe until a datagram is no longer+ // forwarded, then assert the relay is closed._ = ctrl.Close()deadline := time.Now().Add(2 * time.Second)+ closed := falsefor time.Now().Before(deadline) {- if runtime.NumGoroutine() <= baseG+6 {+ before := received.Load()+ _, _ = cliUDP.WriteToUDP(makeClientUDPPacketIPv4(echoAddr.IP, echoAddr.Port, 0x00, []byte("after-close")), relayAddr)+ time.Sleep(50 * time.Millisecond)+ if received.Load() == before {+ closed = truebreak}- time.Sleep(25 * time.Millisecond)}- beforeAfterClose := received.Load()- _, _ = cliUDP.WriteToUDP(makeClientUDPPacketIPv4(echoAddr.IP, echoAddr.Port, 0x00, []byte("after-close")), relayAddr)- _ = cliUDP.SetReadDeadline(time.Now().Add(150 * time.Millisecond))- if _, _, rerr := cliUDP.ReadFromUDP(buf); rerr == nil {- t.Fatal("expected no UDP reply after TCP control connection closed")- }- if received.Load() != beforeAfterClose {- t.Fatal("datagram was forwarded after TCP control connection closed")+ if !closed {+ t.Fatal("UDP association still forwards datagrams 2s after the TCP control connection closed")}}