fix(server): keep script chunks within legacy client read limits
This commit is contained in:
1 parent
1b5c6dbf98
commit
474afb3484
5 files changed
+107
-1
No files matched your search
@@ -1163,6 +1163,12 @@ layer = "integration"
|
||||
status = "implemented"
|
||||
tests = ["test/integration/clientagent/websocket_limits_integration_test.go:TestLargeOutputReplaysAfterReconnect_REC_WS_01"]
|
||||
|
||||
[[requirements]]
|
||||
id = "REC-WS-02"
|
||||
layer = "integration"
|
||||
status = "implemented"
|
||||
tests = ["test/integration/clientagent/websocket_limits_integration_test.go:TestLargeScriptFitsLegacyReader_REC_WS_02"]
|
||||
|
||||
[[requirements]]
|
||||
id = "REC-RUNTIME-06"
|
||||
layer = "unit"
|
||||
|
||||
@@ -3,6 +3,7 @@ package clientagent_test
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -91,6 +92,84 @@ func TestLargeDispatchAndReconciliation_HP_WS_01(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLargeScriptFitsLegacyReader_REC_WS_02(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
fixture := newFrameFixture(t)
|
||||
legacy := agentproto.DefaultLimits()
|
||||
legacy.MaxEnvelopeBytes = 32 << 10
|
||||
transport, err := agent.DialWebSocketWithLimits(ctx, "wss"+strings.TrimPrefix(fixture.server.URL, "https")+"/v1/agent", fixture.server.Client(), legacy)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer transport.Close()
|
||||
accepted, err := agent.Handshake(ctx, transport, fixture.hello, legacy)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := agent.Reconcile(ctx, transport, accepted, &rvboxv1.ReconcileSnapshot{}, legacy); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body := bytes.Repeat([]byte("echo large-script\r\n"), 10000)
|
||||
digest := sha256.Sum256(body)
|
||||
queued, err := fixture.control.RunCommand(ctx, &rvboxv1.RunCommandRequest{TargetClientId: fixture.hello.ClientId,
|
||||
Spec: &rvboxv1.ExecutionSpec{ShellType: rvboxv1.ShellType_SHELL_CMD,
|
||||
Source: &rvboxv1.ExecutionSpec_Script{Script: &rvboxv1.ScriptDescriptor{
|
||||
Filename: "large.cmd", SizeBytes: uint64(len(body)), Sha256: digest[:],
|
||||
}}}, ScriptContent: body})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dispatch := readFrame(t, ctx, transport).GetCommandDispatch()
|
||||
if dispatch == nil || dispatch.IssueUuid != queued.IssueUuid {
|
||||
t.Fatal("missing script dispatch")
|
||||
}
|
||||
ack, _ := proto.Marshal(&rvboxv1.AgentEnvelope{SessionId: accepted.ID, SessionGeneration: accepted.Generation,
|
||||
Payload: &rvboxv1.AgentEnvelope_CommandAccepted{CommandAccepted: &rvboxv1.CommandAccepted{
|
||||
IssueUuid: dispatch.IssueUuid, CommandRevision: 1, Accepted: true,
|
||||
}}})
|
||||
if err := transport.Write(ctx, ack); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var received []byte
|
||||
for {
|
||||
envelope := readFrame(t, ctx, transport)
|
||||
if chunk := envelope.GetScriptChunk(); chunk != nil {
|
||||
if chunk.Offset != uint64(len(received)) || sha256.Sum256(chunk.Data) != bytesToSHA(chunk.Sha256) {
|
||||
t.Fatal("script offset/checksum changed")
|
||||
}
|
||||
received = append(received, chunk.Data...)
|
||||
continue
|
||||
}
|
||||
commit := envelope.GetScriptCommit()
|
||||
if commit == nil || commit.SizeBytes != uint64(len(body)) || !bytes.Equal(commit.Sha256, digest[:]) || !bytes.Equal(received, body) {
|
||||
t.Fatal("script commit/body changed")
|
||||
}
|
||||
break
|
||||
}
|
||||
for i, phase := range []rvboxv1.CommandLifecycle{rvboxv1.CommandLifecycle_COMMAND_RUNNING, rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED} {
|
||||
if err := agent.SendCommandEvent(ctx, transport, accepted, &rvboxv1.CommandEvent{IssueUuid: dispatch.IssueUuid,
|
||||
EventSeq: uint64(i + 1), ObservedAt: timestamppb.Now(), Payload: &rvboxv1.CommandEvent_Lifecycle{
|
||||
Lifecycle: &rvboxv1.LifecycleChange{Lifecycle: phase, CommandRevision: 1},
|
||||
}}, agentproto.DefaultLimits()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ack := readFrame(t, ctx, transport).GetEventAck(); ack == nil || ack.ThroughEventSeq != uint64(i+1) {
|
||||
t.Fatal("script completion not acknowledged")
|
||||
}
|
||||
}
|
||||
if next := fixture.dispatch(t, ctx, transport, "echo still-connected"); next.Spec.GetCommandText() != "echo still-connected" {
|
||||
t.Fatal("legacy session failed after script upload")
|
||||
}
|
||||
}
|
||||
|
||||
func bytesToSHA(value []byte) [sha256.Size]byte {
|
||||
var result [sha256.Size]byte
|
||||
copy(result[:], value)
|
||||
return result
|
||||
}
|
||||
|
||||
type frameFixture struct {
|
||||
persistence *store.Store
|
||||
control *control.Service
|
||||
|
||||
Reference in new issue
Block a user