@@ -753,3 +753,54 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
753753 })
754754 }
755755}
756+
757+ func TestConfigSSH_SnapEnvironment (t * testing.T ) {
758+ if runtime .GOOS == "windows" {
759+ t .Skip ("Snap is not available on Windows" )
760+ }
761+
762+ client := coderdtest .New (t , nil )
763+ _ = coderdtest .CreateFirstUser (t , client )
764+
765+ // Create a temporary directory that simulates the real home
766+ realHome := t .TempDir ()
767+ realSSHDir := filepath .Join (realHome , ".ssh" )
768+ err := os .MkdirAll (realSSHDir , 0o700 )
769+ require .NoError (t , err )
770+ realSSHConfig := filepath .Join (realSSHDir , "config" )
771+
772+ // Create a separate directory that simulates the snap home
773+ snapHome := t .TempDir ()
774+
775+ // Set SNAP_REAL_HOME to point to the real home directory
776+ t .Setenv ("SNAP_REAL_HOME" , realHome )
777+ // Set HOME to the snap directory to simulate snap environment
778+ t .Setenv ("HOME" , snapHome )
779+
780+ // Run config-ssh with default path (~/. ssh/config)
781+ // It should use SNAP_REAL_HOME and write to realSSHConfig
782+ args := []string {
783+ "config-ssh" ,
784+ "--yes" , // Skip confirmation prompts
785+ }
786+ inv , root := clitest .New (t , args ... )
787+ clitest .SetupConfig (t , client , root )
788+
789+ err = inv .Run ()
790+ require .NoError (t , err , "config-ssh should succeed in snap environment" )
791+
792+ // Verify that the config file was written to the REAL home directory,
793+ // not the snap home directory
794+ _ , err = os .Stat (realSSHConfig )
795+ require .NoError (t , err , "config file should exist in real home directory" )
796+
797+ // Verify the config file contains the expected coder section
798+ content , err := os .ReadFile (realSSHConfig )
799+ require .NoError (t , err )
800+ require .Contains (t , string (content ), "# ------------START-CODER-----------" , "config should contain coder section" )
801+
802+ // Verify that nothing was written to the snap home directory
803+ snapSSHConfig := filepath .Join (snapHome , ".ssh" , "config" )
804+ _ , err = os .Stat (snapSSHConfig )
805+ require .True (t , os .IsNotExist (err ), "config file should NOT exist in snap home directory" )
806+ }
0 commit comments