Skip to content

Commit 5e395e8

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 <wking@tremily.us>
1 parent 1b40f71 commit 5e395e8

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-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: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,28 @@ 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+
f, err := os.OpenFile(testFile, os.O_WRONLY|os.O_CREAT, 0777)
23+
if err != nil {
24+
return err
25+
}
26+
defer f.Close()
27+
28+
// runtimetest cannot check the readability of empty files, so
29+
// write something.
30+
_, err = f.Write([]byte("secrets"))
31+
if err != nil {
32+
return err
33+
}
1634
})
1735
if err != nil {
1836
util.Fatal(err)

validation/linux_readonly_paths.go

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

1010
func main() {
1111
g := util.GetDefaultGenerator()
12-
g.AddLinuxReadonlyPaths("readonlytest")
12+
g.AddLinuxReadonlyPaths("/readonly-dir")
13+
g.AddLinuxReadonlyPaths("/readonly-file")
1314
err := util.RuntimeInsideValidate(g, func(path string) error {
14-
pathName := filepath.Join(path, "readonlytest")
15-
return os.MkdirAll(pathName, 0700)
15+
testDir := filepath.Join(path, "readonly-dir")
16+
err := os.MkdirAll(testDir, 0777)
17+
if err != nil {
18+
return err
19+
}
20+
21+
testFile := filepath.Join(path, "readonly-file")
22+
f, err := os.OpenFile(testFile, os.O_WRONLY|os.O_CREAT, 0777)
23+
if err != nil {
24+
return err
25+
}
26+
defer f.Close()
27+
28+
// runtimetest cannot check the readability of empty files, so
29+
// write something.
30+
_, err = f.Write([]byte("secrets"))
31+
if err != nil {
32+
return err
33+
}
1634
})
1735
if err != nil {
1836
util.Fatal(err)

0 commit comments

Comments
 (0)