(t *testing.T)
| 131 | } |
| 132 | |
| 133 | func 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", |
nothing calls this directly
no test coverage detected
searching dependent graphs…