|
1 | 1 | import type * as NodeOS from "node:os"; |
2 | 2 |
|
3 | 3 | import { describe, expect, it } from "@effect/vitest"; |
| 4 | +import * as NetAddress from "effect/net/NetAddress"; |
4 | 5 |
|
5 | 6 | import { |
6 | 7 | acceptsPrivateNetworkConnection, |
| 8 | + loopbackUrlHostForAddress, |
7 | 9 | resolveHeadlessConnectionString, |
8 | 10 | } from "./startupAccess.ts"; |
9 | 11 |
|
@@ -55,6 +57,18 @@ it("prefers a LAN address over a tailnet one for a private-network pairing URL", |
55 | 57 | ).toBe("http://192.168.1.42:3773"); |
56 | 58 | }); |
57 | 59 |
|
| 60 | +it("targets the bound interface when the listener binds a specific address", () => { |
| 61 | + const hostFor = (ip: string) => |
| 62 | + loopbackUrlHostForAddress(NetAddress.inetAddressFromIpStringUnsafe(ip, 3773)); |
| 63 | + |
| 64 | + expect(hostFor("0.0.0.0")).toBe("127.0.0.1"); |
| 65 | + expect(hostFor("::")).toBe("127.0.0.1"); |
| 66 | + expect(hostFor("::1")).toBe("[::1]"); |
| 67 | + expect(hostFor("127.0.0.1")).toBe("127.0.0.1"); |
| 68 | + expect(hostFor("127.0.0.2")).toBe("127.0.0.2"); |
| 69 | + expect(hostFor("100.101.102.103")).toBe("100.101.102.103"); |
| 70 | +}); |
| 71 | + |
58 | 72 | describe("acceptsPrivateNetworkConnection", () => { |
59 | 73 | const accepts = (localAddress: string | undefined, remoteAddress: string | undefined) => |
60 | 74 | acceptsPrivateNetworkConnection({ localAddress, remoteAddress }); |
|
0 commit comments