@@ -53,7 +53,7 @@ func prepareBundle() (string, error) {
5353func getDefaultGenerator () * generate.Generator {
5454 g := generate .New ()
5555 g .SetRootPath ("." )
56- g .SetProcessArgs ([]string {"/runtimetest" })
56+ g .SetProcessArgs ([]string {"/runtimetest" , "--path=/" })
5757 return & g
5858}
5959
@@ -118,6 +118,31 @@ func TestValidateRootFSReadonly(t *testing.T) {
118118 assert .Nil (t , runtimeInsideValidate (g , nil ))
119119}
120120
121+ // Test Process
122+ func TestValidateProcess (t * testing.T ) {
123+ g := getDefaultGenerator ()
124+ g .SetProcessCwd ("/test" )
125+ g .AddProcessEnv ("testa" , "valuea" )
126+ g .AddProcessEnv ("testb" , "123" )
127+
128+ assert .Nil (t , runtimeInsideValidate (g , func (path string ) error {
129+ pathName := filepath .Join (path , "test" )
130+ return os .MkdirAll (pathName , 0700 )
131+ }))
132+ }
133+
134+ // Test whether Capabilites can be applied or not
135+ func TestValidateCapabilities (t * testing.T ) {
136+ if "linux" != runtime .GOOS {
137+ t .Skip ("skip linux-specific capabilities test" )
138+ }
139+
140+ g := getDefaultGenerator ()
141+ g .SetupPrivileged (true )
142+
143+ assert .Nil (t , runtimeInsideValidate (g , nil ))
144+ }
145+
121146// Test whether hostname can be applied or not
122147func TestValidateHostname (t * testing.T ) {
123148 g := getDefaultGenerator ()
@@ -150,6 +175,89 @@ func TestValidateRootfsPropagationUnbindable(t *testing.T) {
150175 assert .Nil (t , runtimeInsideValidate (g , nil ))
151176}
152177
178+ func TestValidateLinuxDevices (t * testing.T ) {
179+ g := getDefaultGenerator ()
180+
181+ // add char device
182+ cdev := rspecs.LinuxDevice {}
183+ cdev .Path = "/dev/test1"
184+ cdev .Type = "c"
185+ cdev .Major = 10
186+ cdev .Minor = 666
187+ cmode := os .FileMode (int32 (432 ))
188+ cdev .FileMode = & cmode
189+ cuid := uint32 (0 )
190+ cdev .UID = & cuid
191+ cgid := uint32 (0 )
192+ cdev .GID = & cgid
193+ g .AddDevice (cdev )
194+ // add block device
195+ bdev := rspecs.LinuxDevice {}
196+ bdev .Path = "/dev/test2"
197+ bdev .Type = "b"
198+ bdev .Major = 8
199+ bdev .Minor = 666
200+ bmode := os .FileMode (int32 (432 ))
201+ bdev .FileMode = & bmode
202+ uid := uint32 (0 )
203+ bdev .UID = & uid
204+ gid := uint32 (0 )
205+ bdev .GID = & gid
206+ g .AddDevice (bdev )
207+ // add fifo device
208+ pdev := rspecs.LinuxDevice {}
209+ pdev .Path = "/dev/test3"
210+ pdev .Type = "p"
211+ pdev .Major = 8
212+ pdev .Minor = 666
213+ pmode := os .FileMode (int32 (432 ))
214+ pdev .FileMode = & pmode
215+ g .AddDevice (pdev )
216+
217+ assert .Nil (t , runtimeInsideValidate (g , nil ))
218+ }
219+
220+ func TestValidateMaskedPaths (t * testing.T ) {
221+ g := getDefaultGenerator ()
222+ g .AddLinuxMaskedPaths ("/masktest" )
223+
224+ assert .Nil (t , runtimeInsideValidate (g , func (path string ) error {
225+ pathName := filepath .Join (path , "masktest" )
226+ return os .MkdirAll (pathName , 0700 )
227+ }))
228+ }
229+
230+ func TestValidateROPaths (t * testing.T ) {
231+ g := getDefaultGenerator ()
232+ g .AddLinuxReadonlyPaths ("readonlytest" )
233+
234+ assert .Nil (t , runtimeInsideValidate (g , func (path string ) error {
235+ pathName := filepath .Join (path , "readonlytest" )
236+ return os .MkdirAll (pathName , 0700 )
237+ }))
238+ }
239+
240+ func TestValidateOOMScoreAdj (t * testing.T ) {
241+ g := getDefaultGenerator ()
242+ g .SetProcessOOMScoreAdj (500 )
243+
244+ assert .Nil (t , runtimeInsideValidate (g , nil ))
245+ }
246+
247+ func TestValidateUIDMappings (t * testing.T ) {
248+ g := getDefaultGenerator ()
249+ g .AddLinuxUIDMapping (uint32 (1000 ), uint32 (0 ), uint32 (3200 ))
250+
251+ assert .Nil (t , runtimeInsideValidate (g , nil ))
252+ }
253+
254+ func TestValidateGIDMappings (t * testing.T ) {
255+ g := getDefaultGenerator ()
256+ g .AddLinuxGIDMapping (uint32 (1000 ), uint32 (0 ), uint32 (3200 ))
257+
258+ assert .Nil (t , runtimeInsideValidate (g , nil ))
259+ }
260+
153261// Test whether mounts are correctly mounted
154262func TestValidateMounts (t * testing.T ) {
155263 // TODO mounts generation options have not been implemented
0 commit comments