Telemetry no longer loses queued batches. The server drops a bad value, or a sample without a plausible time, instead of rejecting the batch, and answers 200 with what it dropped. The app sends only values inside the server's ranges (speed as a magnitude, so reversing is fine) and no samples before the head unit's clock is set. Server: - Pairing hands out and accepts a token only after the device is saved; a failed save leaves the request pending. - A paired token serves only the installation id it was paired with (403 otherwise); the shared INGEST_TOKEN still serves any. - Wrong-password lockouts and open pairing requests are limited per client address (last X-Forwarded-For entry), so a stranger cannot lock the owner out; a car starting again replaces its own request. - ABRP forwarding skips samples stamped ahead of the server's clock, which used to stop it until a restart. App: - Settings written to plaintext during a keystore failure move back into encrypted storage; the stored installation id wins. - The installation id is derived from ANDROID_ID on first start, so a reinstall finds its history; a stored or imported id still wins. - The scanned config file is deleted after import (it holds the token). - GPS stops while live telemetry is off or the server unconfigured, and pauses while parked and idle, keeping the fix the car parked with. - Range estimates use the monotonic clock. - One HTTP helper (ServerHttp) for telemetry, sync and pairing. - Last Turkish strings translated; mise logs shows the NilsMG4 tags. Grafana reads InfluxDB with its own read-only token (new grafana-influx Secret, created by hand as described in k8s/README.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QLJfZQZeAKAwSqViTmLzki
65 lines
2.8 KiB
Java
65 lines
2.8 KiB
Java
package com.evsuite.abrp;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertNull;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import org.junit.Test;
|
|
|
|
/** What the Server tab and the config import accept — pure JVM. */
|
|
public class ServerConfigTest {
|
|
|
|
@Test
|
|
public void urlIsTrimmedAndLosesTrailingSlashes() {
|
|
assertEquals("https://car.example.com", ServerConfig.normalizeUrl(" https://car.example.com// "));
|
|
assertEquals("https://car.example.com/base", ServerConfig.normalizeUrl("https://car.example.com/base/"));
|
|
}
|
|
|
|
@Test
|
|
public void plainHttpAndJunkAreRefused() {
|
|
// The token travels in a header; over plain http anyone on the hotspot could read it.
|
|
assertNull(ServerConfig.normalizeUrl("http://car.example.com"));
|
|
assertNull(ServerConfig.normalizeUrl("car.example.com"));
|
|
assertNull(ServerConfig.normalizeUrl("https://"));
|
|
assertNull(ServerConfig.normalizeUrl("https:///path"));
|
|
assertNull(ServerConfig.normalizeUrl("https://user@car.example.com"));
|
|
assertNull(ServerConfig.normalizeUrl("https://car.example.com/?x=1"));
|
|
assertNull(ServerConfig.normalizeUrl(null));
|
|
}
|
|
|
|
@Test
|
|
public void tokenMustMeetTheServersMinimum() {
|
|
assertTrue(ServerConfig.isValidToken("0123456789abcdef01234567"));
|
|
assertFalse(ServerConfig.isValidToken("too-short"));
|
|
assertFalse(ServerConfig.isValidToken("0123456789abcdef 01234567"));
|
|
assertFalse(ServerConfig.isValidToken(null));
|
|
}
|
|
|
|
@Test
|
|
public void installationIdMustBeAUuidTheServerAccepts() {
|
|
assertTrue(ServerConfig.isValidInstallationId("6f1a2b3c-4d5e-4f60-8a9b-0c1d2e3f4a5b"));
|
|
assertTrue(ServerConfig.isValidInstallationId(java.util.UUID.randomUUID().toString()));
|
|
assertFalse(ServerConfig.isValidInstallationId("6f1a2b3c-4d5e-0f60-8a9b-0c1d2e3f4a5b")); // version 0
|
|
assertFalse(ServerConfig.isValidInstallationId("not-a-uuid"));
|
|
assertFalse(ServerConfig.isValidInstallationId(""));
|
|
}
|
|
|
|
@Test
|
|
public void theInstallationIdFollowsTheHeadUnit() {
|
|
String id = ServerConfig.installationIdFor("a1b2c3d4e5f60718");
|
|
assertTrue(id, ServerConfig.isValidInstallationId(id));
|
|
// The same head unit gets the same id after a reinstall; another gets another.
|
|
assertEquals(id, ServerConfig.installationIdFor(" A1B2C3D4E5F60718 "));
|
|
assertFalse(id.equals(ServerConfig.installationIdFor("0000000000000001")));
|
|
assertFalse(id.contains("a1b2c3d4e5f60718"));
|
|
}
|
|
|
|
@Test
|
|
public void noUsableAndroidIdMeansNoDerivedId() {
|
|
assertNull(ServerConfig.installationIdFor(null));
|
|
assertNull(ServerConfig.installationIdFor(""));
|
|
assertNull(ServerConfig.installationIdFor("9774d56d682e549c"));
|
|
}
|
|
}
|