summaryrefslogtreecommitdiffhomepage
path: root/runsc/fsgofer/fsgofer_test.go
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2018-10-23 00:19:11 -0700
committerShentubot <shentubot@google.com>2018-10-23 00:20:15 -0700
commit75cd70ecc9abfd5daaefea04da5070a0e0d620dd (patch)
treeff17ca619006a3bea596df09a58abbbf21c6528d /runsc/fsgofer/fsgofer_test.go
parentc2c0f9cb7e8320de06ef280c6184bb6aeda71627 (diff)
Track paths and provide a rename hook.
This change also adds extensive testing to the p9 package via mocks. The sanity checks and type checks are moved from the gofer into the core package, where they can be more easily validated. PiperOrigin-RevId: 218296768 Change-Id: I4fc3c326e7bf1e0e140a454cbacbcc6fd617ab55
Diffstat (limited to 'runsc/fsgofer/fsgofer_test.go')
-rw-r--r--runsc/fsgofer/fsgofer_test.go78
1 files changed, 12 insertions, 66 deletions
diff --git a/runsc/fsgofer/fsgofer_test.go b/runsc/fsgofer/fsgofer_test.go
index 48860f952..34033245b 100644
--- a/runsc/fsgofer/fsgofer_test.go
+++ b/runsc/fsgofer/fsgofer_test.go
@@ -415,22 +415,22 @@ func TestLink(t *testing.T) {
func TestROMountChecks(t *testing.T) {
runCustom(t, allTypes, roConfs, func(t *testing.T, s state) {
- if _, _, _, _, err := s.file.Create("..", p9.ReadWrite, 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())); err != syscall.EBADF {
+ if _, _, _, _, err := s.file.Create("some_file", p9.ReadWrite, 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())); err != syscall.EBADF {
t.Errorf("%v: Create() should have failed, got: %v, expected: syscall.EBADF", s, err)
}
- if _, err := s.file.Mkdir("..", 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())); err != syscall.EBADF {
+ if _, err := s.file.Mkdir("some_dir", 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())); err != syscall.EBADF {
t.Errorf("%v: MkDir() should have failed, got: %v, expected: syscall.EBADF", s, err)
}
- if err := s.file.Rename(s.file, ".."); err != syscall.EBADF {
+ if err := s.file.RenameAt("some_file", s.file, "other_file"); err != syscall.EBADF {
t.Errorf("%v: Rename() should have failed, got: %v, expected: syscall.EBADF", s, err)
}
- if _, err := s.file.Symlink("some_place", "..", p9.UID(os.Getuid()), p9.GID(os.Getgid())); err != syscall.EBADF {
+ if _, err := s.file.Symlink("some_place", "some_symlink", p9.UID(os.Getuid()), p9.GID(os.Getgid())); err != syscall.EBADF {
t.Errorf("%v: Symlink() should have failed, got: %v, expected: syscall.EBADF", s, err)
}
- if err := s.file.UnlinkAt("..", 0); err != syscall.EBADF {
+ if err := s.file.UnlinkAt("some_file", 0); err != syscall.EBADF {
t.Errorf("%v: UnlinkAt() should have failed, got: %v, expected: syscall.EBADF", s, err)
}
- if err := s.file.Link(s.file, ".."); err != syscall.EBADF {
+ if err := s.file.Link(s.file, "some_link"); err != syscall.EBADF {
t.Errorf("%v: Link() should have failed, got: %v, expected: syscall.EBADF", s, err)
}
@@ -445,12 +445,12 @@ func TestROMountChecks(t *testing.T) {
func TestROMountPanics(t *testing.T) {
conf := Config{ROMount: true, PanicOnWrite: true}
runCustom(t, allTypes, []Config{conf}, func(t *testing.T, s state) {
- assertPanic(t, func() { s.file.Create("..", p9.ReadWrite, 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())) })
- assertPanic(t, func() { s.file.Mkdir("..", 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())) })
- assertPanic(t, func() { s.file.Rename(s.file, "..") })
- assertPanic(t, func() { s.file.Symlink("some_place", "..", p9.UID(os.Getuid()), p9.GID(os.Getgid())) })
- assertPanic(t, func() { s.file.UnlinkAt("..", 0) })
- assertPanic(t, func() { s.file.Link(s.file, "..") })
+ assertPanic(t, func() { s.file.Create("some_file", p9.ReadWrite, 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())) })
+ assertPanic(t, func() { s.file.Mkdir("some_dir", 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())) })
+ assertPanic(t, func() { s.file.RenameAt("some_file", s.file, "other_file") })
+ assertPanic(t, func() { s.file.Symlink("some_place", "some_symlink", p9.UID(os.Getuid()), p9.GID(os.Getgid())) })
+ assertPanic(t, func() { s.file.UnlinkAt("some_file", 0) })
+ assertPanic(t, func() { s.file.Link(s.file, "some_link") })
valid := p9.SetAttrMask{Size: true}
attr := p9.SetAttr{Size: 0}
@@ -458,60 +458,6 @@ func TestROMountPanics(t *testing.T) {
})
}
-func TestInvalidName(t *testing.T) {
- runCustom(t, []fileType{regular}, rwConfs, func(t *testing.T, s state) {
- if _, _, _, _, err := s.file.Create("..", p9.ReadWrite, 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())); err != syscall.EINVAL {
- t.Errorf("%v: Create() should have failed, got: %v, expected: syscall.EINVAL", s, err)
- }
- if _, _, err := s.file.Walk([]string{".."}); err != syscall.EINVAL {
- t.Errorf("%v: Walk() should have failed, got: %v, expected: syscall.EINVAL", s, err)
- }
- if _, err := s.file.Mkdir("..", 0777, p9.UID(os.Getuid()), p9.GID(os.Getgid())); err != syscall.EINVAL {
- t.Errorf("%v: MkDir() should have failed, got: %v, expected: syscall.EINVAL", s, err)
- }
- if err := s.file.Rename(s.file, ".."); err != syscall.EINVAL {
- t.Errorf("%v: Rename() should have failed, got: %v, expected: syscall.EINVAL", s, err)
- }
- if _, err := s.file.Symlink("some_place", "..", p9.UID(os.Getuid()), p9.GID(os.Getgid())); err != syscall.EINVAL {
- t.Errorf("%v: Symlink() should have failed, got: %v, expected: syscall.EINVAL", s, err)
- }
- if err := s.file.UnlinkAt("..", 0); err != syscall.EINVAL {
- t.Errorf("%v: UnlinkAt() should have failed, got: %v, expected: syscall.EINVAL", s, err)
- }
- if err := s.file.Link(s.file, ".."); err != syscall.EINVAL {
- t.Errorf("%v: Link() should have failed, got: %v, expected: syscall.EINVAL", s, err)
- }
- })
-}
-
-func TestIsNameValid(t *testing.T) {
- valid := []string{
- "name",
- "123",
- "!@#$%^&*()",
- ".name",
- "..name",
- "...",
- }
- for _, s := range valid {
- if got := isNameValid(s); !got {
- t.Errorf("isNameValid(%s) failed, got: %v, expected: true", s, got)
- }
- }
- invalid := []string{
- ".",
- "..",
- "name/name",
- "/name",
- "name/",
- }
- for _, s := range invalid {
- if got := isNameValid(s); got {
- t.Errorf("isNameValid(%s) failed, got: %v, expected: false", s, got)
- }
- }
-}
-
func TestWalkNotFound(t *testing.T) {
runCustom(t, []fileType{directory}, allConfs, func(t *testing.T, s state) {
if _, _, err := s.file.Walk([]string{"nobody-here"}); err != syscall.ENOENT {