Skip to content

Commit f1ff2d0

Browse files
committed
validation: Use non-empty files in masked/readonly tests
Previously we were only looking at directories. But the spec does not say these are directory-only options, so test files too. Put some content in the files, because runtimetest currently has no way to check the readability of empty files. Signed-off-by: W. Trevor King <[email protected]>
1 parent 3015991 commit f1ff2d0

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

cmd/runtimetest/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ func testFileReadAccess(path string) (readable bool, err error) {
426426
if err == nil {
427427
return true, nil
428428
} else if err == io.EOF {
429+
// Our validation/ tests only use non-empty files for read-access
430+
// tests. So if we get an EOF on the first read, the runtime did
431+
// successfully block readability.
429432
return false, nil
430433
}
431434
return false, err

validation/linux_masked_paths.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@ import (
99

1010
func main() {
1111
g := util.GetDefaultGenerator()
12-
g.AddLinuxMaskedPaths("/masktest")
12+
g.AddLinuxMaskedPaths("/masked-dir")
13+
g.AddLinuxMaskedPaths("/masked-file")
1314
err := util.RuntimeInsideValidate(g, func(path string) error {
14-
pathName := filepath.Join(path, "masktest")
15-
return os.MkdirAll(pathName, 0700)
15+
testDir := filepath.Join(path, "masked-dir")
16+
err := os.MkdirAll(testDir, 0777)
17+
if err != nil {
18+
return err
19+
}
20+
21+
testFile := filepath.Join(path, "masked-file")
22+
23+
// runtimetest cannot check the readability of empty files, so
24+
// write something.
25+
err := ioutil.WriteFile(testFile, []byte("secrets"), 0777)
26+
if err != nil {
27+
return err
28+
}
1629
})
1730
if err != nil {
1831
util.Fatal(err)

validation/linux_readonly_paths.go

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

33
import (
4+
"io/ioutil"
45
"os"
56
"path/filepath"
67

@@ -9,10 +10,23 @@ import (
910

1011
func main() {
1112
g := util.GetDefaultGenerator()
12-
g.AddLinuxReadonlyPaths("readonlytest")
13+
g.AddLinuxReadonlyPaths("/readonly-dir")
14+
g.AddLinuxReadonlyPaths("/readonly-file")
1315
err := util.RuntimeInsideValidate(g, func(path string) error {
14-
pathName := filepath.Join(path, "readonlytest")
15-
return os.MkdirAll(pathName, 0700)
16+
testDir := filepath.Join(path, "readonly-dir")
17+
err := os.MkdirAll(testDir, 0777)
18+
if err != nil {
19+
return err
20+
}
21+
22+
testFile := filepath.Join(path, "readonly-file")
23+
24+
// runtimetest cannot check the readability of empty files, so
25+
// write something.
26+
err := ioutil.WriteFile(testFile, []byte("immutable"), 0777)
27+
if err != nil {
28+
return err
29+
}
1630
})
1731
if err != nil {
1832
util.Fatal(err)

0 commit comments

Comments
 (0)