Skip to content

Commit 67884fc

Browse files
committed
validate: prepare for new xeipuuv/gojsonschema
New(er) xeipuuv/gojsonschema package is trying to fetch id fields, which in the spec were looking like this: "id": "https://opencontainers.org/schema/bundle/linux" Obviously, this results in HTTP 404s, and multiple test failures. This was fixed by opencontainers/runtime-spec#945 which ended up in runtime-spec v1.0.2. This essentially means with newer xeipuuv/gojsonschema we are no longer able to validate against runtime-spec < 1.0.2. To adopt for a new xeipuuv/gojsonschema, do the following: 1. Add the version check, add a test case for it. 2. Remove some test cases: - "process is required" as it needed v1.0.0-rc5 version of spec. - "args is required" as args are no longer required since commit opencontainers/runtime-spec@deb4d954eafc4fc. 3. Bump the spec version in all test cases. 4. Fix "invalid seccomp action" error as it now also has SCMP_ACT_LOG. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 17ac4c5 commit 67884fc

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

validate/validate.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ func JSONSchemaURL(version string) (url string, err error) {
131131
if err != nil {
132132
return "", specerror.NewError(specerror.SpecVersionInSemVer, err, rspec.Version)
133133
}
134-
configRenamedToConfigSchemaVersion, _ := semver.Parse("1.0.0-rc2") // config.json became config-schema.json in 1.0.0-rc2
135-
if ver.Compare(configRenamedToConfigSchemaVersion) == -1 {
136-
return "", fmt.Errorf("unsupported configuration version (older than %s)", configRenamedToConfigSchemaVersion)
134+
if ver.LT(semver.Version{Major: 1, Minor: 0, Patch: 2}) {
135+
return "", errors.New("unsupported configuration version (older than 1.0.2)")
137136
}
138137
return fmt.Sprintf(configSchemaTemplate, version), nil
139138
}

validate/validate_test.go

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,32 @@ func TestJSONSchema(t *testing.T) {
4747
},
4848
{
4949
config: &rspec.Spec{
50-
Version: "1.0.1-rc1",
50+
Version: "1.0.99-rc1", // non-existent
5151
},
5252
error: "Could not read schema from HTTP, response status is 404 Not Found",
5353
},
5454
{
5555
config: &rspec.Spec{
56-
Version: "1.0.0",
56+
Version: "1.0.0", // too old
5757
},
58-
error: "",
58+
error: "1 error occurred:\n\t* unsupported configuration version (older than 1.0.2)\n\n",
5959
},
6060
{
6161
config: &rspec.Spec{
62-
Version: "1.0.0",
63-
Process: &rspec.Process{},
62+
Version: "1.0.2",
6463
},
65-
error: "1 error occurred:\n\t* args: args is required\n\n",
64+
error: "",
6665
},
6766
{
6867
config: &rspec.Spec{
69-
Version: "1.0.0",
68+
Version: "1.0.2",
7069
Linux: &rspec.Linux{},
7170
},
7271
error: "",
7372
},
7473
{
7574
config: &rspec.Spec{
76-
Version: "1.0.0",
75+
Version: "1.0.2",
7776
Linux: &rspec.Linux{
7877
RootfsPropagation: "",
7978
},
@@ -82,7 +81,7 @@ func TestJSONSchema(t *testing.T) {
8281
},
8382
{
8483
config: &rspec.Spec{
85-
Version: "1.0.0",
84+
Version: "1.0.2",
8685
Linux: &rspec.Linux{
8786
RootfsPropagation: "shared",
8887
},
@@ -91,7 +90,7 @@ func TestJSONSchema(t *testing.T) {
9190
},
9291
{
9392
config: &rspec.Spec{
94-
Version: "1.0.0",
93+
Version: "1.0.2",
9594
Linux: &rspec.Linux{
9695
RootfsPropagation: "rshared",
9796
},
@@ -100,13 +99,7 @@ func TestJSONSchema(t *testing.T) {
10099
},
101100
{
102101
config: &rspec.Spec{
103-
Version: "1.0.0-rc5",
104-
},
105-
error: "process: process is required",
106-
},
107-
{
108-
config: &rspec.Spec{
109-
Version: "1.0.0",
102+
Version: "1.0.2",
110103
Linux: &rspec.Linux{
111104
Namespaces: []rspec.LinuxNamespace{
112105
{
@@ -119,7 +112,7 @@ func TestJSONSchema(t *testing.T) {
119112
},
120113
{
121114
config: &rspec.Spec{
122-
Version: "1.0.0",
115+
Version: "1.0.2",
123116
Linux: &rspec.Linux{
124117
Namespaces: []rspec.LinuxNamespace{
125118
{
@@ -132,7 +125,7 @@ func TestJSONSchema(t *testing.T) {
132125
},
133126
{
134127
config: &rspec.Spec{
135-
Version: "1.0.0",
128+
Version: "1.0.2",
136129
Linux: &rspec.Linux{
137130
Seccomp: &rspec.LinuxSeccomp{
138131
DefaultAction: "SCMP_ACT_ALLOW",
@@ -147,7 +140,7 @@ func TestJSONSchema(t *testing.T) {
147140
},
148141
{
149142
config: &rspec.Spec{
150-
Version: "1.0.0",
143+
Version: "1.0.2",
151144
Linux: &rspec.Linux{
152145
Seccomp: &rspec.LinuxSeccomp{
153146
DefaultAction: "SCMP_ACT_ALLOW",
@@ -162,7 +155,7 @@ func TestJSONSchema(t *testing.T) {
162155
},
163156
{
164157
config: &rspec.Spec{
165-
Version: "1.0.0",
158+
Version: "1.0.2",
166159
Linux: &rspec.Linux{
167160
Seccomp: &rspec.LinuxSeccomp{
168161
DefaultAction: "SCMP_ACT_ALLOW",
@@ -179,7 +172,7 @@ func TestJSONSchema(t *testing.T) {
179172
},
180173
{
181174
config: &rspec.Spec{
182-
Version: "1.0.0",
175+
Version: "1.0.2",
183176
Linux: &rspec.Linux{
184177
Seccomp: &rspec.LinuxSeccomp{
185178
DefaultAction: "SCMP_ACT_ALLOW",
@@ -192,11 +185,11 @@ func TestJSONSchema(t *testing.T) {
192185
},
193186
},
194187
},
195-
error: "linux.seccomp.syscalls.0.action: linux.seccomp.syscalls.0.action must be one of the following: \"SCMP_ACT_KILL\", \"SCMP_ACT_TRAP\", \"SCMP_ACT_ERRNO\", \"SCMP_ACT_TRACE\", \"SCMP_ACT_ALLOW\"",
188+
error: "linux.seccomp.syscalls.0.action: linux.seccomp.syscalls.0.action must be one of the following: \"SCMP_ACT_KILL\", \"SCMP_ACT_TRAP\", \"SCMP_ACT_ERRNO\", \"SCMP_ACT_TRACE\", \"SCMP_ACT_ALLOW\", \"SCMP_ACT_LOG\"",
196189
},
197190
{
198191
config: &rspec.Spec{
199-
Version: "1.0.0",
192+
Version: "1.0.2",
200193
Linux: &rspec.Linux{
201194
Seccomp: &rspec.LinuxSeccomp{
202195
DefaultAction: "SCMP_ACT_ALLOW",
@@ -220,7 +213,7 @@ func TestJSONSchema(t *testing.T) {
220213
},
221214
{
222215
config: &rspec.Spec{
223-
Version: "1.0.0",
216+
Version: "1.0.2",
224217
Linux: &rspec.Linux{
225218
Seccomp: &rspec.LinuxSeccomp{
226219
DefaultAction: "SCMP_ACT_ALLOW",
@@ -322,7 +315,7 @@ func TestCheckSemVer(t *testing.T) {
322315
expected specerror.Code
323316
}{
324317
{rspec.Version, specerror.NonError},
325-
//FIXME: validate currently only handles rpsec.Version
318+
// FIXME: validate currently only handles rpsec.Version
326319
{"0.0.1", specerror.NonRFCError},
327320
{"invalid", specerror.SpecVersionInSemVer},
328321
}

0 commit comments

Comments
 (0)