MCPcopy Create free account
hub / github.com/Mirantis/cri-dockerd / TestModifyHostConfig

Function TestModifyHostConfig

core/security_context_test.go:133–215  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

131}
132
133func TestModifyHostConfig(t *testing.T) {
134 setNetworkHC := &dockercontainer.HostConfig{}
135
136 // When we have Privileged pods, we do not need to use the
137 // Masked / Readonly paths.
138 setPrivSC := &runtimeapi.LinuxContainerSecurityContext{}
139 setPrivSC.Privileged = true
140 setPrivSC.MaskedPaths = []string{"/hello/world/masked"}
141 setPrivSC.ReadonlyPaths = []string{"/hello/world/readonly"}
142 setPrivHC := &dockercontainer.HostConfig{
143 Privileged: true,
144 }
145
146 unsetPrivSC := &runtimeapi.LinuxContainerSecurityContext{}
147 unsetPrivSC.Privileged = false
148 unsetPrivSC.MaskedPaths = []string{"/hello/world/masked"}
149 unsetPrivSC.ReadonlyPaths = []string{"/hello/world/readonly"}
150 unsetPrivHC := &dockercontainer.HostConfig{
151 Privileged: false,
152 MaskedPaths: []string{"/hello/world/masked"},
153 ReadonlyPaths: []string{"/hello/world/readonly"},
154 }
155
156 setCapsHC := &dockercontainer.HostConfig{
157 CapAdd: []string{"addCapA", "addCapB"},
158 CapDrop: []string{"dropCapA", "dropCapB"},
159 }
160 setSELinuxHC := &dockercontainer.HostConfig{
161 SecurityOpt: []string{
162 fmt.Sprintf("%s:%s", selinuxLabelUser('='), "user"),
163 fmt.Sprintf("%s:%s", selinuxLabelRole('='), "role"),
164 fmt.Sprintf("%s:%s", selinuxLabelType('='), "type"),
165 fmt.Sprintf("%s:%s", selinuxLabelLevel('='), "level"),
166 },
167 }
168
169 cases := []struct {
170 name string
171 sc *runtimeapi.LinuxContainerSecurityContext
172 expected *dockercontainer.HostConfig
173 }{
174 {
175 name: "fully set container.SecurityContext",
176 sc: fullValidSecurityContext(),
177 expected: fullValidHostConfig(),
178 },
179 {
180 name: "empty container.SecurityContext",
181 sc: &runtimeapi.LinuxContainerSecurityContext{},
182 expected: setNetworkHC,
183 },
184 {
185 name: "container.SecurityContext.Privileged",
186 sc: setPrivSC,
187 expected: setPrivHC,
188 },
189 {
190 name: "container.SecurityContext.NoPrivileges",

Callers

nothing calls this directly

Calls 9

selinuxLabelUserFunction · 0.85
selinuxLabelRoleFunction · 0.85
selinuxLabelTypeFunction · 0.85
selinuxLabelLevelFunction · 0.85
fullValidSecurityContextFunction · 0.85
fullValidHostConfigFunction · 0.85
inputCapabilitiesFunction · 0.85
inputSELinuxOptionsFunction · 0.85
modifyHostConfigFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…