Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
validation: check for invalid symlink inside container
Browse files Browse the repository at this point in the history
Deliberately create an invalid read-only symlink that points out of the
container, to see if the test fails inside the container.

Signed-off-by: Dongsu Park <[email protected]>
  • Loading branch information
Dongsu Park committed Jun 12, 2018
1 parent 5dd461f commit e60cd06
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions validation/linux_readonly_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,40 @@ func checkReadonlyRelPaths() error {
return fmt.Errorf("expected: err != nil, actual: err == nil")
}

func checkReadonlySymlinks() error {
g, err := util.GetDefaultGenerator()
if err != nil {
return err
}

// Deliberately create a read-only symlink that points an invalid file,
// and expect an error.
readonlySymlink := "/readonly-symlink"

g.AddLinuxReadonlyPaths(readonlySymlink)
err = util.RuntimeInsideValidate(g, func(path string) error {
testFile := filepath.Join(path, readonlySymlink)
// ln -s .. /readonly-symlink ; readlink -f /readonly-symlink; ls -L /readonly-symlink
if err := os.Symlink("../readonly-symlink", testFile); err != nil {
return err
}
rPath, errR := os.Readlink(testFile)
if errR != nil {
return errR
}
_, errS := os.Stat(rPath)
if errS != nil && os.IsNotExist(errS) {
return errS
}

return nil
})
if err != nil {
return nil
}
return fmt.Errorf("expected: err != nil, actual: err == nil")
}

func main() {
if err := checkReadonlyPaths(); err != nil {
util.Fatal(err)
Expand All @@ -94,4 +128,9 @@ func main() {
if err := checkReadonlyRelPaths(); err != nil {
util.Fatal(err)
}

if err := checkReadonlySymlinks(); err != nil {
util.Fatal(err)
}

}

0 comments on commit e60cd06

Please sign in to comment.