Skip to content

chore: add e2e test for backwards ssh compatibility #8761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fmt
  • Loading branch information
kylecarbs committed Jul 27, 2023
commit 8cff979b815967d08cfda5c51cfd48d1ce5e8646
75 changes: 50 additions & 25 deletions site/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,23 @@ export const createTemplate = async (
}

// sshIntoWorkspace spawns a Coder SSH process and a client connected to it.
export const sshIntoWorkspace = async (page: Page, workspace: string): Promise<ssh.Client> => {
export const sshIntoWorkspace = async (
page: Page,
workspace: string,
): Promise<ssh.Client> => {
const sessionToken = await findSessionToken(page)
return new Promise<ssh.Client>((resolve, reject) => {
const cp = spawn("go", ["run", coderMainPath(), "ssh", "--stdio", workspace], {
env: {
...process.env,
CODER_SESSION_TOKEN: sessionToken,
CODER_URL: "http://localhost:3000",
const cp = spawn(
"go",
["run", coderMainPath(), "ssh", "--stdio", workspace],
{
env: {
...process.env,
CODER_SESSION_TOKEN: sessionToken,
CODER_URL: "http://localhost:3000",
},
},
})
)
cp.on("error", (err) => reject(err))
const proxyStream = new Duplex({
read: (size) => {
Expand All @@ -82,11 +89,11 @@ export const sshIntoWorkspace = async (page: Page, workspace: string): Promise<s
// eslint-disable-next-line no-console -- Helpful for debugging
cp.stderr.on("data", (data) => console.log(data.toString()))
cp.stdout.on("readable", (...args) => {
proxyStream.emit('readable', ...args);
proxyStream.emit("readable", ...args)
if (cp.stdout.readableLength > 0) {
proxyStream.emit("data", cp.stdout.read());
proxyStream.emit("data", cp.stdout.read())
}
});
})
const client = new ssh.Client()
client.connect({
sock: proxyStream,
Expand All @@ -107,7 +114,9 @@ export const startAgent = async (page: Page, token: string): Promise<void> => {

// downloadCoderVersion downloads the version provided into a temporary dir and
// caches it so subsequent calls are fast.
export const downloadCoderVersion = async (version: string): Promise<string> => {
export const downloadCoderVersion = async (
version: string,
): Promise<string> => {
if (version.startsWith("v")) {
version = version.slice(1)
}
Expand All @@ -131,15 +140,26 @@ export const downloadCoderVersion = async (version: string): Promise<string> =>
// Runs our public install script using our options to
// install the binary!
await new Promise<void>((resolve, reject) => {
const cp = spawn("sh", ["-c", [
"curl", "-L", "https://coder.com/install.sh",
"|",
"sh", "-s", "--",
"--version", version,
"--method", "standalone",
"--prefix", tempDir,
"--binary-name", binaryName,
].join(" ")])
const cp = spawn("sh", [
"-c",
[
"curl",
"-L",
"https://coder.com/install.sh",
"|",
"sh",
"-s",
"--",
"--version",
version,
"--method",
"standalone",
"--prefix",
tempDir,
"--binary-name",
binaryName,
].join(" "),
])
// eslint-disable-next-line no-console -- Needed for debugging
cp.stderr.on("data", (data) => console.log(data.toString()))
cp.on("close", (code) => {
Expand All @@ -153,7 +173,12 @@ export const downloadCoderVersion = async (version: string): Promise<string> =>
return binaryPath
}

export const startAgentWithCommand = async (page: Page, token: string, command: string, ...args: string[]): Promise<void> => {
export const startAgentWithCommand = async (
page: Page,
token: string,
command: string,
...args: string[]
): Promise<void> => {
const cp = spawn(command, [...args, "agent", "--no-reap"], {
env: {
...process.env,
Expand Down Expand Up @@ -188,10 +213,10 @@ const coderMainPath = (): string => {
// Allows users to more easily define properties they want for agents and resources!
type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends (infer U)[]
? RecursivePartial<U>[]
: T[P] extends object | undefined
? RecursivePartial<T[P]>
: T[P]
? RecursivePartial<U>[]
: T[P] extends object | undefined
? RecursivePartial<T[P]>
: T[P]
}

interface EchoProvisionerResponses {
Expand Down
12 changes: 9 additions & 3 deletions site/e2e/tests/outdatedAgent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { test } from "@playwright/test"
import { randomUUID } from "crypto"
import { createTemplate, createWorkspace, downloadCoderVersion, sshIntoWorkspace, startAgentWithCommand } from "../helpers"
import {
createTemplate,
createWorkspace,
downloadCoderVersion,
sshIntoWorkspace,
startAgentWithCommand,
} from "../helpers"

const agentVersion = "v0.14.0"

Expand Down Expand Up @@ -38,9 +44,9 @@ test("ssh with agent " + agentVersion, async ({ page }) => {
if (code !== 0) {
return reject(new Error(`Command exited with code ${code}`))
}
client.end();
client.end()
resolve()
});
})
})
})
})