feat: replace openapi hashing system with /version

Apparently I didn't use my brain cells and rely on the /version
endpoint that Headscale has exposed since 0.26 (our lowest supported
version). Switching to that significantly simplifies the API surface.
This commit is contained in:
Aarnav Tale
2026-05-23 19:59:03 -04:00
parent d4eee702e9
commit 0512565f8e
59 changed files with 1123 additions and 1573 deletions
+30 -36
View File
@@ -1,65 +1,59 @@
import { describe, expect, test } from "vitest";
import type { HeadscaleApiInterface } from "~/server/headscale/api";
import nodeEndpoints from "~/server/headscale/api/endpoints/nodes";
import userEndpoints from "~/server/headscale/api/endpoints/users";
import { capabilitiesFor } from "~/server/headscale/api/capabilities";
import { makeNodeApi } from "~/server/headscale/api/resources/nodes";
import { makeUserApi } from "~/server/headscale/api/resources/users";
import { parseServerVersion } from "~/server/headscale/api/server-version";
import type { Transport, TransportRequest } from "~/server/headscale/api/transport";
type ApiFetchArgs = Parameters<HeadscaleApiInterface["clientHelpers"]["apiFetch"]>;
function createApiClientRecorder() {
const calls: Array<{
method: ApiFetchArgs[0];
apiPath: ApiFetchArgs[1];
apiKey: ApiFetchArgs[2];
bodyOrQuery: ApiFetchArgs[3];
}> = [];
const client = {
isAtleast: () => false,
rawFetch: async () => {
throw new Error("rawFetch should not be called");
},
apiFetch: async <T>(
method: ApiFetchArgs[0],
apiPath: ApiFetchArgs[1],
apiKey: ApiFetchArgs[2],
bodyOrQuery?: ApiFetchArgs[3],
) => {
calls.push({ method, apiPath, apiKey, bodyOrQuery });
function createTransportRecorder() {
const calls: TransportRequest[] = [];
const transport: Transport = {
async request<T>(opts: TransportRequest): Promise<T> {
calls.push(opts);
return undefined as T;
},
} as HeadscaleApiInterface["clientHelpers"];
return { calls, client };
async getPublic<T>(): Promise<T> {
throw new Error("getPublic should not be called");
},
async health() {
throw new Error("health should not be called");
},
async dispose() {},
};
return { calls, transport };
}
const capabilities = capabilitiesFor(parseServerVersion("0.28.0"));
describe("Headscale API path encoding", () => {
test("encodes node rename names as a single URL segment", async () => {
const { calls, client } = createApiClientRecorder();
const { calls, transport } = createTransportRecorder();
await nodeEndpoints(client, "api-key").renameNode("2", "../../1/expire");
await makeNodeApi(transport, capabilities, "api-key").rename("2", "../../1/expire");
expect(calls).toEqual([
{
method: "POST",
apiPath: "v1/node/2/rename/..%2F..%2F1%2Fexpire",
path: "v1/node/2/rename/..%2F..%2F1%2Fexpire",
apiKey: "api-key",
bodyOrQuery: undefined,
},
]);
});
test("encodes user rename names as a single URL segment", async () => {
const { calls, client } = createApiClientRecorder();
const { calls, transport } = createTransportRecorder();
await userEndpoints(client, "api-key").renameUser("3", "../../../user/4/rename/pwned-user@");
await makeUserApi(transport, capabilities, "api-key").rename(
"3",
"../../../user/4/rename/pwned-user@",
);
expect(calls).toEqual([
{
method: "POST",
apiPath: "v1/user/3/rename/..%2F..%2F..%2Fuser%2F4%2Frename%2Fpwned-user%40",
path: "v1/user/3/rename/..%2F..%2F..%2Fuser%2F4%2Frename%2Fpwned-user%40",
apiKey: "api-key",
bodyOrQuery: undefined,
},
]);
});