Skip to content

fix: replace ssh config block in-place #211

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 2 commits into from
Feb 9, 2024
Merged
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
add one more test for old block
  • Loading branch information
mafredri committed Feb 9, 2024
commit 89d2f0f1d33f49fe10c0e02812f8452a4564fb41
34 changes: 34 additions & 0 deletions src/sshConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,40 @@ Host coder-vscode--*
})
})

it("it does not remove a user-added block that only matches the host of an old coder SSH config", async () => {
const existentSSHConfig = `Host coder-vscode--*
ForwardAgent=yes`
mockFileSystem.readFile.mockResolvedValueOnce(existentSSHConfig)

const sshConfig = new SSHConfig(sshFilePath, mockFileSystem)
await sshConfig.load()
await sshConfig.update({
Host: "coder-vscode--*",
ProxyCommand: "some-command-here",
ConnectTimeout: "0",
StrictHostKeyChecking: "no",
UserKnownHostsFile: "/dev/null",
LogLevel: "ERROR",
})

const expectedOutput = `Host coder-vscode--*
ForwardAgent=yes

# --- START CODER VSCODE ---
Host coder-vscode--*
ConnectTimeout 0
LogLevel ERROR
ProxyCommand some-command-here
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
# --- END CODER VSCODE ---`

expect(mockFileSystem.writeFile).toBeCalledWith(sshFilePath, expectedOutput, {
encoding: "utf-8",
mode: 384,
})
})

it("override values", async () => {
mockFileSystem.readFile.mockRejectedValueOnce("No file found")
const sshConfig = new SSHConfig(sshFilePath, mockFileSystem)
Expand Down