Skip to content

Commit bb1f087

Browse files
authored
Merge pull request #541 from q384566678/fix-TestJSONSchema
validate_test: perfect TestJSONSchema
2 parents a6e1a3c + 612c315 commit bb1f087

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

validate/validate_test.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,144 @@ func TestJSONSchema(t *testing.T) {
104104
},
105105
error: "process: process is required",
106106
},
107+
{
108+
config: &rspec.Spec{
109+
Version: "1.0.0",
110+
Linux: &rspec.Linux{
111+
Namespaces: []rspec.LinuxNamespace{
112+
{
113+
Type: "pid",
114+
},
115+
},
116+
},
117+
},
118+
error: "",
119+
},
120+
{
121+
config: &rspec.Spec{
122+
Version: "1.0.0",
123+
Linux: &rspec.Linux{
124+
Namespaces: []rspec.LinuxNamespace{
125+
{
126+
Type: "test",
127+
},
128+
},
129+
},
130+
},
131+
error: "2 errors occurred:\n\n* linux.namespaces.0: Must validate at least one schema (anyOf)\n* linux.namespaces.0.type: linux.namespaces.0.type must be one of the following: \"mount\", \"pid\", \"network\", \"uts\", \"ipc\", \"user\", \"cgroup\"",
132+
},
133+
{
134+
config: &rspec.Spec{
135+
Version: "1.0.0",
136+
Linux: &rspec.Linux{
137+
Seccomp: &rspec.LinuxSeccomp{
138+
DefaultAction: "SCMP_ACT_ALLOW",
139+
Architectures: []rspec.Arch{
140+
"SCMP_ARCH_X86",
141+
"SCMP_ARCH_X32",
142+
},
143+
},
144+
},
145+
},
146+
error: "",
147+
},
148+
{
149+
config: &rspec.Spec{
150+
Version: "1.0.0",
151+
Linux: &rspec.Linux{
152+
Seccomp: &rspec.LinuxSeccomp{
153+
DefaultAction: "SCMP_ACT_ALLOW",
154+
Architectures: []rspec.Arch{
155+
"SCMP_ARCH_X86",
156+
"SCMP_ARCH",
157+
},
158+
},
159+
},
160+
},
161+
error: "linux.seccomp.architectures.1: linux.seccomp.architectures.1 must be one of the following: \"SCMP_ARCH_X86\", \"SCMP_ARCH_X86_64\", \"SCMP_ARCH_X32\", \"SCMP_ARCH_ARM\", \"SCMP_ARCH_AARCH64\", \"SCMP_ARCH_MIPS\", \"SCMP_ARCH_MIPS64\", \"SCMP_ARCH_MIPS64N32\", \"SCMP_ARCH_MIPSEL\", \"SCMP_ARCH_MIPSEL64\", \"SCMP_ARCH_MIPSEL64N32\", \"SCMP_ARCH_PPC\", \"SCMP_ARCH_PPC64\", \"SCMP_ARCH_PPC64LE\", \"SCMP_ARCH_S390\", \"SCMP_ARCH_S390X\", \"SCMP_ARCH_PARISC\", \"SCMP_ARCH_PARISC64\"",
162+
},
163+
{
164+
config: &rspec.Spec{
165+
Version: "1.0.0",
166+
Linux: &rspec.Linux{
167+
Seccomp: &rspec.LinuxSeccomp{
168+
DefaultAction: "SCMP_ACT_ALLOW",
169+
Syscalls: []rspec.LinuxSyscall{
170+
{
171+
Names: []string{"getcwd"},
172+
Action: "SCMP_ACT_KILL",
173+
},
174+
},
175+
},
176+
},
177+
},
178+
error: "",
179+
},
180+
{
181+
config: &rspec.Spec{
182+
Version: "1.0.0",
183+
Linux: &rspec.Linux{
184+
Seccomp: &rspec.LinuxSeccomp{
185+
DefaultAction: "SCMP_ACT_ALLOW",
186+
Syscalls: []rspec.LinuxSyscall{
187+
{
188+
Names: []string{"getcwd"},
189+
Action: "SCMP_ACT",
190+
},
191+
},
192+
},
193+
},
194+
},
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\"",
196+
},
197+
{
198+
config: &rspec.Spec{
199+
Version: "1.0.0",
200+
Linux: &rspec.Linux{
201+
Seccomp: &rspec.LinuxSeccomp{
202+
DefaultAction: "SCMP_ACT_ALLOW",
203+
Syscalls: []rspec.LinuxSyscall{
204+
{
205+
Names: []string{"getcwd"},
206+
Action: "SCMP_ACT_KILL",
207+
Args: []rspec.LinuxSeccompArg{
208+
{
209+
Index: 0,
210+
Value: 2080,
211+
Op: "SCMP_CMP_NE",
212+
},
213+
},
214+
},
215+
},
216+
},
217+
},
218+
},
219+
error: "",
220+
},
221+
{
222+
config: &rspec.Spec{
223+
Version: "1.0.0",
224+
Linux: &rspec.Linux{
225+
Seccomp: &rspec.LinuxSeccomp{
226+
DefaultAction: "SCMP_ACT_ALLOW",
227+
Syscalls: []rspec.LinuxSyscall{
228+
{
229+
Names: []string{"getcwd"},
230+
Action: "SCMP_ACT_KILL",
231+
Args: []rspec.LinuxSeccompArg{
232+
{
233+
Index: 0,
234+
Value: 2080,
235+
Op: "SCMP_CMP",
236+
},
237+
},
238+
},
239+
},
240+
},
241+
},
242+
},
243+
error: "linux.seccomp.syscalls.0.args.0.op: linux.seccomp.syscalls.0.args.0.op must be one of the following: \"SCMP_CMP_NE\", \"SCMP_CMP_LT\", \"SCMP_CMP_LE\", \"SCMP_CMP_EQ\", \"SCMP_CMP_GE\", \"SCMP_CMP_GT\", \"SCMP_CMP_MASKED_EQ\"",
244+
},
107245
} {
108246
t.Run(tt.error, func(t *testing.T) {
109247
v := &Validator{spec: tt.config}

0 commit comments

Comments
 (0)