feat: persist and transfer script command payloads
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -20,6 +23,54 @@ import (
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
func TestScriptTransferUsesChecksummedChunksAndCommit_HP_SCRIPT_03(t *testing.T) {
|
||||
t.Parallel()
|
||||
body := bytes.Repeat([]byte("abcd"), 8)
|
||||
digest := sha256.Sum256(body)
|
||||
transfer := map[string]*scriptTransfer{"019c46f1-1d02-7000-8000-0000000000b1": {Body: body, Digest: digest}}
|
||||
queue := NewWriterQueue(4, 8, 2)
|
||||
defer queue.Close()
|
||||
for offset := uint64(0); offset < uint64(len(body)); {
|
||||
queued, err := (&AgentServer{}).enqueueNextScript(queue, "session", 7, transfer, &sync.Mutex{}, 5)
|
||||
if err != nil || !queued {
|
||||
t.Fatalf("chunk at offset %d: queued=%t err=%v", offset, queued, err)
|
||||
}
|
||||
frame, err := queue.Next(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var envelope rvboxv1.AgentEnvelope
|
||||
if err := proto.Unmarshal(frame.Payload, &envelope); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
chunk := envelope.GetScriptChunk()
|
||||
if chunk == nil || chunk.GetOffset() != offset || !bytes.Equal(chunk.GetData(), body[offset:offset+uint64(len(chunk.GetData()))]) {
|
||||
t.Fatalf("chunk = %+v at offset %d", chunk, offset)
|
||||
}
|
||||
chunkDigest := sha256.Sum256(chunk.GetData())
|
||||
if !bytes.Equal(chunk.GetSha256(), chunkDigest[:]) {
|
||||
t.Fatal("chunk digest mismatch")
|
||||
}
|
||||
offset += uint64(len(chunk.GetData()))
|
||||
}
|
||||
queued, err := (&AgentServer{}).enqueueNextScript(queue, "session", 7, transfer, &sync.Mutex{}, 5)
|
||||
if err != nil || !queued {
|
||||
t.Fatalf("commit queued=%t err=%v", queued, err)
|
||||
}
|
||||
frame, err := queue.Next(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var envelope rvboxv1.AgentEnvelope
|
||||
if err := proto.Unmarshal(frame.Payload, &envelope); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
commit := envelope.GetScriptCommit()
|
||||
if commit == nil || commit.GetSizeBytes() != uint64(len(body)) || !bytes.Equal(commit.GetSha256(), digest[:]) {
|
||||
t.Fatalf("commit = %+v", commit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentServerRegistrationAndReplacement_HP_SES_05(t *testing.T) {
|
||||
server, cleanup := newTestAgentServer(t)
|
||||
defer cleanup()
|
||||
|
||||
Reference in New Issue
Block a user