mirror of
https://github.com/coder/coder.git
synced 2026-06-04 05:28:20 +00:00
962608cde0
Closes coder/internal#168 Gets rid of the "global state" authentication, and adds a `login` helper which should be called at the beginning of each test. This means that not every test needs to authenticated as admin, and we can even have tests that encompass multiple permission levels. We also now create more than just the single admin user during setup, so that we can have a set of users to pick from as appropriate.
69 lines
1.5 KiB
TypeScript
69 lines
1.5 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import { test } from "@playwright/test";
|
|
import {
|
|
createTemplate,
|
|
createWorkspace,
|
|
downloadCoderVersion,
|
|
login,
|
|
sshIntoWorkspace,
|
|
startAgentWithCommand,
|
|
stopAgent,
|
|
stopWorkspace,
|
|
} from "../helpers";
|
|
import { beforeCoderTest } from "../hooks";
|
|
|
|
// we no longer support versions w/o DRPC
|
|
const agentVersion = "v2.12.1";
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
beforeCoderTest(page);
|
|
await login(page);
|
|
});
|
|
|
|
test(`ssh with agent ${agentVersion}`, async ({ page }) => {
|
|
test.setTimeout(60_000);
|
|
|
|
const token = randomUUID();
|
|
const template = await createTemplate(page, {
|
|
apply: [
|
|
{
|
|
apply: {
|
|
resources: [
|
|
{
|
|
agents: [
|
|
{
|
|
token,
|
|
order: 0,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
],
|
|
});
|
|
const workspaceName = await createWorkspace(page, template);
|
|
const binaryPath = await downloadCoderVersion(agentVersion);
|
|
const agent = await startAgentWithCommand(page, token, binaryPath);
|
|
|
|
const client = await sshIntoWorkspace(page, workspaceName);
|
|
await new Promise<void>((resolve, reject) => {
|
|
// We just exec a command to be certain the agent is running!
|
|
client.exec("exit 0", (err, stream) => {
|
|
if (err) {
|
|
return reject(err);
|
|
}
|
|
stream.on("exit", (code) => {
|
|
if (code !== 0) {
|
|
return reject(new Error(`Command exited with code ${code}`));
|
|
}
|
|
client.end();
|
|
resolve();
|
|
});
|
|
});
|
|
});
|
|
|
|
await stopWorkspace(page, workspaceName);
|
|
await stopAgent(agent, false);
|
|
});
|