fix(transport): align WebSocket read limits with agent protocol
This commit is contained in:
1 parent
ef6e65e6f1
commit
6984a09486
11 files changed
+376
-4
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -225,6 +226,37 @@ func TestAgentServerRejectsHostileWireInputs_BH_SES_04(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentServerEnforcesConfiguredReadCeiling_BH_WS_02(t *testing.T) {
|
||||
t.Parallel()
|
||||
server, edge, cleanup := newTestAgentServerWithStore(t)
|
||||
defer cleanup()
|
||||
edge.Limits = agentproto.DefaultLimits()
|
||||
edge.Limits.MaxEnvelopeBytes = 2048
|
||||
logs := make(chan string, 1)
|
||||
edge.Logf = func(format string, args ...any) { logs <- fmt.Sprintf(format, args...) }
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
connection, _, err := websocket.Dial(ctx, websocketURL(server.URL), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer connection.CloseNow()
|
||||
if err := connection.Write(ctx, websocket.MessageBinary, bytes.Repeat([]byte{0x51}, 2049)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := connection.Read(ctx); websocket.CloseStatus(err) != websocket.StatusMessageTooBig {
|
||||
t.Fatalf("oversize close = %v", err)
|
||||
}
|
||||
select {
|
||||
case diagnostic := <-logs:
|
||||
if !strings.Contains(diagnostic, "stage=hello-read") || !strings.Contains(diagnostic, "2049") {
|
||||
t.Fatalf("missing bounded transport diagnostic: %s", diagnostic)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatal("oversize failure was not logged")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWireEventAppendCarriesClientBinding_HP_EVENT_01(t *testing.T) {
|
||||
event := &rvboxv1.CommandEvent{IssueUuid: "019c46f1-1d02-7000-8000-000000000096", EventSeq: 1, ObservedAt: timestamppb.Now(), Payload: &rvboxv1.CommandEvent_Lifecycle{Lifecycle: &rvboxv1.LifecycleChange{Lifecycle: rvboxv1.CommandLifecycle_COMMAND_RUNNING, CommandRevision: 1}}}
|
||||
digest, err := agentproto.CommandEventDigest(event)
|
||||
|
||||
Reference in new issue
Block a user