@@ -2157,7 +2157,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2157
2157
Code : 500 ,
2158
2158
},
2159
2159
},
2160
- expectedWarnings : map [runtime. Object ][] string {
2160
+ expectedWarnings : Warnings {
2161
2161
nil : {
2162
2162
"Policy default/allow-policy is missing or invalid" ,
2163
2163
},
@@ -2194,7 +2194,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2194
2194
Allow : []string {"127.0.0.1" },
2195
2195
Deny : []string {"127.0.0.2" },
2196
2196
},
2197
- expectedWarnings : map [runtime. Object ][] string {
2197
+ expectedWarnings : Warnings {
2198
2198
nil : {
2199
2199
"AccessControl policy (or policies) with deny rules is overridden by policy (or policies) with allow rules" ,
2200
2200
},
@@ -2264,7 +2264,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2264
2264
},
2265
2265
},
2266
2266
},
2267
- expectedWarnings :
B5F2
map [runtime. Object ][] string {
2267
+ expectedWarnings : Warnings {
2268
2268
nil : {
2269
2269
`RateLimit policy "default/rateLimit-policy2" with limit request option dryRun=true is overridden to dryRun=false by the first policy reference in this context` ,
2270
2270
`RateLimit policy "default/rateLimit-policy2" with limit request option logLevel=info is overridden to logLevel=error by the first policy reference in this context` ,
@@ -2307,7 +2307,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2307
2307
Code : 500 ,
2308
2308
},
2309
2309
},
2310
- expectedWarnings : map [runtime. Object ][] string {
2310
+ expectedWarnings : Warnings {
2311
2311
nil : {
2312
2312
`JWT policy "default/jwt-policy" references an invalid Secret: secret is invalid` ,
2313
2313
},
@@ -2369,7 +2369,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2369
2369
Realm : "test" ,
2370
2370
},
2371
2371
},
2372
- expectedWarnings : map [runtime. Object ][] string {
2372
+ expectedWarnings : Warnings {
2373
2373
nil : {
2374
2374
`Multiple jwt policies in the same context is not valid. JWT policy "default/jwt-policy2" will be ignored` ,
2375
2375
},
@@ -2410,7 +2410,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2410
2410
Code : 500 ,
2411
2411
},
2412
2412
},
2413
- expectedWarnings : map [runtime. Object ][] string {
2413
+ expectedWarnings : Warnings {
2414
2414
nil : {
2415
2415
`IngressMTLS policy "default/ingress-mtls-policy" references an invalid Secret: secret is invalid` ,
2416
2416
},
@@ -2465,7 +2465,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2465
2465
VerifyDepth : 1 ,
2466
2466
},
2467
2467
},
2468
- expectedWarnings : map [runtime. Object ][] string {
2468
+ expectedWarnings : Warnings {
2469
2469
nil : {
2470
2470
`Multiple ingressMTLS policies are not allowed. IngressMTLS policy "default/ingress-mtls-policy2" will be ignored` ,
2471
2471
},
@@ -2507,7 +2507,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2507
2507
Code : 500 ,
2508
2508
},
2509
2509
},
2510
- expectedWarnings : map [runtime. Object ][] string {
2510
+ expectedWarnings : Warnings {
2511
2511
nil : {
2512
2512
`IngressMTLS policy is not allowed in the route context` ,
2513
2513
},
@@ -2549,7 +2549,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2549
2549
Code : 500 ,
2550
2550
},
2551
2551
},
2552
- expectedWarnings : map [runtime. Object ][] string {
2552
+ expectedWarnings : Warnings {
2553
2553
nil : {
2554
2554
`TLS configuration needed for IngressMTLS policy` ,
2555
2555
},
@@ -2612,7 +2612,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2612
2612
SSLName : "$proxy_host" ,
2613
2613
},
2614
2614
},
2615
- expectedWarnings : map [runtime. Object ][] string {
2615
+ expectedWarnings : Warnings {
2616
2616
nil : {
2617
2617
`Multiple egressMTLS policies in the same context is not valid. EgressMTLS policy "default/egress-mtls-policy2" will be ignored` ,
2618
2618
},
@@ -2654,7 +2654,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2654
2654
Code : 500 ,
2655
2655
},
2656
2656
},
2657
- expectedWarnings : map [runtime. Object ][] string {
2657
+ expectedWarnings : Warnings {
2658
2658
nil : {
2659
2659
`EgressMTLS policy "default/egress-mtls-policy" references an invalid Secret: secret is invalid` ,
2660
2660
},
@@ -2696,7 +2696,7 @@ func TestGeneratePoliciesFails(t *testing.T) {
2696
2696
Code : 500 ,
2697
2697
},
2698
2698
},
2699
- expectedWarnings : map [runtime. Object ][] string {
2699
+ expectedWarnings : Warnings {
2700
2700
nil : {
2701
2701
`EgressMTLS policy "default/egress-mtls-policy" references an invalid Secret: secret is invalid` ,
2702
2702
},
@@ -3326,27 +3326,30 @@ func TestGenerateLocationForRedirect(t *testing.T) {
3326
3326
3327
3327
func TestGenerateSSLConfig (t * testing.T ) {
3328
3328
tests := []struct {
3329
- inputTLS * conf_v1.TLS
3330
- inputSecretRefs map [string ]* secrets.SecretReference
3331
- inputCfgParams * ConfigParams
3332
- expected * version2.SSL
3333
- msg string
3329
+ inputTLS * conf_v1.TLS
3330
+ inputSecretRefs map [string ]* secrets.SecretReference
3331
+ inputCfgParams * ConfigParams
3332
+ expectedSSL * version2.SSL
3333
+ expectedWarnings Warnings
3334
+ msg string
3334
3335
}{
3335
3336
{
3336
- inputTLS : nil ,
3337
- inputSecretRefs : map [string ]* secrets.SecretReference {},
3338
- inputCfgParams : & ConfigParams {},
3339
- expected : nil ,
3340
- msg : "no TLS field" ,
3337
+ inputTLS : nil ,
3338
+ inputSecretRefs : map [string ]* secrets.SecretReference {},
3339
+ inputCfgParams : & ConfigParams {},
3340
+ expectedSSL : nil ,
3341
+ expectedWarnings : Warnings {},
3342
+ msg : "no TLS field" ,
3341
3343
},
3342
3344
{
3343
3345
inputTLS : & conf_v1.TLS {
3344
3346
Secret : "" ,
3345
3347
},
3346
- inputSecretRefs : map [string ]* secrets.SecretReference {},
3347
- inputCfgParams : & ConfigParams {},
3348
- expected : nil ,
3349
- msg : "TLS field with empty secret" ,
3348
+ inputSecretRefs : map [string ]* secrets.SecretReference {},
3349
+ inputCfgParams : & ConfigParams {},
3350
+ expectedSSL : nil ,
3351
+ expectedWarnings : Warnings {},
3352
+ msg : "TLS field with empty secret" ,
3350
3353
},
3351
3354
{
3352
3355
inputTLS : & conf_v1.TLS {
@@ -3358,14 +3361,38 @@ func TestGenerateSSLConfig(t *testing.T) {
3358
3361
Error : errors .New ("secret doesn't exist" ),
3359
3362
},
3360
3363
},
3361
- expected : & version2.SSL {
3364
+ expectedSSL : & version2.SSL {
3362
3365
HTTP2 : false ,
3363
3366
Certificate : pemFileNameForMissingTLSSecret ,
65CE
code>
3364
3367
CertificateKey : pemFileNameForMissingTLSSecret ,
3365
3368
Ciphers : "NULL" ,
3366
3369
},
3370
+ expectedWarnings : Warnings {
3371
+ nil : []string {"TLS secret secret is invalid: secret doesn't exist" },
3372
+ },
3367
3373
msg : "secret doesn't exist in the cluster with HTTPS" ,
3368
3374
},
3375
+ {
3376
+ inputTLS : & conf_v1.TLS {
3377
+ Secret : "secret" ,
3378
+ },
3379
+ inputCfgParams : & ConfigParams {},
3380
+ inputSecretRefs : map [string ]* secrets.SecretReference {
3381
+ "default/secret" : {
3382
+ Type : secrets .SecretTypeCA ,
3383
+ },
3384
+ },
3385
+ expectedSSL : & version2.SSL {
3386
+ HTTP2 : false ,
3387
+ Certificate : pemFileNameForMissingTLSSecret ,
3388
+ CertificateKey : pemFileNameForMissingTLSSecret ,
3389
+ Ciphers : "NULL" ,
3390
+ },
3391
+ expectedWarnings : Warnings {
3392
+ nil : []string {"TLS secret secret is of a wrong type 'nginx.org/ca', must be 'kubernetes.io/tls'" },
3393
+ },
3394
+ msg : "wrong secret type" ,
3395
+ },
3369
3396
{
3370
3397
inputTLS : & conf_v1.TLS {
3371
3398
Secret : "secret" ,
@@ -3377,22 +3404,29 @@ func TestGenerateSSLConfig(t *testing.T) {
3377
3404
},
3378
3405
},
3379
3406
inputCfgParams : & ConfigParams {},
3380
- expected : & version2.SSL {
3407
+ expectedSSL : & version2.SSL {
3381
3408
HTTP2 : false ,
3382
3409
Certificate : "secret.pem" ,
3383
3410
CertificateKey : "secret.pem" ,
3384
3411
Ciphers : "" ,
3385
3412
},
3386
- msg : "normal case with HTTPS" ,
3413
+ expectedWarnings : Warnings {},
3414
+ msg : "normal case with HTTPS" ,
3387
3415
},
3388
3416
}
3389
3417
3390
3418
namespace := "default"
3391
3419
3392
3420
for _ , test := range tests {
3393
- result := generateSSLConfig (test .inputTLS , namespace , test .inputSecretRefs , test .inputCfgParams )
3394
- if ! reflect .DeepEqual (result , test .expected ) {
3395
- t .Errorf ("generateSSLConfig() returned %v but expected %v for the case of %s" , result , test .expected , test .msg )
3421
+ vsc := newVirtualServerConfigurator (& ConfigParams {}, false , false , & StaticConfigParams {})
3422
+
3423
+ // it is ok to use nil as the owner
3424
+ result := vsc .generateSSLConfig (nil , test .inputTLS , namespace , test .inputSecretRefs , test .inputCfgParams )
3425
+ if ! reflect .DeepEqual (result , test .expectedSSL ) {
3426
+ t .Errorf ("generateSSLConfig() returned %v but expected %v for the case of %s" , result , test .expectedSSL , test .msg )
3427
+ }
3428
+ if ! reflect .DeepEqual (vsc .warnings , test .expectedWarnings ) {
3429
+ t .Errorf ("generateSSLConfig() returned warnings of \n %v but expected \n %v for the case of %s" , vsc .warnings , test .expectedWarnings , test .msg )
3396
3430
}
3397
3431
}
3398
3432
}
0 commit comments