audit full project flows and harden backend

This commit is contained in:
2026-08-03 16:03:44 +08:00
parent d8d62469d6
commit 95b6f2b69c
22 changed files with 505 additions and 890 deletions

View File

@@ -0,0 +1,22 @@
package service
import (
"testing"
"git.apinb.com/heqiapp/platforms/backend/iot-server/internal/config"
)
func TestDeviceIDFromTopic(t *testing.T) {
cfg := config.Config{MQTT: config.MQTT{UpTopic: "devices/+/up", AckTopic: "devices/+/ack"}}
for _, topic := range []string{"devices/0000000000000001/up", "devices/0000000000000001/ack"} {
identity, ok := deviceIDFromTopic(cfg, topic)
if !ok || identity != "0000000000000001" {
t.Fatalf("topic %s: identity=%q ok=%v", topic, identity, ok)
}
}
for _, topic := range []string{"devices/0001/up", "devices/0000000000000001/down", "other/0000000000000001/up"} {
if identity, ok := deviceIDFromTopic(cfg, topic); ok || identity != "" {
t.Fatalf("invalid topic %s accepted as %q", topic, identity)
}
}
}