aboutsummaryrefslogtreecommitdiff
path: root/internal/syscallcompat/emulate_test.go
diff options
context:
space:
mode:
authorSebastian Lackner2017-11-30 21:13:46 +0100
committerrfjakob2017-12-01 09:41:52 +0100
commitf30522a0c14218ad236831d1c229968ea46ec8aa (patch)
tree97e0008ca9d302b5ee5f65800b006da5fd169fb0 /internal/syscallcompat/emulate_test.go
parent9bcde0c09e96e17ed7092aa5fa5f6bfc89372a8d (diff)
syscallcompat: Fix syscall emulation for absolute paths
For absolute paths, the file descriptor should be ignored. In such a case there is also no need to hold the lock or change the working directory.
Diffstat (limited to 'internal/syscallcompat/emulate_test.go')
-rw-r--r--internal/syscallcompat/emulate_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/internal/syscallcompat/emulate_test.go b/internal/syscallcompat/emulate_test.go
index 35b2b40..0753a45 100644
--- a/internal/syscallcompat/emulate_test.go
+++ b/internal/syscallcompat/emulate_test.go
@@ -67,6 +67,15 @@ func TestEmulateOpenat(t *testing.T) {
if rawFd < 0 {
t.Fatalf("rawFd=%d", rawFd)
}
+ // Test with absolute path
+ rawFd, err = emulateOpenat(-1, tmpDir + "/testOpenAt", 0, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer syscall.Close(rawFd)
+ if rawFd < 0 {
+ t.Fatalf("rawFd=%d", rawFd)
+ }
}
func TestEmulateRenameat(t *testing.T) {
@@ -95,6 +104,15 @@ func TestEmulateRenameat(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ // Test with absolute path
+ err = emulateRenameat(-1, tmpDir + "/dir2/f2", -1, tmpDir + "/dir2/f1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, err = os.Stat(tmpDir + "/dir2/f1")
+ if err != nil {
+ t.Fatal(err)
+ }
}
func TestEmulateUnlinkat(t *testing.T) {
@@ -135,6 +153,19 @@ func TestEmulateUnlinkat(t *testing.T) {
if err == nil {
t.Fatalf("dir not deleted!")
}
+ // Test with absolute path
+ err = os.Mkdir(tmpDir + "/unlink1/d1", 0700)
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = emulateUnlinkat(-1, tmpDir + "/unlink1/d1", unix.AT_REMOVEDIR)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, err = os.Stat(tmpDir + "/unlink1/d1")
+ if err == nil {
+ t.Fatalf("dir not deleted!")
+ }
}
func TestEmulateMknodat(t *testing.T) {
@@ -146,6 +177,15 @@ func TestEmulateMknodat(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ // Test with absolute path
+ err = emulateMknodat(-1, tmpDir + "/fifo2", unix.S_IFIFO, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, err = os.Stat(tmpDir + "/fifo2")
+ if err != nil {
+ t.Fatal(err)
+ }
}
func TestEmulateFchmodat(t *testing.T) {
@@ -187,6 +227,18 @@ func TestEmulateFchmodat(t *testing.T) {
if st.Mode != 0100600 {
t.Fatalf("Wrong mode: have %o, want %o", st.Mode, 0100600)
}
+ // Test with absolute path
+ err = emulateFchmodat(-1, tmpDir + "/chmod", 0400, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = syscall.Lstat(tmpDir + "/chmod", &st)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if st.Mode != 0100400 {
+ t.Fatalf("Wrong mode: have %o, want %o", st.Mode, 0100400)
+ }
}
func TestEmulateFchownat(t *testing.T) {
@@ -206,6 +258,18 @@ func TestEmulateSymlinkat(t *testing.T) {
if st.Mode != 0120777 {
t.Fatalf("Wrong mode, have %o, want 0120777", st.Mode)
}
+ // Test with absolute path
+ err = emulateSymlinkat("/foo/bar/baz", -1, tmpDir + "/symlink2")
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = syscall.Lstat(tmpDir + "/symlink2", &st)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if st.Mode != 0120777 {
+ t.Fatalf("Wrong mode, have %o, want 0120777", st.Mode)
+ }
}
func TestEmulateMkdirat(t *testing.T) {
@@ -220,4 +284,16 @@ func TestEmulateMkdirat(t *testing.T) {
if !fi.IsDir() {
t.Fatalf("mkdirat did not create a directory")
}
+ // Test with absolute path
+ err = emulateMkdirat(-1, tmpDir + "/mkdirat2", 0100)
+ if err != nil {
+ t.Fatal(err)
+ }
+ fi, err = os.Stat(tmpDir + "/mkdirat2")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !fi.IsDir() {
+ t.Fatalf("mkdirat did not create a directory")
+ }
}