mirror of
https://github.com/tale/headplane.git
synced 2026-08-11 06:16:52 +00:00
test: add docker and proc e2e testing
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { getRuntimeClient, HS_VERSIONS } from "../setup/env";
|
||||
|
||||
describe.for(HS_VERSIONS)("Headscale %s: API Keys", (version) => {
|
||||
test("api keys can be fetched", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const apiKeys = await client.getApiKeys();
|
||||
expect(Array.isArray(apiKeys)).toBe(true);
|
||||
expect(apiKeys.length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { getBootstrapClient, getNode, getRuntimeClient, HS_VERSIONS } from "../setup/env";
|
||||
|
||||
describe.sequential.for(HS_VERSIONS)("Headscale %s: Users", (version) => {
|
||||
let workingNodeId: string;
|
||||
|
||||
test("nodes can register via their nodekey", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const tailnetNode = await getNode(version);
|
||||
|
||||
const user = await client.createUser("node-reg@");
|
||||
const node = await client.registerNode(user.name, tailnetNode.authCode);
|
||||
expect(node).toBeDefined();
|
||||
expect(node.registerMethod).toBe("REGISTER_METHOD_CLI");
|
||||
expect(node.name).toBe(tailnetNode.nodeName);
|
||||
});
|
||||
|
||||
test("nodes can be retrieved", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const { nodeName } = await getNode(version);
|
||||
const nodes = await client.getNodes();
|
||||
const node = nodes.find((n) => n.name === nodeName);
|
||||
expect(node).toBeDefined();
|
||||
expect(node?.name).toBe(nodeName);
|
||||
|
||||
const fetchedNode = await client.getNode(node!.id);
|
||||
expect(fetchedNode).toBeDefined();
|
||||
expect(fetchedNode.id).toBe(node!.id);
|
||||
workingNodeId = node!.id;
|
||||
});
|
||||
|
||||
test("nodes can be renamed", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const { nodeName } = await getNode(version);
|
||||
const newName = `${nodeName}-renamed`;
|
||||
|
||||
await client.renameNode(workingNodeId, newName);
|
||||
const renamedNode = await client.getNode(workingNodeId);
|
||||
expect(renamedNode).toBeDefined();
|
||||
expect(renamedNode.givenName).toBe(newName);
|
||||
});
|
||||
|
||||
test("nodes can be reassigned to another user", async (context) => {
|
||||
const bootstrap = await getBootstrapClient(version);
|
||||
if (bootstrap.clientHelpers.isAtleast("0.28.0")) {
|
||||
context.skip();
|
||||
}
|
||||
|
||||
const client = await getRuntimeClient(version);
|
||||
const user = await client.createUser("node-reassign@");
|
||||
|
||||
await client.setNodeUser(workingNodeId, user.id);
|
||||
const reassignedNode = await client.getNode(workingNodeId);
|
||||
expect(reassignedNode).toBeDefined();
|
||||
expect(reassignedNode.user.name).toBe(user.name);
|
||||
});
|
||||
|
||||
test("nodes can be expired", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
await client.expireNode(workingNodeId);
|
||||
|
||||
const expiredNode = await client.getNode(workingNodeId);
|
||||
expect(expiredNode).toBeDefined();
|
||||
expect(expiredNode.expiry).toBeDefined();
|
||||
});
|
||||
|
||||
test("nodes can be deleted", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
await client.deleteNode(workingNodeId);
|
||||
|
||||
const nodes = await client.getNodes();
|
||||
const node = nodes.find((n) => n.id === workingNodeId);
|
||||
expect(node).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,124 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { getBootstrapClient, getIsAtLeast, getRuntimeClient, HS_VERSIONS } from "../setup/env";
|
||||
|
||||
describe.sequential.for(HS_VERSIONS)("Headscale %s: Pre-auth Keys", (version) => {
|
||||
test("pre-auth keys can be created", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const preAuthKeyUser = await client.createUser("preauthkeyuser@");
|
||||
expect(preAuthKeyUser).toBeDefined();
|
||||
expect(preAuthKeyUser.name).toBe("preauthkeyuser@");
|
||||
|
||||
const expiry = new Date(Date.now() + 3600 * 1000);
|
||||
const preAuthKey = await client.createPreAuthKey(preAuthKeyUser.id, false, false, expiry, null);
|
||||
|
||||
expect(preAuthKey).toBeDefined();
|
||||
expect(preAuthKey.user?.id).toBe(preAuthKeyUser.id);
|
||||
expect(preAuthKey.ephemeral).toBe(false);
|
||||
expect(preAuthKey.reusable).toBe(false);
|
||||
expect(preAuthKey.aclTags).toEqual([]);
|
||||
expect(new Date(preAuthKey.expiration).getTime()).toBeCloseTo(expiry.getTime(), -2);
|
||||
});
|
||||
|
||||
test("pre-auth keys can be created with ACL tags", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const [preAuthKeyUser] = await client.getUsers(undefined, "preauthkeyuser@");
|
||||
expect(preAuthKeyUser).toBeDefined();
|
||||
expect(preAuthKeyUser.name).toBe("preauthkeyuser@");
|
||||
|
||||
const aclTags = ["tag:test1", "tag:test2"];
|
||||
const preAuthKey = await client.createPreAuthKey(preAuthKeyUser.id, true, true, null, aclTags);
|
||||
|
||||
expect(preAuthKey).toBeDefined();
|
||||
expect(preAuthKey.user?.id).toBe(preAuthKeyUser.id);
|
||||
expect(preAuthKey.ephemeral).toBe(true);
|
||||
expect(preAuthKey.reusable).toBe(true);
|
||||
expect(preAuthKey.aclTags.sort()).toEqual(aclTags.sort());
|
||||
});
|
||||
|
||||
test("tag-only pre-auth keys (0.28+)", async (context) => {
|
||||
const bootstrap = await getBootstrapClient(version);
|
||||
if (!bootstrap.clientHelpers.isAtleast("0.28.0")) {
|
||||
context.skip();
|
||||
}
|
||||
|
||||
const client = await getRuntimeClient(version);
|
||||
const aclTags = ["tag:server", "tag:prod"];
|
||||
const preAuthKey = await client.createPreAuthKey(null, false, true, null, aclTags);
|
||||
|
||||
expect(preAuthKey).toBeDefined();
|
||||
expect(preAuthKey.user).toBeNull();
|
||||
expect(preAuthKey.ephemeral).toBe(false);
|
||||
expect(preAuthKey.reusable).toBe(true);
|
||||
expect(preAuthKey.aclTags.sort()).toEqual(aclTags.sort());
|
||||
});
|
||||
|
||||
test("pre-auth keys can be listed", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const [preAuthKeyUser] = await client.getUsers(undefined, "preauthkeyuser@");
|
||||
expect(preAuthKeyUser).toBeDefined();
|
||||
expect(preAuthKeyUser.name).toBe("preauthkeyuser@");
|
||||
|
||||
const preAuthKeys = await client.getPreAuthKeys(preAuthKeyUser.id);
|
||||
expect(Array.isArray(preAuthKeys)).toBe(true);
|
||||
expect(preAuthKeys.length).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test("all pre-auth keys can be listed without user filter (0.28+)", async (context) => {
|
||||
const isAtLeast = await getIsAtLeast(version);
|
||||
if (!isAtLeast("0.28.0")) {
|
||||
context.skip();
|
||||
}
|
||||
|
||||
const client = await getRuntimeClient(version);
|
||||
const [preAuthKeyUser] = await client.getUsers(undefined, "preauthkeyuser@");
|
||||
expect(preAuthKeyUser).toBeDefined();
|
||||
|
||||
const allKeys = await client.getAllPreAuthKeys();
|
||||
expect(Array.isArray(allKeys)).toBe(true);
|
||||
expect(allKeys.length).toBeGreaterThanOrEqual(2);
|
||||
|
||||
const userSpecificKeys = await client.getPreAuthKeys(preAuthKeyUser.id);
|
||||
for (const userKey of userSpecificKeys) {
|
||||
const found = allKeys.find((k) => k.key === userKey.key);
|
||||
expect(found).toBeDefined();
|
||||
}
|
||||
});
|
||||
|
||||
test("getAllPreAuthKeys returns keys with correct structure (0.28+)", async (context) => {
|
||||
const isAtLeast = await getIsAtLeast(version);
|
||||
if (!isAtLeast("0.28.0")) {
|
||||
context.skip();
|
||||
}
|
||||
|
||||
const client = await getRuntimeClient(version);
|
||||
const allKeys = await client.getAllPreAuthKeys();
|
||||
|
||||
for (const key of allKeys) {
|
||||
expect(key.id).toBeDefined();
|
||||
expect(key.key).toBeDefined();
|
||||
expect(typeof key.reusable).toBe("boolean");
|
||||
expect(typeof key.ephemeral).toBe("boolean");
|
||||
expect(typeof key.used).toBe("boolean");
|
||||
expect(key.expiration).toBeDefined();
|
||||
expect(key.createdAt).toBeDefined();
|
||||
}
|
||||
});
|
||||
|
||||
test("pre-auth keys can be expired", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const [preAuthKeyUser] = await client.getUsers(undefined, "preauthkeyuser@");
|
||||
expect(preAuthKeyUser).toBeDefined();
|
||||
expect(preAuthKeyUser.name).toBe("preauthkeyuser@");
|
||||
|
||||
const preAuthKeys = await client.getPreAuthKeys(preAuthKeyUser.id);
|
||||
expect(preAuthKeys.length).toBeGreaterThanOrEqual(2);
|
||||
const preAuthKeyToExpire = preAuthKeys[0];
|
||||
|
||||
await client.expirePreAuthKey(preAuthKeyUser.id, preAuthKeyToExpire.key);
|
||||
|
||||
const preAuthKeysAfterExpire = await client.getPreAuthKeys(preAuthKeyUser.id);
|
||||
const expiredKey = preAuthKeysAfterExpire.find((key) => key.key === preAuthKeyToExpire.key);
|
||||
expect(expiredKey).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { getRuntimeClient, HS_VERSIONS } from "../setup/env";
|
||||
|
||||
describe.sequential.for(HS_VERSIONS)("Headscale %s: Users", (version) => {
|
||||
test("users can be created", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const user = await client.createUser("tale@");
|
||||
expect(user).toBeDefined();
|
||||
expect(user.name).toBe("tale@");
|
||||
});
|
||||
|
||||
test("users can be created with attributes", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const user = await client.createUser(
|
||||
"test-user@",
|
||||
"test-user@example.com",
|
||||
"Test User",
|
||||
"https://github.com/tale.png",
|
||||
);
|
||||
|
||||
expect(user).toBeDefined();
|
||||
expect(user.name).toBe("test-user@");
|
||||
expect(user.email).toBe("test-user@example.com");
|
||||
expect(user.displayName).toBe("Test User");
|
||||
expect(user.profilePicUrl).toBe("https://github.com/tale.png");
|
||||
});
|
||||
|
||||
test("users can be listed", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const users = await client.getUsers();
|
||||
expect(Array.isArray(users)).toBe(true);
|
||||
expect(users.length).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test("users can be listed by name", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const users = await client.getUsers(undefined, "tale@");
|
||||
expect(Array.isArray(users)).toBe(true);
|
||||
expect(users.length).toBe(1);
|
||||
expect(users[0].name).toBe("tale@");
|
||||
});
|
||||
|
||||
test("users can be listed by email", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const users = await client.getUsers(undefined, undefined, "test-user@example.com");
|
||||
expect(Array.isArray(users)).toBe(true);
|
||||
expect(users.length).toBe(1);
|
||||
expect(users[0].email).toBe("test-user@example.com");
|
||||
});
|
||||
|
||||
test("users can be renamed", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const usersBefore = await client.getUsers(undefined, "tale@");
|
||||
expect(usersBefore.length).toBe(1);
|
||||
const user = usersBefore[0];
|
||||
|
||||
await client.renameUser(user.id, "renamed-user@");
|
||||
const usersAfter = await client.getUsers(undefined, "renamed-user@");
|
||||
expect(usersAfter.length).toBe(1);
|
||||
expect(usersAfter[0].id).toBe(user.id);
|
||||
});
|
||||
|
||||
test("users can be deleted", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const usersBefore = await client.getUsers(undefined, "test-user@");
|
||||
expect(usersBefore.length).toBe(1);
|
||||
const user = usersBefore[0];
|
||||
|
||||
await client.deleteUser(user.id);
|
||||
const usersAfter = await client.getUsers(undefined, "test-user@");
|
||||
expect(usersAfter.length).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import canonicals from "~/openapi-canonical-families.json";
|
||||
|
||||
import { getBootstrapClient, getRuntimeClient, HS_VERSIONS, Version } from "../setup/env";
|
||||
|
||||
function getCanonicalVersion(version: Version) {
|
||||
const canonical = Object.entries(canonicals).find(([_, family]) =>
|
||||
family.includes(version),
|
||||
)?.[0] as Version | undefined;
|
||||
|
||||
if (!canonical) {
|
||||
return version;
|
||||
}
|
||||
|
||||
return canonical;
|
||||
}
|
||||
|
||||
describe.for(HS_VERSIONS)("Headscale %s: Runtime Client", (version) => {
|
||||
test("the runtime client is usable", async () => {
|
||||
const bootstrapper = await getBootstrapClient(version);
|
||||
const runtimeClient = bootstrapper.getRuntimeClient("test-api-key");
|
||||
expect(runtimeClient).toBeDefined();
|
||||
});
|
||||
|
||||
test("the runtime client has the correct canonical API version", async () => {
|
||||
const bootstrapper = await getBootstrapClient(version);
|
||||
expect(bootstrapper.apiVersion).toBe(getCanonicalVersion(version));
|
||||
});
|
||||
|
||||
test("the health check endpoint works", async () => {
|
||||
const client = await getRuntimeClient(version);
|
||||
const health = await client.isHealthy();
|
||||
expect(health).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user