@@ -82,7 +82,7 @@ func TestIngressCorsConfigValid(t *testing.T) {
8282 data [parser .GetAnnotationWithPrefix (corsAllowHeadersAnnotation )] = "DNT,X-CustomHeader, Keep-Alive,User-Agent"
8383 data [parser .GetAnnotationWithPrefix (corsAllowCredentialsAnnotation )] = "false"
8484 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"
8686 data [parser .GetAnnotationWithPrefix (corsExposeHeadersAnnotation )] = "*, X-CustomResponseHeader"
8787 data [parser .GetAnnotationWithPrefix (corsMaxAgeAnnotation )] = "600"
8888 ing .SetAnnotations (data )
@@ -113,7 +113,7 @@ func TestIngressCorsConfigValid(t *testing.T) {
113113 t .Errorf ("expected %v but returned %v" , data [parser .GetAnnotationWithPrefix (corsAllowMethodsAnnotation )], nginxCors .CorsAllowMethods )
114114 }
115115
116- if nginxCors .CorsAllowOrigin [ 0 ] != "https://origin123.test.com:4443" {
116+ if ! reflect . DeepEqual ( nginxCors .CorsAllowOrigin , [] string { "null" , "https://origin123.test.com:4443" }) {
117117 t .Errorf ("expected %v but returned %v" , data [parser .GetAnnotationWithPrefix (corsAllowOriginAnnotation )], nginxCors .CorsAllowOrigin )
118118 }
119119
@@ -176,7 +176,7 @@ func TestIngressCorsConfigInvalid(t *testing.T) {
176176 }
177177}
178178
179- func TestIngresCorsConfigAllowOriginWithTrailingComma (t * testing.T ) {
179+ func TestIngressCorsConfigAllowOriginWithTrailingComma (t * testing.T ) {
180180 ing := buildIngress ()
181181
182182 data := map [string ]string {}
@@ -206,6 +206,36 @@ func TestIngresCorsConfigAllowOriginWithTrailingComma(t *testing.T) {
206206 }
207207}
208208
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+
209239func TestIngressCorsConfigAllowOriginWithNonHttpProtocol (t * testing.T ) {
210240 ing := buildIngress ()
211241
0 commit comments