Skip to content

Commit 5dd461f

Browse files
author
Dongsu Park
committed
validation: check for a read-only relative path
Test inside container should return error if a relative path is given for read-only paths. Signed-off-by: Dongsu Park <dongsu@kinvolk.io>
1 parent 91f2983 commit 5dd461f

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

validation/linux_readonly_paths.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"io/ioutil"
56
"os"
67
"path/filepath"
@@ -61,9 +62,36 @@ func checkReadonlyPaths() error {
6162
return err
6263
}
6364

65+
func checkReadonlyRelPaths() error {
66+
g, err := util.GetDefaultGenerator()
67+
if err != nil {
68+
return err
69+
}
70+
71+
// Deliberately set a relative path to be read-only, and expect an error
72+
readonlyRelPath := "readonly-relpath"
73+
74+
g.AddLinuxReadonlyPaths(readonlyRelPath)
75+
err = util.RuntimeInsideValidate(g, func(path string) error {
76+
testFile := filepath.Join(path, readonlyRelPath)
77+
if _, err := os.Stat(testFile); err != nil && os.IsNotExist(err) {
78+
return err
79+
}
80+
81+
return nil
82+
})
83+
if err != nil {
84+
return nil
85+
}
86+
return fmt.Errorf("expected: err != nil, actual: err == nil")
87+
}
88+
6489
func main() {
6590
if err := checkReadonlyPaths(); err != nil {
6691
util.Fatal(err)
6792
}
6893

94+
if err := checkReadonlyRelPaths(); err != nil {
95+
util.Fatal(err)
96+
}
6997
}

0 commit comments

Comments
 (0)