This commit is contained in:
KingKDot
2026-03-12 21:26:53 -05:00
parent 5da706bc88
commit 409ed35f5b
30 changed files with 1097 additions and 36 deletions
@@ -26,6 +26,7 @@ var DefaultMutex = ""
var DefaultID = ""
var DefaultCountry = ""
var DefaultAgentToken = ""
var DefaultBuildTag = ""
const settingsFile = "config/settings.json"
const serverIndexFile = "config/server_index.json"
@@ -60,6 +61,7 @@ type Config struct {
TLSClientCert string
TLSClientKey string
AgentToken string
BuildTag string
}
func Load() Config {
@@ -159,6 +161,7 @@ func Load() Config {
TLSClientCert: tlsClientCert,
TLSClientKey: tlsClientKey,
AgentToken: agentToken,
BuildTag: strings.TrimSpace(DefaultBuildTag),
}
}
+1
View File
@@ -388,6 +388,7 @@ func runSession(ctx context.Context, cancel context.CancelFunc, conn *websocket.
Monitors: capture.MonitorCount(),
MonitorInfo: toWireMonitorInfo(capture.MonitorInfos()),
Country: cfg.Country,
BuildTag: cfg.BuildTag,
}
if err := wire.WriteMsg(ctx, env.Conn, hello); err != nil {
@@ -12,6 +12,7 @@ type Hello struct {
Monitors int `msgpack:"monitors"`
MonitorInfo []MonitorInfo `msgpack:"monitorInfo,omitempty"`
Country string `msgpack:"country,omitempty"`
BuildTag string `msgpack:"buildTag,omitempty"`
}
type MonitorInfo struct {
@@ -57,6 +57,113 @@ func TestHelloMarshaling(t *testing.T) {
}
}
func TestHelloBuildTagMarshaling(t *testing.T) {
t.Run("with build tag", func(t *testing.T) {
hello := Hello{
Type: "hello",
ID: "test-id",
HWID: "test-hwid",
Host: "test-host",
OS: "test-os",
Arch: "test-arch",
Version: "1.0.0",
User: "test-user",
BuildTag: "abc-123-def-456",
}
data, err := msgpack.Marshal(hello)
if err != nil {
t.Fatalf("Failed to marshal Hello with BuildTag: %v", err)
}
var decoded Hello
if err := msgpack.Unmarshal(data, &decoded); err != nil {
t.Fatalf("Failed to unmarshal Hello with BuildTag: %v", err)
}
if decoded.BuildTag != "abc-123-def-456" {
t.Errorf("BuildTag mismatch: got %q, want %q", decoded.BuildTag, "abc-123-def-456")
}
if decoded.ID != hello.ID {
t.Errorf("ID mismatch: got %s, want %s", decoded.ID, hello.ID)
}
})
t.Run("without build tag (omitempty)", func(t *testing.T) {
hello := Hello{
Type: "hello",
ID: "test-id",
HWID: "test-hwid",
Host: "test-host",
OS: "test-os",
Arch: "test-arch",
Version: "1.0.0",
User: "test-user",
}
data, err := msgpack.Marshal(hello)
if err != nil {
t.Fatalf("Failed to marshal Hello without BuildTag: %v", err)
}
// Verify buildTag key is not present in the wire data (omitempty)
if bytes.Contains(data, []byte("buildTag")) {
t.Error("Expected buildTag to be omitted from wire data when empty")
}
var decoded Hello
if err := msgpack.Unmarshal(data, &decoded); err != nil {
t.Fatalf("Failed to unmarshal Hello without BuildTag: %v", err)
}
if decoded.BuildTag != "" {
t.Errorf("BuildTag should be empty, got %q", decoded.BuildTag)
}
})
t.Run("server-side decode without build tag field", func(t *testing.T) {
// Simulate an older client that doesn't send buildTag at all
type OldHello struct {
Type string `msgpack:"type"`
ID string `msgpack:"id"`
HWID string `msgpack:"hwid"`
Host string `msgpack:"host"`
OS string `msgpack:"os"`
Arch string `msgpack:"arch"`
Version string `msgpack:"version"`
User string `msgpack:"user"`
}
old := OldHello{
Type: "hello",
ID: "old-client",
HWID: "old-hwid",
Host: "old-host",
OS: "windows",
Arch: "amd64",
Version: "0.9.0",
User: "old-user",
}
data, err := msgpack.Marshal(old)
if err != nil {
t.Fatalf("Failed to marshal OldHello: %v", err)
}
var decoded Hello
if err := msgpack.Unmarshal(data, &decoded); err != nil {
t.Fatalf("Failed to unmarshal OldHello into Hello: %v", err)
}
if decoded.BuildTag != "" {
t.Errorf("BuildTag should default to empty for old client, got %q", decoded.BuildTag)
}
if decoded.ID != "old-client" {
t.Errorf("ID mismatch: got %s, want old-client", decoded.ID)
}
})
}
func TestPingPongMarshaling(t *testing.T) {
ping := Ping{
Type: "ping",