(t *testing.T)
| 156 | } |
| 157 | |
| 158 | func testIDMapMountWithAttrs(t *testing.T) { |
| 159 | usernsFD, err := getUsernsFD(testUIDMaps, testGIDMaps) |
| 160 | require.NoError(t, err) |
| 161 | defer usernsFD.Close() |
| 162 | |
| 163 | type testCase struct { |
| 164 | name string |
| 165 | srcDir string |
| 166 | setAttr uint64 |
| 167 | checkFunc func(destDir string) |
| 168 | } |
| 169 | |
| 170 | cases := make([]testCase, 0) |
| 171 | srcDir, checkFunc := initIDMappedChecker(t, testUIDMaps, testGIDMaps, true) |
| 172 | cases = append(cases, testCase{ |
| 173 | name: "Writable idmapped mount", |
| 174 | srcDir: srcDir, |
| 175 | setAttr: 0, |
| 176 | checkFunc: checkFunc, |
| 177 | }) |
| 178 | |
| 179 | srcDir, checkFunc = initIDMappedChecker(t, testUIDMaps, testGIDMaps, false) |
| 180 | cases = append(cases, testCase{ |
| 181 | name: "Readonly idmapped mount", |
| 182 | srcDir: srcDir, |
| 183 | setAttr: unix.MOUNT_ATTR_RDONLY, |
| 184 | checkFunc: checkFunc, |
| 185 | }) |
| 186 | |
| 187 | for _, tc := range cases { |
| 188 | t.Run(tc.name, func(t *testing.T) { |
| 189 | destDir := t.TempDir() |
| 190 | defer func() { |
| 191 | require.NoError(t, UnmountAll(destDir, 0)) |
| 192 | }() |
| 193 | err := IDMapMountWithAttrs(tc.srcDir, destDir, int(usernsFD.Fd()), tc.setAttr, 0) |
| 194 | require.NoError(t, err) |
| 195 | tc.checkFunc(destDir) |
| 196 | }) |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | func initIDMappedChecker(t *testing.T, uidMaps, gidMaps []syscall.SysProcIDMap, expectWritable bool) (_srcDir string, _verifyFunc func(destDir string)) { |
| 201 | testutil.RequiresRoot(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…