Files
fscan/plugins/services/modbus_test.go
T
ZacharyZcR 8d30ee334c
测试构建 / 代码检查 (push) Has been cancelled
测试构建 / 单元测试和构建 (push) Has been cancelled
测试构建 / 构建验证 (push) Has been cancelled
Add native protocol service plugins
2026-05-23 15:51:50 +08:00

23 lines
609 B
Go

//go:build plugin_modbus || !plugin_selective
package services
import (
"encoding/binary"
"strings"
"testing"
)
func TestModbusDeviceIDRequestAndResponse(t *testing.T) {
req := buildModbusDeviceIDRequest(0x1001)
if len(req) != 11 || binary.BigEndian.Uint16(req[0:2]) != 0x1001 || req[7] != 0x2b {
t.Fatalf("unexpected modbus request: %#v", req)
}
header := []byte{0x10, 0x01, 0x00, 0x00, 0x00, 0x03, 0xff}
banner, ok := parseModbusResponse(header, []byte{0x2b, 0x0e}, 0x1001)
if !ok || !strings.Contains(banner, "Modbus TCP") {
t.Fatalf("unexpected modbus banner: %q ok=%v", banner, ok)
}
}