@@ -1009,6 +1009,70 @@ func TestNonSearchableWorkingDirectory(t *testing.T) {
1009
1009
}
1010
1010
}
1011
1011
1012
+ // NOTE(gvisor.dev/issue/11910): Regression test. Make sure that working
1013
+ // directory can be set to a symlinked path.
1014
+ func TestSymlinkWorkingDirectory (t * testing.T ) {
1015
+ ctx := context .Background ()
1016
+ d := dockerutil .MakeContainer (ctx , t )
1017
+ defer d .CleanUp (ctx )
1018
+
1019
+ dir , err := os .MkdirTemp (testutil .TmpDir (), "symlink-workdir" )
1020
+ if err != nil {
1021
+ t .Fatalf ("MkdirTemp() failed: %v" , err )
1022
+ }
1023
+ defer os .RemoveAll (dir )
1024
+
1025
+ // Create the actual target directory
1026
+ targetDir := filepath .Join (dir , "actual-dir" )
1027
+ if err := os .Mkdir (targetDir , 0755 ); err != nil {
1028
+ t .Fatalf ("Mkdir() failed: %v" , err )
1029
+ }
1030
+
1031
+ // Create a symlink pointing to the target directory
1032
+ symlinkPath := filepath .Join (dir , "symlink-to-dir" )
1033
+ if err := os .Symlink ("actual-dir" , symlinkPath ); err != nil {
1034
+ t .Fatalf ("Symlink() failed: %v" , err )
1035
+ }
1036
+
1037
+ // Mount the temp directory and set working directory to the symlink
1038
+ opts := dockerutil.RunOpts {
1039
+ Image : "basic/alpine" ,
1040
+ WorkDir : "/test/symlink-to-dir" ,
1041
+ Mounts : []mount.Mount {
1042
+ {
1043
+ Type : mount .TypeBind ,
1044
+ Source : dir ,
1045
+ Target : "/test" ,
1046
+ },
1047
+ },
1048
+ }
1049
+
1050
+ // Test that the container can start with symlinked working directory
1051
+ // and that pwd returns the symlinked path
1052
+ got , err := d .Run (ctx , opts , "sh" , "-c" , "pwd" )
1053
+ if err != nil {
1054
+ t .Fatalf ("docker run failed: %v" , err )
1055
+ }
1056
+
1057
+ want := "/test/symlink-to-dir\n "
1058
+ if got != want {
1059
+ t .Errorf ("working directory mismatch, want: %q, got: %q" , want , got )
1060
+ }
1061
+
1062
+ // Additional test: verify we can actually use the working directory
1063
+ // by creating a file in it
1064
+ _ , err = d .Run (ctx , opts , "sh" , "-c" , "echo 'test content' > testfile && cat testfile" )
1065
+ if err != nil {
1066
+ t .Fatalf ("docker run failed: %v" , err )
1067
+ }
1068
+
1069
+ // Verify the file was created in the actual target directory
1070
+ createdFile := filepath .Join (targetDir , "testfile" )
1071
+ if _ , err := os .Stat (createdFile ); err != nil {
1072
+ t .Errorf ("file was not created in target directory: %v" , err )
1073
+ }
1074
+ }
1075
+
1012
1076
func TestCharDevice (t * testing.T ) {
1013
1077
if testutil .IsRunningWithOverlay () {
1014
1078
t .Skip ("files are not available outside the sandbox with overlay." )
0 commit comments