MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / TestE2E_Register_FieldMapping

Function TestE2E_Register_FieldMapping

internal/bridge/bridge_e2e_test.go:61–101  ·  view source on GitHub ↗

=================================================================== Test 2: Register should use real hostname and meaningful username ===================================================================

(t *testing.T)

Source from the content-addressed store, hash-verified

59// ===================================================================
60
61func TestE2E_Register_FieldMapping(t *testing.T) {
62 srv, rpcClient, cleanup := startTestServer(t)
63 defer cleanup()
64
65 mgr := sessions.NewManager(10 * time.Minute)
66 origGlobal := swapGlobalManager(mgr)
67
68 b := newTestBridgeWithRPC(t, rpcClient)
69 defer cancelAndRestore(b, origGlobal)
70
71 sess := mgr.Touch("test-key", "claude-code/1.0.33 (Linux 6.1.0; x86_64)", "claude", "")
72 b.onNewSession(sess)
73
74 // Wait briefly for registration RPC to complete.
75 time.Sleep(200 * time.Millisecond)
76
77 regs := srv.getRegisteredSessions()
78 if len(regs) == 0 {
79 t.Fatal("expected at least 1 registered session")
80 }
81
82 reg := regs[0]
83 sysinfo := reg.RegisterData.Sysinfo
84 if sysinfo == nil || sysinfo.Os == nil {
85 t.Fatal("expected non-nil SysInfo.Os")
86 }
87
88 // Hostname should be the real machine hostname, not the agent name.
89 expectedHostname, _ := os.Hostname()
90 if expectedHostname == "" {
91 expectedHostname = "unknown"
92 }
93 if sysinfo.Os.Hostname != expectedHostname {
94 t.Errorf("expected Hostname=%q (real hostname), got %q", expectedHostname, sysinfo.Os.Hostname)
95 }
96
97 // Username should be agent_name/version, not an API key hash.
98 if sysinfo.Os.Username != "claude-code/1.0.33" {
99 t.Errorf("expected Username=%q, got %q", "claude-code/1.0.33", sysinfo.Os.Username)
100 }
101}
102
103// ===================================================================
104// Test 3: waitForSession should respond quickly (not poll every 1s)

Callers

nothing calls this directly

Calls 8

TouchMethod · 0.95
NewManagerFunction · 0.92
startTestServerFunction · 0.85
swapGlobalManagerFunction · 0.85
newTestBridgeWithRPCFunction · 0.85
cancelAndRestoreFunction · 0.85
onNewSessionMethod · 0.80
getRegisteredSessionsMethod · 0.80

Tested by

no test coverage detected