@@ -504,17 +504,82 @@ func TestValidateIDMapMounts(t *testing.T) {
504504 config * configs.Config
505505 }{
506506 {
507- name : "idmap mount without bind opt specified " ,
507+ name : "idmap non- bind mount " ,
508508 isErr : true ,
509509 config : & configs.Config {
510510 UIDMappings : mapping ,
511511 GIDMappings : mapping ,
512+ Mounts : []* configs.Mount {
513+ {
514+ Source : "/dev/sda1" ,
515+ Destination : "/abs/path/" ,
516+ Device : "ext4" ,
517+ IDMapping : & configs.MountIDMapping {
518+ UIDMappings : mapping ,
519+ GIDMappings : mapping ,
520+ },
521+ },
522+ },
523+ },
524+ },
525+ {
526+ name : "idmap option non-bind mount" ,
527+ isErr : true ,
528+ config : & configs.Config {
529+ Mounts : []* configs.Mount {
530+ {
531+ Source : "/dev/sda1" ,
532+ Destination : "/abs/path/" ,
533+ Device : "ext4" ,
534+ IDMapping : & configs.MountIDMapping {},
535+ },
536+ },
537+ },
538+ },
539+ {
540+ name : "ridmap option non-bind mount" ,
541+ isErr : true ,
542+ config : & configs.Config {
543+ Mounts : []* configs.Mount {
544+ {
545+ Source : "/dev/sda1" ,
546+ Destination : "/abs/path/" ,
547+ Device : "ext4" ,
548+ IDMapping : & configs.MountIDMapping {
549+ Recursive : true ,
550+ },
551+ },
552+ },
553+ },
554+ },
555+ {
556+ name : "idmap mount no uid mapping" ,
557+ isErr : true ,
558+ config : & configs.Config {
559+ Mounts : []* configs.Mount {
560+ {
561+ Source : "/abs/path/" ,
562+ Destination : "/abs/path/" ,
563+ Flags : unix .MS_BIND ,
564+ IDMapping : & configs.MountIDMapping {
565+ GIDMappings : mapping ,
566+ },
567+ },
568+ },
569+ },
570+ },
571+ {
572+ name : "idmap mount no gid mapping" ,
573+ isErr : true ,
574+ config : & configs.Config {
512575 Mounts : []* configs.Mount {
513576 {
514577 Source : "/abs/path/" ,
515578 Destination : "/abs/path/" ,
516- UIDMappings : mapping ,
517- GIDMappings : mapping ,
579+ Flags : unix .MS_BIND ,
580+ IDMapping : & configs.MountIDMapping {
581+ UIDMappings : mapping ,
582+ },
518583 },
519584 },
520585 },
@@ -531,8 +596,10 @@ func TestValidateIDMapMounts(t *testing.T) {
531596 Source : "/abs/path/" ,
532597 Destination : "/abs/path/" ,
533598 Flags : unix .MS_BIND ,
534- UIDMappings : mapping ,
535- GIDMappings : mapping ,
599+ IDMapping : & configs.MountIDMapping {
600+ UIDMappings : mapping ,
601+ GIDMappings : mapping ,
602+ },
536603 },
537604 },
538605 },
@@ -547,8 +614,10 @@ func TestValidateIDMapMounts(t *testing.T) {
547614 Source : "./rel/path/" ,
548615 Destination : "/abs/path/" ,
549616 Flags : unix .MS_BIND ,
550- UIDMappings : mapping ,
551- GIDMappings : mapping ,
617+ IDMapping : & configs.MountIDMapping {
618+ UIDMappings : mapping ,
619+ GIDMappings : mapping ,
620+ },
552621 },
553622 },
554623 },
@@ -563,8 +632,10 @@ func TestValidateIDMapMounts(t *testing.T) {
563632 Source : "/abs/path/" ,
564633 Destination : "./rel/path/" ,
565634 Flags : unix .MS_BIND ,
566- UIDMappings : mapping ,
567- GIDMappings : mapping ,
635+ IDMapping : & configs.MountIDMapping {
636+ UIDMappings : mapping ,
637+ GIDMappings : mapping ,
638+ },
568639 },
569640 },
570641 },
@@ -579,8 +650,10 @@ func TestValidateIDMapMounts(t *testing.T) {
579650 Source : "/another-abs/path/" ,
580651 Destination : "/abs/path/" ,
581652 Flags : unix .MS_BIND ,
582- UIDMappings : mapping ,
583- GIDMappings : mapping ,
653+ IDMapping : & configs.MountIDMapping {
654+ UIDMappings : mapping ,
655+ GIDMappings : mapping ,
656+ },
584657 },
585658 },
586659 },
@@ -595,8 +668,10 @@ func TestValidateIDMapMounts(t *testing.T) {
595668 Source : "/another-abs/path/" ,
596669 Destination : "/abs/path/" ,
597670 Flags : unix .MS_BIND | unix .MS_RDONLY ,
598- UIDMappings : mapping ,
599- GIDMappings : mapping ,
671+ IDMapping : & configs.MountIDMapping {
672+ UIDMappings : mapping ,
673+ GIDMappings : mapping ,
674+ },
600675 },
601676 },
602677 },
@@ -609,8 +684,10 @@ func TestValidateIDMapMounts(t *testing.T) {
609684 Source : "/abs/path/" ,
610685 Destination : "/abs/path/" ,
611686 Flags : unix .MS_BIND ,
612- UIDMappings : mapping ,
613- GIDMappings : mapping ,
687+ IDMapping : & configs.MountIDMapping {
688+ UIDMappings : mapping ,
689+ GIDMappings : mapping ,
690+ },
614691 },
615692 },
616693 },
@@ -625,14 +702,16 @@ func TestValidateIDMapMounts(t *testing.T) {
625702 Source : "/abs/path/" ,
626703 Destination : "/abs/path/" ,
627704 Flags : unix .MS_BIND ,
628- UIDMappings : []configs.IDMap {
629- {
630- ContainerID : 10 ,
631- HostID : 10 ,
632- Size : 1 ,
705+ IDMapping : & configs.MountIDMapping {
706+ UIDMappings : []configs.IDMap {
707+ {
708+ ContainerID : 10 ,
709+ HostID : 10 ,
710+ Size : 1 ,
711+ },
633712 },
713+ GIDMappings : mapping ,
634714 },
635- GIDMappings : mapping ,
636715 },
637716 },
638717 },
@@ -647,18 +726,50 @@ func TestValidateIDMapMounts(t *testing.T) {
647726 Source : "/abs/path/" ,
648727 Destination : "/abs/path/" ,
649728 Flags : unix .MS_BIND ,
650- UIDMappings : mapping ,
651- GIDMappings : []configs.IDMap {
652- {
653- ContainerID : 10 ,
654- HostID : 10 ,
655- Size : 1 ,
729+ IDMapping : & configs.MountIDMapping {
730+ UIDMappings : mapping ,
731+ GIDMappings : []configs.IDMap {
732+ {
733+ ContainerID : 10 ,
734+ HostID : 10 ,
735+ Size : 1 ,
736+ },
656737 },
657738 },
658739 },
659740 },
660741 },
661742 },
743+ {
744+ name : "mount with 'idmap' option but no mappings" ,
745+ isErr : true ,
746+ config : & configs.Config {
747+ Mounts : []* configs.Mount {
748+ {
749+ Source : "/abs/path/" ,
750+ Destination : "/abs/path/" ,
751+ Flags : unix .MS_BIND ,
752+ IDMapping : & configs.MountIDMapping {},
753+ },
754+ },
755+ },
756+ },
757+ {
758+ name : "mount with 'ridmap' option but no mappings" ,
759+ isErr : true ,
760+ config : & configs.Config {
761+ Mounts : []* configs.Mount {
762+ {
763+ Source : "/abs/path/" ,
764+ Destination : "/abs/path/" ,
765+ Flags : unix .MS_BIND ,
766+ IDMapping : & configs.MountIDMapping {
767+ Recursive : true ,
768+ },
769+ },
770+ },
771+ },
772+ },
662773 }
663774
664775 for _ , tc := range testCases {
0 commit comments