tiny update
This commit is contained in:
@@ -825,7 +825,7 @@ func HandleFileUploadHTTP(ctx context.Context, env *agentRuntime.Env, cmdID stri
|
||||
if token := strings.TrimSpace(env.Cfg.AgentToken); token != "" {
|
||||
req.Header.Set("x-agent-token", token)
|
||||
}
|
||||
if id := strings.TrimSpace(env.Cfg.ID); id != "" {
|
||||
if id := env.ClientID(); id != "" {
|
||||
req.Header.Set("x-overlord-client-id", id)
|
||||
}
|
||||
if offset > 0 {
|
||||
|
||||
@@ -477,8 +477,8 @@ func TestHandleFileUploadHTTP(t *testing.T) {
|
||||
data := []byte("http-upload-payload")
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if got := r.Header.Get("x-overlord-client-id"); got != "client-abc" {
|
||||
t.Fatalf("expected x-overlord-client-id client-abc, got %q", got)
|
||||
if got := r.Header.Get("x-overlord-client-id"); got != "key-fingerprint-canonical-id" {
|
||||
t.Fatalf("expected canonical x-overlord-client-id, got %q", got)
|
||||
}
|
||||
if got := r.Header.Get("x-agent-token"); got != "agent-token" {
|
||||
t.Fatalf("expected x-agent-token agent-token, got %q", got)
|
||||
@@ -494,11 +494,14 @@ func TestHandleFileUploadHTTP(t *testing.T) {
|
||||
env := &rt.Env{
|
||||
Conn: writer,
|
||||
Cfg: config.Config{
|
||||
ID: "client-abc",
|
||||
ID: "claimed-client-id",
|
||||
AgentToken: "agent-token",
|
||||
TLSInsecureSkipVerify: true,
|
||||
},
|
||||
}
|
||||
if !env.SetServerClientID("key-fingerprint-canonical-id") {
|
||||
t.Fatal("failed to install canonical client id")
|
||||
}
|
||||
|
||||
if err := HandleFileUploadHTTP(context.Background(), env, "cmd-http-upload", destPath, ts.URL+"/file", int64(len(data))); err != nil {
|
||||
t.Fatalf("HandleFileUploadHTTP failed: %v", err)
|
||||
|
||||
@@ -14,6 +14,12 @@ func HandleHelloAck(_ context.Context, env *runtime.Env, envelope map[string]int
|
||||
if env == nil || envelope == nil {
|
||||
return nil
|
||||
}
|
||||
if canonicalID, ok := envelope["id"].(string); ok && env.SetServerClientID(canonicalID) {
|
||||
if env.Plugins != nil {
|
||||
env.Plugins.SetClientID(env.ClientID())
|
||||
}
|
||||
log.Printf("hello ack: using canonical client id %s", env.ClientID())
|
||||
}
|
||||
if version := toInt(envelope["protocolVersion"]); version > 0 {
|
||||
log.Printf("hello ack: negotiated wire protocol v%d (agent v%d)", version, wire.WireProtocolVersion)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"overlord-client/cmd/agent/config"
|
||||
"overlord-client/cmd/agent/plugins"
|
||||
agentRuntime "overlord-client/cmd/agent/runtime"
|
||||
)
|
||||
|
||||
func TestHandleHelloAckAdoptsCanonicalClientID(t *testing.T) {
|
||||
writer := &testWriter{}
|
||||
env := &agentRuntime.Env{
|
||||
Conn: writer,
|
||||
Cfg: config.Config{ID: "claimed-client-id"},
|
||||
}
|
||||
env.Plugins = plugins.NewManager(writer, plugins.HostInfo{ClientID: env.ClientID()})
|
||||
|
||||
if err := HandleHelloAck(context.Background(), env, map[string]interface{}{
|
||||
"id": "key-fingerprint-canonical-id",
|
||||
"protocolVersion": 1,
|
||||
}); err != nil {
|
||||
t.Fatalf("HandleHelloAck failed: %v", err)
|
||||
}
|
||||
|
||||
if got := env.ClientID(); got != "key-fingerprint-canonical-id" {
|
||||
t.Fatalf("runtime client id = %q, want canonical id", got)
|
||||
}
|
||||
if got := env.Plugins.ClientID(); got != "key-fingerprint-canonical-id" {
|
||||
t.Fatalf("plugin host client id = %q, want canonical id", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleHelloAckWithoutIDRetainsConfiguredFallback(t *testing.T) {
|
||||
env := &agentRuntime.Env{Cfg: config.Config{ID: "claimed-client-id"}}
|
||||
if err := HandleHelloAck(context.Background(), env, map[string]interface{}{
|
||||
"protocolVersion": 1,
|
||||
}); err != nil {
|
||||
t.Fatalf("HandleHelloAck failed: %v", err)
|
||||
}
|
||||
if got := env.ClientID(); got != "claimed-client-id" {
|
||||
t.Fatalf("legacy hello_ack client id = %q, want configured fallback", got)
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func HandlePluginLoadHTTP(ctx context.Context, env *agentRuntime.Env, cmdID stri
|
||||
if token := strings.TrimSpace(env.Cfg.AgentToken); token != "" {
|
||||
req.Header.Set("x-agent-token", token)
|
||||
}
|
||||
if id := strings.TrimSpace(env.Cfg.ID); id != "" {
|
||||
if id := env.ClientID(); id != "" {
|
||||
req.Header.Set("x-overlord-client-id", id)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"overlord-client/cmd/agent/config"
|
||||
"overlord-client/cmd/agent/plugins"
|
||||
agentRuntime "overlord-client/cmd/agent/runtime"
|
||||
)
|
||||
|
||||
func TestHandlePluginLoadHTTPUsesCanonicalClientID(t *testing.T) {
|
||||
headers := make(chan http.Header, 1)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
headers <- r.Header.Clone()
|
||||
http.Error(w, "stop after header assertion", http.StatusForbidden)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
writer := &testWriter{}
|
||||
env := &agentRuntime.Env{
|
||||
Conn: writer,
|
||||
Cfg: config.Config{
|
||||
ID: "claimed-client-id",
|
||||
AgentToken: "agent-token",
|
||||
TLSInsecureSkipVerify: true,
|
||||
},
|
||||
}
|
||||
env.Plugins = plugins.NewManager(writer, plugins.HostInfo{ClientID: env.ClientID()})
|
||||
if !env.SetServerClientID("key-fingerprint-canonical-id") {
|
||||
t.Fatal("failed to install canonical client id")
|
||||
}
|
||||
|
||||
if err := HandlePluginLoadHTTP(
|
||||
context.Background(),
|
||||
env,
|
||||
"plugin-command-id",
|
||||
plugins.PluginManifest{ID: "test-plugin"},
|
||||
server.URL+"/api/plugins/pull/test-id",
|
||||
1,
|
||||
); err != nil {
|
||||
t.Fatalf("HandlePluginLoadHTTP failed: %v", err)
|
||||
}
|
||||
|
||||
got := <-headers
|
||||
if clientID := got.Get("x-overlord-client-id"); clientID != "key-fingerprint-canonical-id" {
|
||||
t.Fatalf("plugin pull client id = %q, want canonical id", clientID)
|
||||
}
|
||||
if token := got.Get("x-agent-token"); token != "agent-token" {
|
||||
t.Fatalf("plugin pull token = %q, want agent token", token)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user