@@ -68,6 +68,29 @@ func TestConfigMapUnpacker(t *testing.T) {
68
68
roleBindings []* rbacv1.RoleBinding
69
69
}
70
70
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
+
71
94
tests := []struct {
72
95
description string
73
96
fields fields
@@ -220,6 +243,7 @@ func TestConfigMapUnpacker(t *testing.T) {
220
243
Spec : corev1.PodSpec {
221
244
RestartPolicy : corev1 .RestartPolicyNever ,
222
245
ImagePullSecrets : []corev1.LocalObjectReference {{Name : "my-secret" }},
246
+ SecurityContext : expectedPodSecurityContext ,
223
247
Containers : []corev1.Container {
224
248
{
225
249
Name : "extract" ,
@@ -243,6 +267,7 @@ func TestConfigMapUnpacker(t *testing.T) {
243
267
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
244
268
},
245
269
},
270
+ SecurityContext : expectedContainerSecurityContext ,
246
271
},
247
272
},
248
273
InitContainers : []corev1.Container {
@@ -262,6 +287,7 @@ func TestConfigMapUnpacker(t *testing.T) {
262
287
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
263
288
},
264
289
},
290
+ SecurityContext : expectedContainerSecurityContext ,
265
291
},
266
292
{
267
293
Name : "pull" ,
@@ -284,6 +310,7 @@ func TestConfigMapUnpacker(t *testing.T) {
284
310
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
285
311
},
286
312
},
313
+ SecurityContext : expectedContainerSecurityContext ,
287
314
},
288
315
},
289
316
Volumes : []corev1.Volume {
@@ -396,7 +423,8 @@ func TestConfigMapUnpacker(t *testing.T) {
396
423
Name : pathHash ,
397
424
},
398
425
Spec : corev1.PodSpec {
399
- RestartPolicy : corev1 .RestartPolicyNever ,
426
+ RestartPolicy : corev1 .RestartPolicyNever ,
427
+ SecurityContext : expectedPodSecurityContext ,
400
428
Containers : []corev1.Container {
401
429
{
402
430
Name : "extract" ,
@@ -420,6 +448,7 @@ func TestConfigMapUnpacker(t *testing.T) {
420
448
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
421
449
},
422
450
},
451
+ SecurityContext : expectedContainerSecurityContext ,
423
452
},
424
453
},
425
454
InitContainers : []corev1.Container {
@@ -439,6 +468,7 @@ func TestConfigMapUnpacker(t *testing.T) {
439
468
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
440
469
},
441
470
},
471
+ SecurityContext : expectedContainerSecurityContext ,
442
472
},
443
473
{
444
474
Name : "pull" ,
@@ -461,6 +491,7 @@ func TestConfigMapUnpacker(t *testing.T) {
461
491
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
462
492
},
463
493
},
494
+ SecurityContext : expectedContainerSecurityContext ,
464
495
},
465
496
},
466
497
Volumes : []corev1.Volume {
@@ -614,7 +645,8 @@ func TestConfigMapUnpacker(t *testing.T) {
614
645
Name : pathHash ,
615
646
},
616
647
Spec : corev1.PodSpec {
617
- RestartPolicy : corev1 .RestartPolicyNever ,
648
+ RestartPolicy : corev1 .RestartPolicyNever ,
649
+ SecurityContext : expectedPodSecurityContext ,
618
650
Containers : []corev1.Container {
619
651
{
620
652
Name : "extract" ,
@@ -638,6 +670,7 @@ func TestConfigMapUnpacker(t *testing.T) {
638
670
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
639
671
},
640
672
},
673
+ SecurityContext : expectedContainerSecurityContext ,
641
674
},
642
675
},
643
676
InitContainers : []corev1.Container {
@@ -657,6 +690,7 @@ func TestConfigMapUnpacker(t *testing.T) {
657
690
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
658
691
},
659
692
},
693
+ SecurityContext : expectedContainerSecurityContext ,
660
694
},
661
695
{
662
696
Name : "pull" ,
@@ -679,6 +713,7 @@ func TestConfigMapUnpacker(t *testing.T) {
679
713
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
680
714
},
681
715
},
716
+ SecurityContext : expectedContainerSecurityContext ,
682
717
},
683
718
},
684
719
Volumes : []corev1.Volume {
@@ -826,7 +861,8 @@ func TestConfigMapUnpacker(t *testing.T) {
826
861
Name : pathHash ,
827
862
},
828
863
Spec : corev1.PodSpec {
829
- RestartPolicy : corev1 .RestartPolicyNever ,
864
+ RestartPolicy : corev1 .RestartPolicyNever ,
865
+ SecurityContext : expectedPodSecurityContext ,
830
866
Containers : []corev1.Container {
831
867
{
832
868
Name : "extract" ,
@@ -850,6 +886,7 @@ func TestConfigMapUnpacker(t *testing.T) {
850
886
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
851
887
},
852
888
},
889
+ SecurityContext : expectedContainerSecurityContext ,
853
890
},
854
891
},
855
892
InitContainers : []corev1.Container {
@@ -869,6 +906,7 @@ func TestConfigMapUnpacker(t *testing.T) {
869
906
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
870
907
},
871
908
},
909
+ SecurityContext : expectedContainerSecurityContext ,
872
910
},
873
911
{
874
912
Name : "pull" ,
@@ -891,6 +929,7 @@ func TestConfigMapUnpacker(t *testing.T) {
891
929
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
892
930
},
893
931
},
932
+ SecurityContext : expectedContainerSecurityContext ,
894
933
},
895
934
},
896
935
Volumes : []corev1.Volume {
@@ -1008,7 +1047,8 @@ func TestConfigMapUnpacker(t *testing.T) {
1008
1047
Name : pathHash ,
1009
1048
},
1010
1049
Spec : corev1.PodSpec {
1011
- RestartPolicy : corev1 .RestartPolicyNever ,
1050
+ RestartPolicy : corev1 .RestartPolicyNever ,
1051
+ SecurityContext : expectedPodSecurityContext ,
1012
1052
Containers : []corev1.Container {
1013
1053
{
1014
1054
Name : "extract" ,
@@ -1032,6 +1072,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1032
1072
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1033
1073
},
1034
1074
},
1075
+ SecurityContext : expectedContainerSecurityContext ,
1035
1076
},
1036
1077
},
1037
1078
InitContainers : []corev1.Container {
@@ -1051,6 +1092,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1051
1092
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1052
1093
},
1053
1094
},
1095
+ SecurityContext : expectedContainerSecurityContext ,
1054
1096
},
1055
1097
{
1056
1098
Name : "pull" ,
@@ -1073,6 +1115,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1073
1115
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1074
1116
},
1075
1117
},
1118
+ SecurityContext : expectedContainerSecurityContext ,
1076
1119
},
1077
1120
},
1078
1121
Volumes : []corev1.Volume {
@@ -1201,7 +1244,8 @@ func TestConfigMapUnpacker(t *testing.T) {
1201
1244
Name : pathHash ,
1202
1245
},
1203
1246
Spec : corev1.PodSpec {
1204
- RestartPolicy : corev1 .RestartPolicyNever ,
1247
+ RestartPolicy : corev1 .RestartPolicyNever ,
1248
+ SecurityContext : expectedPodSecurityContext ,
1205
1249
Containers : []corev1.Container {
1206
1250
{
1207
1251
Name : "extract" ,
@@ -1225,6 +1269,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1225
1269
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1226
1270
},
1227
1271
},
1272
+ SecurityContext : expectedContainerSecurityContext ,
1228
1273
},
1229
1274
},
1230
1275
InitContainers : []corev1.Container {
@@ -1244,6 +1289,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1244
1289
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1245
1290
},
1246
1291
},
1292
+ SecurityContext : expectedContainerSecurityContext ,
1247
1293
},
1248
1294
{
1249
1295
Name : "pull" ,
@@ -1266,6 +1312,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1266
1312
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1267
1313
},
1268
1314
},
1315
+ SecurityContext : expectedContainerSecurityContext ,
1269
1316
},
1270
1317
},
1271
1318
Volumes : []corev1.Volume {
0 commit comments