@@ -223,3 +223,57 @@ func TestFifoHandler(t *testing.T) {
223223 })
224224 }
225225}
226+
227+ func TestPrepareBindMount (t * testing.T ) {
228+ // Because of chown(2).
229+ internal .RequiresRoot (t )
230+
231+ t .Run ("no mounts" , func (t * testing.T ) {
232+ j := & runcJailer {}
233+ err := j .prepareBindMounts ([]* proto.FirecrackerDriveMount {})
234+ require .NoError (t , err )
235+ })
236+
237+ dir , err := ioutil .TempDir ("" , t .Name ())
238+ require .NoError (t , err )
239+ defer os .RemoveAll (dir )
240+
241+ j := & runcJailer {Config : runcJailerConfig {
242+ OCIBundlePath : filepath .Join (dir , "bundle" ),
243+ UID : 1234 ,
244+ GID : 5678 ,
245+ }}
246+
247+ err = ioutil .WriteFile (dir + "/foobar" , []byte ("hello" ), 0700 )
248+ require .NoError (t , err )
249+
250+ testcases := []struct {
251+ name string
252+ hostPath string
253+ }{
254+ {
255+ name : "absolute path" ,
256+ hostPath : dir + "/foobar" ,
257+ },
258+ {
259+ name : "use dots to access the original directory" ,
260+ hostPath : "/../../../../../.." + dir + "/foobar" ,
261+ },
262+ }
263+ for _ , tc := range testcases {
264+ t .Run (tc .name , func (t * testing.T ) {
265+ err = j .prepareBindMounts ([]* proto.FirecrackerDriveMount {{
266+ HostPath : tc .hostPath ,
267+ FilesystemType : "ext4" ,
268+ VMPath : "/mnt" ,
269+ }})
270+ require .NoError (t , err )
271+ stat , err := os .Stat (dir )
272+ require .NoError (t , err )
273+
274+ s := stat .Sys ().(* syscall.Stat_t )
275+ assert .Equal (t , 0 , int (s .Uid ), "UID" )
276+ assert .Equal (t , 0 , int (s .Gid ), "GID" )
277+ })
278+ }
279+ }
0 commit comments