Configure hotspot credentials from dashboard
This commit is contained in:
@@ -3,7 +3,14 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import type { AppConfig } from "../src/config.js";
|
||||
import { consumeNetworkCommand, readNetworkStatus, requestNetworkAction } from "../src/network.js";
|
||||
import {
|
||||
consumeHotspotConfigurationRequest,
|
||||
consumeNetworkCommand,
|
||||
hotspotConfigurationSchema,
|
||||
readNetworkStatus,
|
||||
requestHotspotConfiguration,
|
||||
requestNetworkAction
|
||||
} from "../src/network.js";
|
||||
|
||||
const directories: string[] = [];
|
||||
|
||||
@@ -18,7 +25,12 @@ function config(directory: string, enabled = true): AppConfig {
|
||||
allowedOrigins: new Set(),
|
||||
updateStatusPath: join(directory, "update.json"),
|
||||
versionFile: join(directory, "REVISION"),
|
||||
network: { enabled, statusPath: join(directory, "status.json"), commandPath: join(directory, "command.json") },
|
||||
network: {
|
||||
enabled,
|
||||
statusPath: join(directory, "status.json"),
|
||||
commandPath: join(directory, "command.json"),
|
||||
configurationRequestPath: join(directory, "configuration.json")
|
||||
},
|
||||
adb: { enabled: false, executable: "adb", serial: null, timeoutMs: 3_000 }
|
||||
};
|
||||
}
|
||||
@@ -49,4 +61,21 @@ describe("network control boundary", () => {
|
||||
await writeFile(testConfig.network.statusPath, '{"mode":"shell"}');
|
||||
await expect(readNetworkStatus(testConfig)).resolves.toMatchObject({ supported: false, mode: "starting" });
|
||||
});
|
||||
|
||||
it("validates and transfers hotspot credentials only through the root request file", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "pi-car-network-test-"));
|
||||
directories.push(directory);
|
||||
const testConfig = config(directory, false);
|
||||
expect(hotspotConfigurationSchema.safeParse({ ssid: "MG4 Car", password: "Strong pass!2" }).success).toBe(true);
|
||||
expect(hotspotConfigurationSchema.safeParse({ ssid: "bad/name", password: "Strong pass!2" }).success).toBe(false);
|
||||
expect(hotspotConfigurationSchema.safeParse({ ssid: "MG4 Car", password: "short" }).success).toBe(false);
|
||||
|
||||
await requestHotspotConfiguration(testConfig, { ssid: "MG4 Car", password: "Strong pass!2" }, 7, async () => undefined);
|
||||
await expect(consumeHotspotConfigurationRequest(testConfig.network.configurationRequestPath)).resolves.toMatchObject({
|
||||
ssid: "MG4 Car",
|
||||
password: "Strong pass!2",
|
||||
actorUserId: 7
|
||||
});
|
||||
await expect(readFile(testConfig.network.configurationRequestPath, "utf8")).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user