Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/agent-device/local-profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ import {
import { FakeDriver, fakeDeviceDataTables } from "../core/testing.js";
import { startDaemon, type StartDaemonOptions } from "../daemon/main.js";
import type { DaemonServer } from "../daemon/server.js";
import { FakeClock, JsonLinesLogger, MemoryFilesystem, MemoryLogSink } from "../ports/index.js";
import {
FakeClock,
JsonLinesLogger,
MemoryFilesystem,
MemoryLogSink,
NoopLogger,
} from "../ports/index.js";
import { seedTokensDatabase } from "../auth/testing.js";
import { createModuleHost } from "../modules/index.js";
import { fakeModuleTokens, fakeWorkerContext } from "../modules/testing.js";
import { removeDirectory } from "../test-support/remove-directory.js";
import { agentDeviceModuleWith, FakeAgentDevice } from "./testing.js";

Expand Down Expand Up @@ -311,6 +319,32 @@ describe("the local agent-device profile", () => {
}
});

it("names a listen address that is no wildcard as it is", async () => {
// why: the module host alone, because a daemon cannot listen on an address the test machine does not have.
const { ctx } = await fakeWorkerContext("agent-device", {});
const definition = agentDeviceModuleWith({ upstream: new FakeAgentDevice() });
const host = await createModuleHost({
config: {
...ctx.daemonConfig,
capabilities: { "agent-device": { command: "fake-agent-device", enabled: true } },
http: { ...ctx.daemonConfig.http, enabled: true, host: "192.0.2.20", port: 4701 },
},
context: ctx,
definitions: [definition],
logger: new NoopLogger(),
role: "worker",
tokens: fakeModuleTokens(),
});

await ctx.filesystem.mkdirp(ctx.dataDirectory);
await host.prepareLocalProfiles();

const path = join(ctx.dataDirectory, "agent-device-profile.json");
expect(JSON.parse(await ctx.filesystem.readFile(path))).toMatchObject({
daemonBaseUrl: "http://192.0.2.20:4701/v1/agent-device",
});
});

it("keeps the profile across a restart, and replaces a token that no longer verifies", async () => {
const readProfile = async (rig: Rig) => {
const text = await rig.filesystem.readFile(rig.profilePath);
Expand Down
1 change: 1 addition & 0 deletions src/modules/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
} from "./types.js";
import { errorMessage } from "../shared/index.js";

// why: HTTP listens on `host` alone, so only a wildcard bind is sure to answer on loopback; any other address is named as it is.
function profileOrigin(host: string, port: number): string {
const reachable = host === "0.0.0.0" || host === "::" ? "127.0.0.1" : host;
return `http://${reachable.includes(":") ? `[${reachable}]` : reachable}:${String(port)}`;
Expand Down
9 changes: 9 additions & 0 deletions website/src/content/docs/docs/using-devices/agent-device.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ agent-device close --session s1
- A worker that has joined a gateway does not write the file.
- The file's token is labelled `agent-device on this Mac`. Do not give your own tokens that label: the worker revokes them at its next start.

### If the worker listens on one network address

The file reaches the worker on this Mac's loopback when `http.host` is `127.0.0.1` (the default), `localhost`, `::1`, `0.0.0.0` or `::`. With one network address, such as `192.168.1.20`, the worker listens only there, so the file names that address over plain `http://`. agent-device 0.22+ refuses to send the token to it; 0.21.x warns.

Do one of these:

- Set `http.host` back to `127.0.0.1` and restart the daemon ([Change the address or port](/simlock/docs/worker/console-and-http#change-the-address-or-port)). Agents on other machines then connect through your HTTPS proxy on this Mac.
- Keep the address, and set `AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT=1` in the environment where the local agent runs `agent-device`. This allows plain `http://` to any host from those commands, not only to this Mac.

## Use a real phone

`open --physical` leases an enrolled phone, and the reply names it with `physical: true`. See [Lease a real iPhone or Android phone](/simlock/docs/using-devices/lease-a-phone). Phones need setup on the worker:
Expand Down
Loading