MCPcopy
hub / github.com/containerd/containerd / testIDMapMountWithAttrs

Function testIDMapMountWithAttrs

core/mount/mount_idmapped_linux_test.go:158–198  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func 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
200func initIDMappedChecker(t *testing.T, uidMaps, gidMaps []syscall.SysProcIDMap, expectWritable bool) (_srcDir string, _verifyFunc func(destDir string)) {
201 testutil.RequiresRoot(t)

Callers

nothing calls this directly

Calls 6

getUsernsFDFunction · 0.85
initIDMappedCheckerFunction · 0.85
IDMapMountWithAttrsFunction · 0.85
UnmountAllFunction · 0.70
CloseMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…