Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
POST /api/v1/recon/relay-scan probes from the dashboard when reachable, otherwise dispatches recon_relay_scan to a same-/24 online agent. Agents reuse probePortsFn for TCP and optionally UDP 53/51820 with dns/wireguard Path Tracer tags.
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package client
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"crypto-miner-agent/deploy"
|
|
)
|
|
|
|
func TestHandleReconRelayScanCommand(t *testing.T) {
|
|
deploy.SetProbePortsHook(func(host string, ports []int) []int {
|
|
if host == "10.1.2.3" {
|
|
return []int{22, 445}
|
|
}
|
|
return nil
|
|
})
|
|
t.Cleanup(func() { deploy.SetProbePortsHook(nil) })
|
|
deploy.SetRelayUDPGuessHook(func(host string, ports []int) []deploy.RelayUDPHint {
|
|
return []deploy.RelayUDPHint{{Port: 51820, Open: true, Service: "wireguard"}}
|
|
})
|
|
t.Cleanup(func() { deploy.SetRelayUDPGuessHook(nil) })
|
|
|
|
var gotAction string
|
|
var gotSuccess bool
|
|
var gotMsg string
|
|
c := &AgentClient{}
|
|
c.commandResultHook = func(action string, success bool, message string) {
|
|
gotAction, gotSuccess, gotMsg = action, success, message
|
|
}
|
|
|
|
if !c.handleReconCommand("recon_relay_scan", "10.1.2.3", "true") {
|
|
t.Fatal("expected handled")
|
|
}
|
|
if gotAction != "recon_relay_scan" || !gotSuccess {
|
|
t.Fatalf("action=%s success=%v", gotAction, gotSuccess)
|
|
}
|
|
var parsed map[string]interface{}
|
|
if err := json.Unmarshal([]byte(gotMsg), &parsed); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ports, _ := parsed["open_ports"].([]interface{})
|
|
if len(ports) != 2 {
|
|
t.Fatalf("ports=%v", ports)
|
|
}
|
|
}
|
|
|
|
func TestHandleReconRelayScanMissingHost(t *testing.T) {
|
|
c := &AgentClient{}
|
|
c.commandResultHook = func(action string, success bool, _ string) {
|
|
if action != "recon_relay_scan" || success {
|
|
t.Fatalf("action=%s success=%v", action, success)
|
|
}
|
|
}
|
|
if !c.handleReconCommand("recon_relay_scan", "", "") {
|
|
t.Fatal("expected handled")
|
|
}
|
|
}
|