@@ -1055,71 +1055,34 @@ func TestValidateTLS(t *testing.T) {
1055
1055
}
1056
1056
}
1057
1057
1058
- func TestValidateTLSInsecureEdgeTerminationPolicy (t * testing.T ) {
1059
- tests := []struct {
1060
- name string
1061
- route * api.Route
1062
- }{
1063
- {
1064
- name : "Passthrough termination" ,
1065
- route : & api.Route {
1066
- Spec : api.RouteSpec {
1067
- TLS : & api.TLSConfig {
1068
- Termination : api .TLSTerminationPassthrough ,
1069
- },
1070
- },
1071
- },
1072
- },
1073
- {
1074
- name : "Reencrypt termination" ,
1075
- route : & api.Route {
1076
- Spec : api.RouteSpec {
1077
- TLS : & api.TLSConfig {
1078
- Termination : api .TLSTerminationReencrypt ,
1079
- DestinationCACertificate : "dca" ,
1080
- },
1081
- },
1082
- },
1083
- },
1084
- {
1085
- name : "Reencrypt termination DestCACert" ,
1086
- route : & api.Route {
1087
- Spec : api.RouteSpec {
1088
- TLS : & api.TLSConfig {
1089
- Termination : api .TLSTerminationReencrypt ,
1090
- DestinationCACertificate : testDestinationCACertificate ,
1091
- },
1092
- },
1093
- },
1094
- },
1095
- }
1058
+ func TestValidatePassthroughInsecureEdgeTerminationPolicy (t * testing.T ) {
1096
1059
1097
- insecureTypes := []api.InsecureEdgeTerminationPolicyType {
1098
- api .InsecureEdgeTerminationPolicyNone ,
1099
- api .InsecureEdgeTerminationPolicyAllow ,
1100
- api .InsecureEdgeTerminationPolicyRedirect ,
1101
- "support HTTPsec" ,
1102
- "or maybe HSTS" ,
1060
+ insecureTypes := map [api.InsecureEdgeTerminationPolicyType ]bool {
1061
+ "" : false ,
1062
+ api .InsecureEdgeTerminationPolicyNone : false ,
1063
+ api .InsecureEdgeTerminationPolicyAllow : true ,
1064
+ api .InsecureEdgeTerminationPolicyRedirect : false ,
1065
+ "support HTTPsec" : true ,
1066
+ "or maybe HSTS" : true ,
1103
1067
}
1104
1068
1105
- for _ , tc := range tests {
1106
- if errs := validateTLS (tc .route , nil ); len (errs ) != 0 {
1107
- t .Errorf ("Test case %s got %d errors where none were expected. %v" ,
1108
- tc .name , len (errs ), errs )
1069
+ for key , expected := range insecureTypes {
1070
+ route := & api.Route {
1071
+ Spec : api.RouteSpec {
1072
+ TLS : & api.TLSConfig {
1073
+ Termination : api .TLSTerminationPassthrough ,
1074
+ InsecureEdgeTerminationPolicy : key ,
1075
+ },
1076
+ },
1109
1077
}
1110
-
1111
- tc . route . Spec . TLS . InsecureEdgeTerminationPolicy = ""
1112
- if errs := validateTLS ( tc . route , nil ); len (errs ) != 0 {
1113
- t .Errorf ("Test case %s got %d errors where none were expected. %v" ,
1114
- tc . name , len (errs ), errs )
1078
+ route . Spec . TLS . InsecureEdgeTerminationPolicy = key
1079
+ errs := validateTLS ( route , nil )
1080
+ if ! expected && len (errs ) != 0 {
1081
+ t .Errorf ("Test case for Passthrough termination with insecure= %s got %d errors where none where expected. %v" ,
1082
+ key , len (errs ), errs )
1115
1083
}
1116
-
1117
- for _ , val := range insecureTypes {
1118
- tc .route .Spec .TLS .InsecureEdgeTerminationPolicy = val
1119
- if errs := validateTLS (tc .route , nil ); len (errs ) != 1 {
1120
- t .Errorf ("Test case %s with insecure=%q got %d errors where one was expected. %v" ,
1121
- tc .name , val , len (errs ), errs )
1122
- }
1084
+ if expected && len (errs ) == 0 {
1085
+ t .Errorf ("Test case for Passthrough termination with insecure=%s got no errors where some where expected." , key )
1123
1086
}
1124
1087
}
1125
1088
}
@@ -1258,7 +1221,45 @@ func TestValidateInsecureEdgeTerminationPolicy(t *testing.T) {
1258
1221
}
1259
1222
}
1260
1223
1261
- func TestValidateNoTLSInsecureEdgeTerminationPolicy (t * testing.T ) {
1224
+ func TestValidateEdgeReencryptInsecureEdgeTerminationPolicy (t * testing.T ) {
1225
+ tests := []struct {
1226
+ name string
1227
+ route * api.Route
1228
+ }{
1229
+ {
1230
+ name : "Reencrypt termination" ,
1231
+ route : & api.Route {
1232
+ Spec : api.RouteSpec {
1233
+ TLS : & api.TLSConfig {
1234
+ Termination : api .TLSTerminationReencrypt ,
1235
+ DestinationCACertificate : "dca" ,
1236
+ },
1237
+ },
1238
+ },
1239
+ },
1240
+ {
1241
+ name : "Reencrypt termination DestCACert" ,
1242
+ route : & api.Route {
1243
+ Spec : api.RouteSpec {
1244
+ TLS : & api.TLSConfig {
1245
+ Termination : api .TLSTerminationReencrypt ,
1246
+ DestinationCACertificate : testDestinationCACertificate ,
1247
+ },
1248
+ },
1249
+ },
1250
+ },
1251
+ {
1252
+ name : "Edge termination" ,
1253
+ route : & api.Route {
1254
+ Spec : api.RouteSpec {
1255
+ TLS : & api.TLSConfig {
1256
+ Termination : api .TLSTerminationEdge ,
1257
+ },
1258
+ },
1259
+ },
1260
+ },
1261
+ }
1262
+
1262
1263
insecureTypes := map [api.InsecureEdgeTerminationPolicyType ]bool {
1263
1264
api .InsecureEdgeTerminationPolicyNone : false ,
1264
1265
api .InsecureEdgeTerminationPolicyAllow : false ,
@@ -1267,22 +1268,17 @@ func TestValidateNoTLSInsecureEdgeTerminationPolicy(t *testing.T) {
1267
1268
"or maybe HSTS" : true ,
1268
1269
}
1269
1270
1270
- for key , expected := range insecureTypes {
1271
- route := & api.Route {
1272
- Spec : api.RouteSpec {
1273
- TLS : & api.TLSConfig {
1274
- Termination : api .TLSTerminationEdge ,
1275
- InsecureEdgeTerminationPolicy : key ,
1276
- },
1277
- },
1278
- }
1279
- errs := validateTLS (route , nil )
1280
- if ! expected && len (errs ) != 0 {
1281
- t .Errorf ("Test case for edge termination with insecure=%s got %d errors where none were expected. %v" ,
1282
- key , len (errs ), errs )
1283
- }
1284
- if expected && len (errs ) == 0 {
1285
- t .Errorf ("Test case for edge termination with insecure=%s got no errors where some were expected." , key )
1271
+ for _ , tc := range tests {
1272
+ for key , expected := range insecureTypes {
1273
+ tc .route .Spec .TLS .InsecureEdgeTerminationPolicy = key
1274
+ errs := validateTLS (tc .route , nil )
1275
+ if ! expected && len (errs ) != 0 {
1276
+ t .Errorf ("Test case %s with insecure=%s got %d errors where none were expected. %v" ,
1277
+ tc .name , key , len (errs ), errs )
1278
+ }
1279
+ if expected && len (errs ) == 0 {
1280
+ t .Errorf ("Test case %s with insecure=%s got no errors where some were expected." , tc .name , key )
1281
+ }
1286
1282
}
1287
1283
}
1288
1284
}
0 commit comments