Skip to content

Commit ceaeb76

Browse files
M09Icclaude
andcommitted
fix: cross-platform test compatibility for Switch proto and file paths
Updates mock implant e2e test to use new Targets field instead of removed Urls in Switch proto. Fixes download basename extraction to handle Windows backslash paths on Linux via path.Base with normalised separators. Fixes upload error assertion to match both Windows and Linux file-not-found messages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 153cbf4 commit ceaeb76

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

client/command/file/download.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
"github.com/chainreactors/IoM-go/proto/services/clientrpc"
88
"github.com/chainreactors/malice-network/client/core"
99
"github.com/spf13/cobra"
10-
"path/filepath"
10+
"path"
11+
"strings"
1112
)
1213

1314
func DownloadCmd(cmd *cobra.Command, con *core.Console) error {
@@ -23,9 +24,16 @@ func DownloadCmd(cmd *cobra.Command, con *core.Console) error {
2324
return nil
2425
}
2526

27+
// remotePath extracts the basename from a remote path that may use
28+
// either forward slashes (Unix) or backslashes (Windows).
29+
func remotePath(p string) string {
30+
// Normalise Windows backslashes so path.Base works on all platforms.
31+
return path.Base(strings.ReplaceAll(p, `\`, "/"))
32+
}
33+
2634
func Download(rpc clientrpc.MaliceRPCClient, session *client.Session, path string, is_dir bool) (*clientpb.Task, error) {
2735
task, err := rpc.Download(session.Context(), &implantpb.DownloadRequest{
28-
Name: filepath.Base(path),
36+
Name: remotePath(path),
2937
Path: path,
3038
Dir: is_dir,
3139
})

client/command/file/file_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func TestFileUploadCommandErrors(t *testing.T) {
6868
t.Run("upload rejects missing local file", func(t *testing.T) {
6969
h := testsupport.NewHarness(t)
7070
err := h.Execute(consts.ModuleUpload, filepath.Join(t.TempDir(), "missing.bin"), `C:\Temp\remote.bin`)
71-
if err == nil || !strings.Contains(strings.ToLower(err.Error()), "cannot find") {
72-
t.Fatalf("upload missing file error = %v, want cannot find", err)
71+
if err == nil || (!strings.Contains(strings.ToLower(err.Error()), "cannot find") && !strings.Contains(strings.ToLower(err.Error()), "no such file")) {
72+
t.Fatalf("upload missing file error = %v, want file-not-found error", err)
7373
}
7474
testsupport.RequireNoPrimaryCalls(t, h)
7575
testsupport.RequireNoSessionEvents(t, h)

server/mock_implant_common_rpc_e2e_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,14 +1458,17 @@ func TestMockImplantControlAndExecutionRPCsE2E(t *testing.T) {
14581458

14591459
switchBefore := len(f.mock.RequestsByName(consts.ModuleSwitch))
14601460
switchTask, err := f.rpc.Switch(f.session, &implantpb.Switch{
1461-
Urls: []string{"https://edge-a.example/mock", "wss://edge-b.example/mock"},
1461+
Targets: []*implantpb.Target{
1462+
{Address: "edge-a.example:443", Protocol: "tcp"},
1463+
{Address: "edge-b.example:443", Protocol: "tcp"},
1464+
},
14621465
})
14631466
if err != nil {
14641467
t.Fatalf("Switch failed: %v", err)
14651468
}
14661469
switchRequest := waitModuleRequest(t, f.mock, consts.ModuleSwitch, switchBefore)
1467-
if got := switchRequest.GetSpite().GetSwitch().GetUrls(); len(got) != 2 || got[0] != "https://edge-a.example/mock" {
1468-
t.Fatalf("switch urls = %#v", got)
1470+
if got := switchRequest.GetSpite().GetSwitch().GetTargets(); len(got) != 2 || got[0].GetAddress() != "edge-a.example:443" {
1471+
t.Fatalf("switch targets = %#v", got)
14691472
}
14701473
waitTaskFinish(t, f.rpc, f.mock.SessionID, switchTask.TaskId)
14711474

0 commit comments

Comments
 (0)