diff options
Diffstat (limited to 'runsc/fsgofer/fsgofer_test.go')
-rw-r--r-- | runsc/fsgofer/fsgofer_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/runsc/fsgofer/fsgofer_test.go b/runsc/fsgofer/fsgofer_test.go index 8d038eaf6..fcece4e83 100644 --- a/runsc/fsgofer/fsgofer_test.go +++ b/runsc/fsgofer/fsgofer_test.go @@ -34,6 +34,15 @@ func init() { allConfs = append(allConfs, roConfs...) } +func assertPanic(t *testing.T, f func()) { + defer func() { + if r := recover(); r == nil { + t.Errorf("function did not panic") + } + }() + f() +} + var ( allTypes = []fileType{regular, directory, symlink} @@ -434,6 +443,22 @@ 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, "..") }) + + valid := p9.SetAttrMask{Size: true} + attr := p9.SetAttr{Size: 0} + assertPanic(t, func() { s.file.SetAttr(valid, attr) }) + }) +} + 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 { |