94 lines
3.3 KiB
Go
94 lines
3.3 KiB
Go
//go:build windows
|
|
|
|
package remote
|
|
|
|
import "testing"
|
|
|
|
func TestGetServiceStatusNonExist(t *testing.T) {
|
|
// 不存在的服务应返回错误(Radmin 服务普通机器上不会安装)
|
|
_, err := GetRadminServiceStatus()
|
|
if err == nil {
|
|
t.Log("本机安装了 Radmin 服务,跳过该断言")
|
|
}
|
|
}
|
|
|
|
func TestGetRemoteInfo(t *testing.T) {
|
|
info := GetRemoteInfo()
|
|
if info.Hostname == "" {
|
|
t.Error("Hostname 不应为空")
|
|
}
|
|
if len(info.IpAddr) == 0 {
|
|
t.Log("本机无 IPv4 地址(CI 环境可能出现)")
|
|
}
|
|
// 只读查询,不应 panic
|
|
_ = info.RdpState
|
|
_ = info.VncState
|
|
}
|
|
|
|
func TestVncPasswordCryptDecrypt(t *testing.T) {
|
|
password := "tvncpass"
|
|
encrypted := VncPasswordCrypt(password)
|
|
if len(encrypted) == 0 {
|
|
t.Fatal("加密结果不应为空")
|
|
}
|
|
if string(encrypted) == password {
|
|
t.Error("加密结果不应等于明文")
|
|
}
|
|
decrypted := VncPasswordDecrypt(encrypted)
|
|
if decrypted != password {
|
|
t.Errorf("解密 = %q, want %q", decrypted, password)
|
|
}
|
|
}
|
|
|
|
func TestVncServerDefaultConfig(t *testing.T) {
|
|
cfg := VncServerDefaultConfig(false)
|
|
if cfg.RfbPort == 0 {
|
|
t.Error("RfbPort 不应为 0")
|
|
}
|
|
if cfg.HttpPort == 0 {
|
|
t.Error("HttpPort 不应为 0")
|
|
}
|
|
}
|
|
|
|
// TestVncClientDefaultConfigLatest 锁定对最新版 TightVNC(2.8.x) 注册表全集的支持:
|
|
// 值与本机最新版安装器落盘值逐项对齐(AcceptHttpConnections/RunControlInterface
|
|
// 为安全策略有意取 0:不开 5800 Web 通道、不显托盘)。
|
|
func TestVncClientDefaultConfigLatest(t *testing.T) {
|
|
cfg := VncClientDefaultConfig(false)
|
|
if cfg.RfbPort != 5900 || cfg.HttpPort != 5800 {
|
|
t.Errorf("端口 = %d/%d, want 5900/5800", cfg.RfbPort, cfg.HttpPort)
|
|
}
|
|
// 最新版捕获能力:镜像驱动 + D3D + 透明窗口 + 视频区域识别
|
|
if cfg.UseMirrorDriver != 1 || cfg.UseD3D != 1 {
|
|
t.Errorf("捕获开关 = mirror:%d d3d:%d, want 1/1", cfg.UseMirrorDriver, cfg.UseD3D)
|
|
}
|
|
if cfg.GrabTransparentWindows != 1 || cfg.VideoRecognitionInterval != 3000 {
|
|
t.Errorf("透明窗口/视频识别 = %d/%d, want 1/3000", cfg.GrabTransparentWindows, cfg.VideoRecognitionInterval)
|
|
}
|
|
// 安全策略:不开 HTTP 通道、不出托盘控制台、不接 RDP 会话
|
|
if cfg.AcceptHttpConnections != 0 || cfg.RunControlInterface != 0 || cfg.ConnectToRdp != 0 {
|
|
t.Errorf("安全策略 = http:%d tray:%d rdp:%d, want 0/0/0", cfg.AcceptHttpConnections, cfg.RunControlInterface, cfg.ConnectToRdp)
|
|
}
|
|
// 连接行为:VNC 认证 + 接受 RFB + 本机输入优先 + 断开踢旧连接
|
|
if cfg.AcceptRfbConnections != 1 || cfg.UseVncAuthentication != 1 || cfg.LocalInputPriority != 1 || cfg.DisconnectClients != 1 {
|
|
t.Errorf("连接行为异常: %+v", cfg)
|
|
}
|
|
if cfg.QueryTimeout != 30 || cfg.LocalInputPriorityTimeout != 3 || cfg.PollingInterval != 1000 || cfg.AllowLoopback != 1 {
|
|
t.Errorf("超时/轮询/环回异常: %+v", cfg)
|
|
}
|
|
if len(cfg.Password) == 0 {
|
|
t.Error("固定密码密文不应为空")
|
|
}
|
|
if dec := VncPasswordDecrypt(cfg.Password); dec != "tvncpass" {
|
|
t.Errorf("固定密码回解 = %q, want tvncpass", dec)
|
|
}
|
|
}
|
|
|
|
// TestInstallVncServerMissingExe 安装入口对 tvnserver.exe 缺失必须报错(不触注册表/服务)
|
|
func TestInstallVncServerMissingExe(t *testing.T) {
|
|
_, err := InstallVncServer(`Z:\no\such\dir\tvnserver.exe`)
|
|
if err == nil {
|
|
t.Fatal("exe 不存在时应返回错误")
|
|
}
|
|
}
|