-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add test for workdir being a symlink to another folder #11915
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
Open
ekzhang
wants to merge
1
commit into
google:master
Choose a base branch
from
ekzhang:add-test-symlink-workdir
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1009,6 +1009,70 @@ func TestNonSearchableWorkingDirectory(t *testing.T) { | |
} | ||
} | ||
|
||
// NOTE(gvisor.dev/issue/11910): Regression test. Make sure that working | ||
// directory can be set to a symlinked path. | ||
func TestSymlinkWorkingDirectory(t *testing.T) { | ||
ctx := context.Background() | ||
d := dockerutil.MakeContainer(ctx, t) | ||
defer d.CleanUp(ctx) | ||
|
||
dir, err := os.MkdirTemp(testutil.TmpDir(), "symlink-workdir") | ||
if err != nil { | ||
t.Fatalf("MkdirTemp() failed: %v", err) | ||
} | ||
defer os.RemoveAll(dir) | ||
|
||
// Create the actual target directory | ||
targetDir := filepath.Join(dir, "actual-dir") | ||
if err := os.Mkdir(targetDir, 0755); err != nil { | ||
t.Fatalf("Mkdir() failed: %v", err) | ||
} | ||
|
||
// Create a symlink pointing to the target directory | ||
symlinkPath := filepath.Join(dir, "symlink-to-dir") | ||
if err := os.Symlink("actual-dir", symlinkPath); err != nil { | ||
t.Fatalf("Symlink() failed: %v", err) | ||
} | ||
|
||
// Mount the temp directory and set working directory to the symlink | ||
opts := dockerutil.RunOpts{ | ||
Image: "basic/alpine", | ||
WorkDir: "/test/symlink-to-dir", | ||
Mounts: []mount.Mount{ | ||
{ | ||
Type: mount.TypeBind, | ||
Source: dir, | ||
Target: "/test", | ||
}, | ||
}, | ||
} | ||
|
||
// Test that the container can start with symlinked working directory | ||
// and that pwd returns the symlinked path | ||
got, err := d.Run(ctx, opts, "sh", "-c", "pwd") | ||
if err != nil { | ||
t.Fatalf("docker run failed: %v", err) | ||
} | ||
|
||
want := "/test/symlink-to-dir\n" | ||
if got != want { | ||
t.Errorf("working directory mismatch, want: %q, got: %q", want, got) | ||
} | ||
|
||
// Additional test: verify we can actually use the working directory | ||
// by creating a file in it | ||
_, err = d.Run(ctx, opts, "sh", "-c", "echo 'test content' > testfile && cat testfile") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can combine this command with the previous one to avoid executing the same container twice. |
||
if err != nil { | ||
t.Fatalf("docker run failed: %v", err) | ||
} | ||
|
||
// Verify the file was created in the actual target directory | ||
createdFile := filepath.Join(targetDir, "testfile") | ||
if _, err := os.Stat(createdFile); err != nil { | ||
t.Errorf("file was not created in target directory: %v", err) | ||
} | ||
} | ||
|
||
func TestCharDevice(t *testing.T) { | ||
if testutil.IsRunningWithOverlay() { | ||
t.Skip("files are not available outside the sandbox with overlay.") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In gVisor,
pwd
returnstargetDir
, which differs from Linux's behavior. However, this doesn't like a critical issue. You can file a separate issue for that.