Files
godoxy/agent/pkg/agent/stream/payload_test.go
yusing fe619f1dd9 feat(agent): agent stream tunneling with TLS and dTLS (UDP); combined agent APIs
- Add `StreamPort` configuration to agent configuration and environment variables
- Implement TCP and UDP stream client support in agent package
- Update agent verification to test stream connectivity (TCP/UDP)
- Add `/info` endpoint to agent HTTP handler for version, name, runtime, and stream port
- Remove /version, /name, /runtime APIs, replaced by /info
- Update agent compose template to expose stream port for TCP and UDP
- Update agent creation API to optionally specify stream port (defaults to port + 1)
- Modify `StreamRoute` to pass agent configuration to stream implementations
- Update `TCPTCPStream` and `UDPUDPStream` to use agent stream tunneling when agent is configured
- Add support for both direct connections and agent-tunneled connections in stream routes

This enables agents to handle TCP and UDP route tunneling, expanding the proxy capabilities beyond HTTP-only connections.
2026-01-07 00:44:12 +08:00

54 lines
1.3 KiB
Go

package stream
import (
"bytes"
"testing"
)
func TestStreamRequestHeader_RoundTripAndChecksum(t *testing.T) {
h, err := NewStreamRequestHeader("example.com", "443")
if err != nil {
t.Fatalf("NewStreamRequestHeader: %v", err)
}
if !h.Validate() {
t.Fatalf("expected header to validate")
}
var buf [headerSize]byte
copy(buf[:], h.Bytes())
h2 := ToHeader(buf)
if !h2.Validate() {
t.Fatalf("expected round-tripped header to validate")
}
host, port := h2.GetHostPort()
if host != "example.com" || port != "443" {
t.Fatalf("unexpected host/port: %q:%q", host, port)
}
}
func TestStreamRequestPayload_WriteTo_WritesFullHeader(t *testing.T) {
h, err := NewStreamRequestHeader("127.0.0.1", "53")
if err != nil {
t.Fatalf("NewStreamRequestHeader: %v", err)
}
p := &StreamRequestPayload{StreamRequestHeader: *h, Data: []byte("hello")}
var out bytes.Buffer
n, err := p.WriteTo(&out)
if err != nil {
t.Fatalf("WriteTo: %v", err)
}
if int(n) != headerSize+len(p.Data) {
t.Fatalf("unexpected bytes written: got %d want %d", n, headerSize+len(p.Data))
}
written := out.Bytes()
if len(written) != headerSize+len(p.Data) {
t.Fatalf("unexpected output size: got %d", len(written))
}
if !bytes.Equal(written[:headerSize], h.Bytes()) {
t.Fatalf("expected full header (including checksum) to be written")
}
}