@@ -68,6 +68,29 @@ func TestConfigMapUnpacker(t *testing.T) {
6868 roleBindings []* rbacv1.RoleBinding
6969 }
7070
71+ var expectedReadOnlyRootFilesystem = false
72+ var expectedAllowPrivilegeEscalation = false
73+ var expectedRunAsNonRoot = true
74+ var expectedRunAsUser int64 = 1001
75+ var expectedPrivileged = false
76+
77+ var expectedContainerSecurityContext = & corev1.SecurityContext {
78+ Privileged : & expectedPrivileged ,
79+ ReadOnlyRootFilesystem : & expectedReadOnlyRootFilesystem ,
80+ AllowPrivilegeEscalation : & expectedAllowPrivilegeEscalation ,
81+ Capabilities : & corev1.Capabilities {
82+ Drop : []corev1.Capability {"ALL" },
83+ },
84+ }
85+
86+ var expectedPodSecurityContext = & corev1.PodSecurityContext {
87+ RunAsNonRoot : & expectedRunAsNonRoot ,
88+ RunAsUser : & expectedRunAsUser ,
89+ SeccompProfile : & corev1.SeccompProfile {
90+ Type : corev1 .SeccompProfileTypeRuntimeDefault ,
91+ },
92+ }
93+
7194 tests := []struct {
7295 description string
7396 fields fields
@@ -220,6 +243,7 @@ func TestConfigMapUnpacker(t *testing.T) {
220243 Spec : corev1.PodSpec {
221244 RestartPolicy : corev1 .RestartPolicyNever ,
222245 ImagePullSecrets : []corev1.LocalObjectReference {{Name : "my-secret" }},
246+ SecurityContext : expectedPodSecurityContext ,
223247 Containers : []corev1.Container {
224248 {
225249 Name : "extract" ,
@@ -243,6 +267,7 @@ func TestConfigMapUnpacker(t *testing.T) {
243267 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
244268 },
245269 },
270+ SecurityContext : expectedContainerSecurityContext ,
246271 },
247272 },
248273 InitContainers : []corev1.Container {
@@ -262,6 +287,7 @@ func TestConfigMapUnpacker(t *testing.T) {
262287 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
263288 },
264289 },
290+ SecurityContext : expectedContainerSecurityContext ,
265291 },
266292 {
267293 Name : "pull" ,
@@ -284,6 +310,7 @@ func TestConfigMapUnpacker(t *testing.T) {
284310 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
285311 },
286312 },
313+ SecurityContext : expectedContainerSecurityContext ,
287314 },
288315 },
289316 Volumes : []corev1.Volume {
@@ -396,7 +423,8 @@ func TestConfigMapUnpacker(t *testing.T) {
396423 Name : pathHash ,
397424 },
398425 Spec : corev1.PodSpec {
399- RestartPolicy : corev1 .RestartPolicyNever ,
426+ RestartPolicy : corev1 .RestartPolicyNever ,
427+ SecurityContext : expectedPodSecurityContext ,
400428 Containers : []corev1.Container {
401429 {
402430 Name : "extract" ,
@@ -420,6 +448,7 @@ func TestConfigMapUnpacker(t *testing.T) {
420448 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
421449 },
422450 },
451+ SecurityContext : expectedContainerSecurityContext ,
423452 },
424453 },
425454 InitContainers : []corev1.Container {
@@ -439,6 +468,7 @@ func TestConfigMapUnpacker(t *testing.T) {
439468 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
440469 },
441470 },
471+ SecurityContext : expectedContainerSecurityContext ,
442472 },
443473 {
444474 Name : "pull" ,
@@ -461,6 +491,7 @@ func TestConfigMapUnpacker(t *testing.T) {
461491 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
462492 },
463493 },
494+ SecurityContext : expectedContainerSecurityContext ,
464495 },
465496 },
466497 Volumes : []corev1.Volume {
@@ -614,7 +645,8 @@ func TestConfigMapUnpacker(t *testing.T) {
614645 Name : pathHash ,
615646 },
616647 Spec : corev1.PodSpec {
617- RestartPolicy : corev1 .RestartPolicyNever ,
648+ RestartPolicy : corev1 .RestartPolicyNever ,
649+ SecurityContext : expectedPodSecurityContext ,
618650 Containers : []corev1.Container {
619651 {
620652 Name : "extract" ,
@@ -638,6 +670,7 @@ func TestConfigMapUnpacker(t *testing.T) {
638670 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
639671 },
640672 },
673+ SecurityContext : expectedContainerSecurityContext ,
641674 },
642675 },
643676 InitContainers : []corev1.Container {
@@ -657,6 +690,7 @@ func TestConfigMapUnpacker(t *testing.T) {
657690 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
658691 },
659692 },
693+ SecurityContext : expectedContainerSecurityContext ,
660694 },
661695 {
662696 Name : "pull" ,
@@ -679,6 +713,7 @@ func TestConfigMapUnpacker(t *testing.T) {
679713 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
680714 },
681715 },
716+ SecurityContext : expectedContainerSecurityContext ,
682717 },
683718 },
684719 Volumes : []corev1.Volume {
@@ -826,7 +861,8 @@ func TestConfigMapUnpacker(t *testing.T) {
826861 Name : pathHash ,
827862 },
828863 Spec : corev1.PodSpec {
829- RestartPolicy : corev1 .RestartPolicyNever ,
864+ RestartPolicy : corev1 .RestartPolicyNever ,
865+ SecurityContext : expectedPodSecurityContext ,
830866 Containers : []corev1.Container {
831867 {
832868 Name : "extract" ,
@@ -850,6 +886,7 @@ func TestConfigMapUnpacker(t *testing.T) {
850886 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
851887 },
852888 },
889+ SecurityContext : expectedContainerSecurityContext ,
853890 },
854891 },
855892 InitContainers : []corev1.Container {
@@ -869,6 +906,7 @@ func TestConfigMapUnpacker(t *testing.T) {
869906 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
870907 },
871908 },
909+ SecurityContext : expectedContainerSecurityContext ,
872910 },
873911 {
874912 Name : "pull" ,
@@ -891,6 +929,7 @@ func TestConfigMapUnpacker(t *testing.T) {
891929 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
892930 },
893931 },
932+ SecurityContext : expectedContainerSecurityContext ,
894933 },
895934 },
896935 Volumes : []corev1.Volume {
@@ -1008,7 +1047,8 @@ func TestConfigMapUnpacker(t *testing.T) {
10081047 Name : pathHash ,
10091048 },
10101049 Spec : corev1.PodSpec {
1011- RestartPolicy : corev1 .RestartPolicyNever ,
1050+ RestartPolicy : corev1 .RestartPolicyNever ,
1051+ SecurityContext : expectedPodSecurityContext ,
10121052 Containers : []corev1.Container {
10131053 {
10141054 Name : "extract" ,
@@ -1032,6 +1072,7 @@ func TestConfigMapUnpacker(t *testing.T) {
10321072 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
10331073 },
10341074 },
1075+ SecurityContext : expectedContainerSecurityContext ,
10351076 },
10361077 },
10371078 InitContainers : []corev1.Container {
@@ -1051,6 +1092,7 @@ func TestConfigMapUnpacker(t *testing.T) {
10511092 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
10521093 },
10531094 },
1095+ SecurityContext : expectedContainerSecurityContext ,
10541096 },
10551097 {
10561098 Name : "pull" ,
@@ -1073,6 +1115,7 @@ func TestConfigMapUnpacker(t *testing.T) {
10731115 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
10741116 },
10751117 },
1118+ SecurityContext : expectedContainerSecurityContext ,
10761119 },
10771120 },
10781121 Volumes : []corev1.Volume {
@@ -1201,7 +1244,8 @@ func TestConfigMapUnpacker(t *testing.T) {
12011244 Name : pathHash ,
12021245 },
12031246 Spec : corev1.PodSpec {
1204- RestartPolicy : corev1 .RestartPolicyNever ,
1247+ RestartPolicy : corev1 .RestartPolicyNever ,
1248+ SecurityContext : expectedPodSecurityContext ,
12051249 Containers : []corev1.Container {
12061250 {
12071251 Name : "extract" ,
@@ -1225,6 +1269,7 @@ func TestConfigMapUnpacker(t *testing.T) {
12251269 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
12261270 },
12271271 },
1272+ SecurityContext : expectedContainerSecurityContext ,
12281273 },
12291274 },
12301275 InitContainers : []corev1.Container {
@@ -1244,6 +1289,7 @@ func TestConfigMapUnpacker(t *testing.T) {
12441289 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
12451290 },
12461291 },
1292+ SecurityContext : expectedContainerSecurityContext ,
12471293 },
12481294 {
12491295 Name : "pull" ,
@@ -1266,6 +1312,7 @@ func TestConfigMapUnpacker(t *testing.T) {
12661312 corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
12671313 },
12681314 },
1315+ SecurityContext : expectedContainerSecurityContext ,
12691316 },
12701317 },
12711318 Volumes : []corev1.Volume {
0 commit comments