package device import ( "context" "os" "testing" "time" "data-terminal-cloud/internal/database" "data-terminal-cloud/internal/deviceauth" ) func TestRepositoryReportsBootstrapAndKeepsTenantBoundary(t *testing.T) { databaseURL := os.Getenv("TEST_DATABASE_URL") if databaseURL == "" { t.Skip("TEST_DATABASE_URL is not set") } ctx := context.Background() pool, err := database.Open(ctx, databaseURL, "device-integration-test") if err != nil { t.Fatal(err) } defer pool.Close() repository := NewRepository(pool) identity := deviceauth.Identity{ ID: "10000000-0000-0000-0000-000000000501", PublicID: "10000000-0000-0000-0000-000000000511", TenantID: "10000000-0000-0000-0000-000000000001", Status: "registered", } result, err := repository.ReportBootstrap(ctx, identity, BootstrapReport{ FirmwareVersion: "0.1.1-test", BoardRevision: "sim-rev-a", RTCSDKVersion: "mock-rtc-1", Codec: "opus", SampleRate: 16000, Network: "test", DeviceTime: time.Now(), }) if err != nil { t.Fatal(err) } if result.DeviceID != identity.PublicID || !result.Binding.Bound || result.ConfigRevision != 1 || !result.FirmwareCompatible || result.MinimumFirmwareVersion == nil || *result.MinimumFirmwareVersion != "0.1.0-sim" { t.Fatalf("bootstrap = %#v", result) } configuration, err := repository.GetConfiguration(ctx, identity) if err != nil || configuration.DeviceID != identity.PublicID || !configuration.Binding.Bound { t.Fatalf("configuration = %#v, err = %v", configuration, err) } wrongTenant := identity wrongTenant.TenantID = "20000000-0000-0000-0000-000000000001" if _, err := repository.GetConfiguration(ctx, wrongTenant); err == nil { t.Fatal("cross-tenant device configuration was not denied") } }