1- import { it , afterEach , vi , expect , describe } from "vitest" ;
1+ import { it , afterEach , vi , expect , describe , beforeEach } from "vitest" ;
22
33import {
4- SSHConfig ,
4+ SshConfig ,
55 parseCoderSshOptions ,
66 parseSshConfig ,
77 mergeSshConfigValues ,
88} from "@/remote/sshConfig" ;
99
10+ import { createMockLogger } from "../../mocks/testHelpers" ;
11+
1012// This is not the usual path to ~/.ssh/config, but
1113// setting it to a different path makes it easier to test
1214// and makes mistakes abundantly clear.
@@ -25,6 +27,8 @@ const mockFileSystem = {
2527 writeFile : vi . fn ( ) ,
2628} ;
2729
30+ const mockLogger = createMockLogger ( ) ;
31+
2832afterEach ( ( ) => {
2933 vi . clearAllMocks ( ) ;
3034} ) ;
@@ -33,7 +37,7 @@ it("creates a new file and adds config with empty label", async () => {
3337 mockFileSystem . readFile . mockRejectedValueOnce ( "No file found" ) ;
3438 mockFileSystem . stat . mockRejectedValueOnce ( { code : "ENOENT" } ) ;
3539
36- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
40+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
3741 await sshConfig . load ( ) ;
3842 await sshConfig . update ( "" , {
3943 Host : "coder-vscode--*" ,
@@ -76,7 +80,7 @@ it("creates a new file and adds the config", async () => {
7680 mockFileSystem . readFile . mockRejectedValueOnce ( "No file found" ) ;
7781 mockFileSystem . stat . mockRejectedValueOnce ( { code : "ENOENT" } ) ;
7882
79- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
83+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
8084 await sshConfig . load ( ) ;
8185 await sshConfig . update ( "dev.coder.com" , {
8286 Host : "coder-vscode.dev.coder.com--*" ,
@@ -126,7 +130,7 @@ it("adds a new coder config in an existent SSH configuration", async () => {
126130 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
127131 mockFileSystem . stat . mockResolvedValueOnce ( { mode : 0o644 } ) ;
128132
129- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
133+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
130134 await sshConfig . load ( ) ;
131135 await sshConfig . update ( "dev.coder.com" , {
132136 Host : "coder-vscode.dev.coder.com--*" ,
@@ -197,7 +201,7 @@ Host *
197201 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
198202 mockFileSystem . stat . mockResolvedValueOnce ( { mode : 0o644 } ) ;
199203
200- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
204+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
201205 await sshConfig . load ( ) ;
202206 await sshConfig . update ( "dev.coder.com" , {
203207 Host : "coder-vscode.dev-updated.coder.com--*" ,
@@ -255,7 +259,7 @@ Host coder-vscode--*
255259 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
256260 mockFileSystem . stat . mockResolvedValueOnce ( { mode : 0o644 } ) ;
257261
258- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
262+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
259263 await sshConfig . load ( ) ;
260264 await sshConfig . update ( "dev.coder.com" , {
261265 Host : "coder-vscode.dev.coder.com--*" ,
@@ -298,7 +302,7 @@ it("it does not remove a user-added block that only matches the host of an old c
298302 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
299303 mockFileSystem . stat . mockResolvedValueOnce ( { mode : 0o644 } ) ;
300304
301- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
305+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
302306 await sshConfig . load ( ) ;
303307 await sshConfig . update ( "dev.coder.com" , {
304308 Host : "coder-vscode.dev.coder.com--*" ,
@@ -355,7 +359,7 @@ Host afterconfig
355359 HostName after.config.tld
356360 User after` ;
357361
358- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
362+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
359363 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
360364 await sshConfig . load ( ) ;
361365
@@ -410,7 +414,7 @@ Host afterconfig
410414 HostName after.config.tld
411415 User after` ;
412416
413- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
417+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
414418 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
415419 await sshConfig . load ( ) ;
416420
@@ -461,7 +465,7 @@ Host afterconfig
461465 HostName after.config.tld
462466 User after` ;
463467
464- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
468+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
465469 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
466470 await sshConfig . load ( ) ;
467471
@@ -511,7 +515,7 @@ Host afterconfig
511515 HostName after.config.tld
512516 User after` ;
513517
514- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
518+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
515519 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
516520 await sshConfig . load ( ) ;
517521
@@ -561,7 +565,7 @@ Host afterconfig
561565 HostName after.config.tld
562566 User after` ;
563567
564- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
568+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
565569 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
566570 mockFileSystem . stat . mockResolvedValueOnce ( { mode : 0o644 } ) ;
567571 await sshConfig . load ( ) ;
@@ -624,7 +628,7 @@ it("override values", async () => {
624628 mockFileSystem . readFile . mockRejectedValueOnce ( "No file found" ) ;
625629 mockFileSystem . stat . mockRejectedValueOnce ( { code : "ENOENT" } ) ;
626630
627- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
631+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
628632 await sshConfig . load ( ) ;
629633 await sshConfig . update (
630634 "dev.coder.com" ,
@@ -683,7 +687,7 @@ it("fails if we are unable to write the temporary file", async () => {
683687 HostName before.config.tld
684688 User before` ;
685689
686- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
690+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
687691 mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig ) ;
688692 mockFileSystem . stat . mockResolvedValueOnce ( { mode : 0o600 } ) ;
689693 mockFileSystem . writeFile . mockRejectedValueOnce ( new Error ( "EACCES" ) ) ;
@@ -714,7 +718,7 @@ it("cleans up temp file when rename fails", async () => {
714718 ( err as NodeJS . ErrnoException ) . code = "EXDEV" ;
715719 mockFileSystem . rename . mockRejectedValueOnce ( err ) ;
716720
717- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
721+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
718722 await sshConfig . load ( ) ;
719723 await expect (
720724 sshConfig . update ( "dev.coder.com" , {
@@ -755,7 +759,7 @@ describe("rename retry on Windows", () => {
755759 . mockRejectedValueOnce ( err )
756760 . mockResolvedValueOnce ( undefined ) ;
757761
758- const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem ) ;
762+ const sshConfig = new SshConfig ( sshFilePath , mockLogger , mockFileSystem ) ;
759763 await sshConfig . load ( ) ;
760764 const promise = sshConfig . update ( "dev.coder.com" , {
761765 Host : "coder-vscode.dev.coder.com--*" ,
0 commit comments