Files
story/internal/onboarding/ble_state_test.go
T
Codex Local bf1233d5df
ci / verify (push) Canceled after 0s
feat: expand companion platform, device controls, and memoir workflows
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
2026-10-08 10:06:44 +08:00

61 lines
1.7 KiB
Go

package onboarding
import (
"data-terminal-cloud/internal/identity"
"github.com/google/uuid"
"testing"
)
func TestBLEPlaintextBindingState(t *testing.T) {
f := newFixture(t)
in := BLEDeviceInput{DeviceID: f.d.FactoryID}
state, err := f.s.BLEDeviceState(f.ctx, f.user, in)
must(t, err)
if state["bound"] != false || state["id"] != f.d.PublicID {
t.Fatal(state)
}
device, err := f.s.DeviceBLEState(f.ctx, f.d)
must(t, err)
if device["bound"] != false {
t.Fatal(device)
}
_, err = f.s.BindBLE(f.ctx, f.d, uuid.NewString(), BLEBindInput{Token: ""})
if err == nil {
t.Fatal("empty token must not create a binding")
}
_, err = f.s.BLEDeviceState(f.ctx, identity.Principal{Issuer: f.user.Issuer, Subject: uuid.NewString()}, in)
if err == nil {
t.Fatal("unrelated account read binding state")
}
token := f.bleToken()
_, err = f.s.BindBLE(f.ctx, f.d, uuid.NewString(), BLEBindInput{Token: token})
must(t, err)
f.refresh()
generation := f.d.Generation
state, err = f.s.BLEDeviceState(f.ctx, f.user, in)
must(t, err)
if state["bound"] != true {
t.Fatal(state)
}
for i := 0; i < 3; i++ {
device, err = f.s.DeviceBLEState(f.ctx, f.d)
must(t, err)
if device["bound"] != true {
t.Fatal(device)
}
}
f.refresh()
if f.d.Generation != generation {
t.Fatal("WiFi checks modified ownership")
}
_, err = f.s.pool.Exec(f.ctx, `UPDATE device_binding SET unbound_at=now() WHERE device_id=$1::uuid AND unbound_at IS NULL`, f.d.ID)
must(t, err)
f.web.Hash = "" // Unbinding intentionally expires the fixture's old setup session.
f.refresh()
device, err = f.s.DeviceBLEState(f.ctx, f.d)
must(t, err)
if device["bound"] != false {
t.Fatal("stale bound state after unbind", device)
}
}