audit full project flows and harden backend
This commit is contained in:
22
backend/iot-server/internal/service/service_test.go
Normal file
22
backend/iot-server/internal/service/service_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user