Server 2.4.0, app 2.11.1: ABRP forwarding removed from the server
The car sends live data to ABRP itself, and the car and the server go over the same mobile connection: when the car cannot reach ABRP, it cannot reach the server either, so the server's fallback bought nothing. The forwarder, its ABRP_* settings and abrpSentUtc are gone; the server only stores. The app stops sending abrpSentUtc (the server ignores unknown fields, so 2.11.0 keeps working) and its texts no longer promise a server fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QLJfZQZeAKAwSqViTmLzki
This commit is contained in:
+1
-67
@@ -1,10 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -49,68 +45,6 @@ func TestAggregateDaysNewestSohWins(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTlmSendsFlagsAsZeroOrOne(t *testing.T) {
|
||||
got := tlm(TelemetrySample{UTC: testNowS, Numbers: map[string]float64{"soc": 50},
|
||||
Flags: map[string]bool{"is_charging": true, "is_parked": false}})
|
||||
if got["utc"] != int64(testNowS) || got["soc"] != 50.0 || got["is_charging"] != 1 || got["is_parked"] != 0 {
|
||||
t.Fatalf("tlm %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestForwarderPicksOnlyTheNewestFreshSampleOncePerInterval(t *testing.T) {
|
||||
f := &Forwarder{MinInterval: 5 * time.Second}
|
||||
now := time.Unix(testNowS, 0)
|
||||
got, ok := f.pick([]TelemetrySample{{UTC: testNowS - 10}, {UTC: testNowS - 2}, {UTC: testNowS - 5}}, now)
|
||||
if !ok || got.UTC != testNowS-2 {
|
||||
t.Fatalf("picked %+v %v", got, ok)
|
||||
}
|
||||
if _, ok := f.pick([]TelemetrySample{{UTC: testNowS}}, now.Add(time.Second)); ok {
|
||||
t.Fatal("forwarded again within the interval")
|
||||
}
|
||||
if _, ok := f.pick([]TelemetrySample{{UTC: testNowS - 3}}, now.Add(time.Minute)); ok {
|
||||
t.Fatal("forwarded an older sample than the last one")
|
||||
}
|
||||
// A sample from ten minutes ago describes a car that has moved on.
|
||||
fresh := &Forwarder{MinInterval: 5 * time.Second}
|
||||
if _, ok := fresh.pick([]TelemetrySample{{UTC: testNowS - 600}}, now); ok {
|
||||
t.Fatal("forwarded a stale sample")
|
||||
}
|
||||
// A sample from a clock a day ahead is skipped, and does not block the real ones after it.
|
||||
ahead := &Forwarder{MinInterval: 5 * time.Second}
|
||||
got, ok = ahead.pick([]TelemetrySample{{UTC: testNowS + 86400}, {UTC: testNowS - 1}}, now)
|
||||
if !ok || got.UTC != testNowS-1 {
|
||||
t.Fatalf("picked %+v %v", got, ok)
|
||||
}
|
||||
if _, ok := ahead.pick([]TelemetrySample{{UTC: testNowS + 86400}}, now.Add(time.Minute)); ok {
|
||||
t.Fatal("forwarded a sample from the future")
|
||||
}
|
||||
if _, ok := ahead.pick([]TelemetrySample{{UTC: testNowS + 60}}, now.Add(time.Minute)); !ok {
|
||||
t.Fatal("a real sample after a future one was not forwarded")
|
||||
}
|
||||
}
|
||||
|
||||
func TestForwarderPutsCredentialsInTheBodyNotTheURL(t *testing.T) {
|
||||
received := make(chan *http.Request, 1)
|
||||
var form url.Values
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
form, _ = url.ParseQuery(string(body))
|
||||
received <- r
|
||||
}))
|
||||
defer srv.Close()
|
||||
f := &Forwarder{APIKey: "key-123", UserToken: "token-456", Endpoint: srv.URL + "/1/tlm/send"}
|
||||
if err := f.send(t.Context(), TelemetrySample{UTC: testNowS, Numbers: map[string]float64{"soc": 80}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := <-received
|
||||
if r.URL.RawQuery != "" {
|
||||
t.Fatalf("credentials leaked into the URL: %s", r.URL.RawQuery)
|
||||
}
|
||||
if form.Get("api_key") != "key-123" || form.Get("token") != "token-456" || form.Get("tlm") != `{"soc":80,"utc":1790000000}` {
|
||||
t.Fatalf("form %v", form)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadConfigFailsClosed(t *testing.T) {
|
||||
env := map[string]string{
|
||||
"INFLUX_URL": "http://influxdb:8086", "INFLUX_TOKEN": "t", "INFLUX_ORG": "mg4",
|
||||
@@ -118,7 +52,7 @@ func TestLoadConfigFailsClosed(t *testing.T) {
|
||||
}
|
||||
get := func(k string) string { return env[k] }
|
||||
c, err := loadConfig(get)
|
||||
if err != nil || c.listenAddr != ":8080" || c.influxBucket != "mg4" || c.abrpMinInterval != 5*time.Second {
|
||||
if err != nil || c.listenAddr != ":8080" || c.influxBucket != "mg4" {
|
||||
t.Fatalf("defaults: %+v %v", c, err)
|
||||
}
|
||||
env["INGEST_TOKEN"] = "short"
|
||||
|
||||
Reference in New Issue
Block a user