@@ -607,3 +607,52 @@ Host coder-vscode.dev.coder.com--*
607607 )
608608 expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringMatching ( sshTempFilePathExpr ) , sshFilePath )
609609} )
610+
611+ it ( "fails if we are unable to write the temporary file" , async ( ) => {
612+ const existentSSHConfig = `Host beforeconfig
613+ HostName before.config.tld
614+ User before`
615+
616+ const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem )
617+ mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig )
618+ mockFileSystem . stat . mockResolvedValueOnce ( { mode : 0o600 } )
619+ mockFileSystem . writeFile . mockRejectedValueOnce ( new Error ( "EACCES" ) )
620+
621+ await sshConfig . load ( )
622+
623+ expect ( mockFileSystem . readFile ) . toBeCalledWith ( sshFilePath , expect . anything ( ) )
624+ await expect (
625+ sshConfig . update ( "dev.coder.com" , {
626+ Host : "coder-vscode.dev.coder.com--*" ,
627+ ProxyCommand : "some-command-here" ,
628+ ConnectTimeout : "0" ,
629+ StrictHostKeyChecking : "no" ,
630+ UserKnownHostsFile : "/dev/null" ,
631+ LogLevel : "ERROR" ,
632+ } ) ,
633+ ) . rejects . toThrow ( / F a i l e d t o w r i t e t e m p o r a r y S S H c o n f i g f i l e .* E A C C E S / )
634+ } )
635+
636+ it ( "fails if we are unable to rename the temporary file" , async ( ) => {
637+ const existentSSHConfig = `Host beforeconfig
638+ HostName before.config.tld
639+ User before`
640+
641+ const sshConfig = new SSHConfig ( sshFilePath , mockFileSystem )
642+ mockFileSystem . readFile . mockResolvedValueOnce ( existentSSHConfig )
643+ mockFileSystem . stat . mockResolvedValueOnce ( { mode : 0o600 } )
644+ mockFileSystem . writeFile . mockResolvedValueOnce ( "" )
645+ mockFileSystem . rename . mockRejectedValueOnce ( new Error ( "EACCES" ) )
646+
647+ await sshConfig . load ( )
648+ await expect (
649+ sshConfig . update ( "dev.coder.com" , {
650+ Host : "coder-vscode.dev.coder.com--*" ,
651+ ProxyCommand : "some-command-here" ,
652+ ConnectTimeout : "0" ,
653+ StrictHostKeyChecking : "no" ,
654+ UserKnownHostsFile : "/dev/null" ,
655+ LogLevel : "ERROR" ,
656+ } ) ,
657+ ) . rejects . toThrow ( / F a i l e d t o r e n a m e t e m p o r a r y S S H c o n f i g f i l e .* E A C C E S / )
658+ } )
0 commit comments