Skip to content

Commit fc0b7d8

Browse files
committed
validation: add a generate smoke-test
To avoid cases where our own validation code would consider our defaults unsafe (which has happened in the past severall times), add a smoke-test to ensure that this won't happen. Our defaults should not be intentionally invalid, as that confuses downstreams like umoci which use runtime-tools for the default as well as for validation of the generated configuration. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 5d22fd0 commit fc0b7d8

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

validation/generate_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package validation
2+
3+
import (
4+
"io/ioutil"
5+
"os"
6+
"path/filepath"
7+
"runtime"
8+
"testing"
9+
10+
"github.com/opencontainers/runtime-tools/generate"
11+
"github.com/opencontainers/runtime-tools/validate"
12+
)
13+
14+
// Smoke test to ensure that _at the very least_ our default configuration
15+
// passes the validation tests. If this test fails, something is _very_ wrong
16+
// and needs to be fixed immediately (as it will break downstreams that depend
17+
// on us for a "sane default" and do compliance testing -- such as umoci).
18+
func TestGenerateValid(t *testing.T) {
19+
bundle, err := ioutil.TempDir("", "TestGenerateValid_bundle")
20+
if err != nil {
21+
t.Fatal(err)
22+
}
23+
defer os.RemoveAll(bundle)
24+
25+
// Create our toy bundle.
26+
rootfsPath := filepath.Join(bundle, "rootfs")
27+
if err := os.Mkdir(rootfsPath, 0755); err != nil {
28+
t.Fatal(err)
29+
}
30+
configPath := filepath.Join(bundle, "config.json")
31+
g := generate.New()
32+
if err := (&g).SaveToFile(configPath, generate.ExportOptions{Seccomp: false}); err != nil {
33+
t.Fatal(err)
34+
}
35+
36+
// Validate the bundle.
37+
v, err := validate.NewValidatorFromPath(bundle, true, runtime.GOOS)
38+
if err != nil {
39+
t.Errorf("unexpected NewValidatorFromPath error: %+v", err)
40+
}
41+
if err := v.CheckAll(); err != nil {
42+
t.Errorf("unexpected error(s) validating default: %+v", err)
43+
}
44+
}

0 commit comments

Comments
 (0)