@@ -82,7 +82,7 @@ func TestIngressCorsConfigValid(t *testing.T) {
82
82
data [parser .GetAnnotationWithPrefix (corsAllowHeadersAnnotation )] = "DNT,X-CustomHeader, Keep-Alive,User-Agent"
83
83
data [parser .GetAnnotationWithPrefix (corsAllowCredentialsAnnotation )] = "false"
84
84
data [parser .GetAnnotationWithPrefix (corsAllowMethodsAnnotation )] = "GET, PATCH"
85
- data [parser .GetAnnotationWithPrefix (corsAllowOriginAnnotation )] = "https://origin123.test.com:4443"
85
+ data [parser .GetAnnotationWithPrefix (corsAllowOriginAnnotation )] = "null, https://origin123.test.com:4443"
86
86
data [parser .GetAnnotationWithPrefix (corsExposeHeadersAnnotation )] = "*, X-CustomResponseHeader"
87
87
data [parser .GetAnnotationWithPrefix (corsMaxAgeAnnotation )] = "600"
88
88
ing .SetAnnotations (data )
@@ -113,7 +113,7 @@ func TestIngressCorsConfigValid(t *testing.T) {
113
113
t .Errorf ("expected %v but returned %v" , data [parser .GetAnnotationWithPrefix (corsAllowMethodsAnnotation )], nginxCors .CorsAllowMethods )
114
114
}
115
115
116
- if nginxCors .CorsAllowOrigin [ 0 ] != "https://origin123.test.com:4443" {
116
+ if ! reflect . DeepEqual ( nginxCors .CorsAllowOrigin , [] string { "null" , "https://origin123.test.com:4443" }) {
117
117
t .Errorf ("expected %v but returned %v" , data [parser .GetAnnotationWithPrefix (corsAllowOriginAnnotation )], nginxCors .CorsAllowOrigin )
118
118
}
119
119
@@ -176,7 +176,7 @@ func TestIngressCorsConfigInvalid(t *testing.T) {
176
176
}
177
177
}
178
178
179
- func TestIngresCorsConfigAllowOriginWithTrailingComma (t * testing.T ) {
179
+ func TestIngressCorsConfigAllowOriginWithTrailingComma (t * testing.T ) {
180
180
ing := buildIngress ()
181
181
182
182
data := map [string ]string {}
@@ -206,6 +206,36 @@ func TestIngresCorsConfigAllowOriginWithTrailingComma(t *testing.T) {
206
206
}
207
207
}
208
208
209
+ func TestIngressCorsConfigAllowOriginNull (t * testing.T ) {
210
+ ing := buildIngress ()
211
+
212
+ data := map [string ]string {}
213
+ data [parser .GetAnnotationWithPrefix (corsEnableAnnotation )] = enableAnnotation
214
+
215
+ // Include a trailing comma and an empty value between the commas.
216
+ data [parser .GetAnnotationWithPrefix (corsAllowOriginAnnotation )] = "https://origin123.test.com:4443,null,https://origin321.test.com:4443"
217
+ ing .SetAnnotations (data )
218
+
219
+ corst , err := NewParser (& resolver.Mock {}).Parse (ing )
220
+ if err != nil {
221
+ t .Errorf ("error parsing annotations: %v" , err )
222
+ }
223
+
224
+ nginxCors , ok := corst .(* Config )
225
+ if ! ok {
226
+ t .Errorf ("expected a Config type but returned %t" , corst )
227
+ }
228
+
229
+ if ! nginxCors .CorsEnabled {
230
+ t .Errorf ("expected %v but returned %v" , data [parser .GetAnnotationWithPrefix (corsEnableAnnotation )], nginxCors .CorsEnabled )
231
+ }
232
+
233
+ expectedCorsAllowOrigins := []string {"https://origin123.test.com:4443" , "null" , "https://origin321.test.com:4443" }
234
+ if ! reflect .DeepEqual (nginxCors .CorsAllowOrigin , expectedCorsAllowOrigins ) {
235
+ t .Errorf ("expected %v but returned %v" , expectedCorsAllowOrigins , nginxCors .CorsAllowOrigin )
236
+ }
237
+ }
238
+
209
239
func TestIngressCorsConfigAllowOriginWithNonHttpProtocol (t * testing.T ) {
210
240
ing := buildIngress ()
211
241
0 commit comments