@@ -1270,6 +1270,7 @@ func TestValidateIngressRuleValue(t *testing.T) {
1270
1270
1271
1271
func TestValidateIngressCreate (t * testing.T ) {
1272
1272
implementationPathType := networking .PathTypeImplementationSpecific
1273
+ exactPathType := networking .PathTypeExact
1273
1274
serviceBackend := & networking.IngressServiceBackend {
1274
1275
Name : "defaultbackend" ,
1275
1276
Port : networking.ServiceBackendPort {
@@ -1404,6 +1405,79 @@ func TestValidateIngressCreate(t *testing.T) {
1404
1405
ingress .Spec .TLS = []networking.IngressTLS {{SecretName : "invalid name 1" }}
1405
1406
},
1406
1407
},
1408
+ "v1: valid rules with wildcard host" : {
1409
+ groupVersion : & networkingv1 .SchemeGroupVersion ,
1410
+ tweakIngress : func (ingress * networking.Ingress ) {
1411
+ ingress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1412
+ ingress .Spec .Rules = []networking.IngressRule {{
1413
+ Host : "*.foo.com" ,
1414
+ IngressRuleValue : networking.IngressRuleValue {
1415
+ HTTP : & networking.HTTPIngressRuleValue {
1416
+ Paths : []networking.HTTPIngressPath {{
1417
+ Path : "/foo" ,
1418
+ PathType : & exactPathType ,
1419
+ Backend : defaultBackend ,
1420
+ }},
1421
+ },
1422
+ },
1423
+ }}
1424
+ },
1425
+ },
1426
+ "v1: invalid rules with wildcard host" : {
1427
+ groupVersion : & networkingv1 .SchemeGroupVersion ,
1428
+ tweakIngress : func (ingress * networking.Ingress ) {
1429
+ ingress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1430
+ ingress .Spec .Rules = []networking.IngressRule {{
1431
+ Host : "*.foo.com" ,
1432
+ IngressRuleValue : networking.IngressRuleValue {
1433
+ HTTP : & networking.HTTPIngressRuleValue {
1434
+ Paths : []networking.HTTPIngressPath {{
1435
+ Path : "foo" ,
1436
+ PathType : & exactPathType ,
1437
+ Backend : defaultBackend ,
1438
+ }},
1439
+ },
1440
+ },
1441
+ }}
1442
+ },
1443
+ expectedErrs : field.ErrorList {field .Invalid (field .NewPath ("spec" ).Child ("rules" ).Index (0 ).Child ("http" ).Child ("paths" ).Index (0 ).Child ("path" ), "foo" , `must be an absolute path` )},
1444
+ },
1445
+ "v1beta1: valid rules with wildcard host" : {
1446
+ groupVersion : & networkingv1beta1 .SchemeGroupVersion ,
1447
+ tweakIngress : func (ingress * networking.Ingress ) {
1448
+ ingress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1449
+ ingress .Spec .Rules = []networking.IngressRule {{
1450
+ Host : "*.foo.com" ,
1451
+ IngressRuleValue : networking.IngressRuleValue {
1452
+ HTTP : & networking.HTTPIngressRuleValue {
1453
+ Paths : []networking.HTTPIngressPath {{
1454
+ Path : "/foo" ,
1455
+ PathType : & exactPathType ,
1456
+ Backend : defaultBackend ,
1457
+ }},
1458
+ },
1459
+ },
1460
+ }}
1461
+ },
1462
+ },
1463
+ "v1beta1: invalid rules with wildcard host" : {
1464
+ groupVersion : & networkingv1beta1 .SchemeGroupVersion ,
1465
+ tweakIngress : func (ingress * networking.Ingress ) {
1466
+ ingress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1467
+ ingress .Spec .Rules = []networking.IngressRule {{
1468
+ Host : "*.foo.com" ,
1469
+ IngressRuleValue : networking.IngressRuleValue {
1470
+ HTTP : & networking.HTTPIngressRuleValue {
1471
+ Paths : []networking.HTTPIngressPath {{
1472
+ Path : "foo" ,
1473
+ PathType : & exactPathType ,
1474
+ Backend : defaultBackend ,
1475
+ }},
1476
+ },
1477
+ },
1478
+ }}
1479
+ },
1480
+ },
1407
1481
}
1408
1482
1409
1483
for name , testCase := range testCases {
@@ -1430,6 +1504,7 @@ func TestValidateIngressCreate(t *testing.T) {
1430
1504
1431
1505
func TestValidateIngressUpdate (t * testing.T ) {
1432
1506
implementationPathType := networking .PathTypeImplementationSpecific
1507
+ exactPathType := networking .PathTypeExact
1433
1508
serviceBackend := & networking.IngressServiceBackend {
1434
1509
Name : "defaultbackend" ,
1435
1510
Port : networking.ServiceBackendPort {
@@ -1769,6 +1844,131 @@ func TestValidateIngressUpdate(t *testing.T) {
1769
1844
newIngress .Spec .TLS = []networking.IngressTLS {{SecretName : "invalid name 2" }}
1770
1845
},
1771
1846
},
1847
+ "v1: change valid rules with wildcard host -> invalid rules" : {
1848
+ gv : networkingv1 .SchemeGroupVersion ,
1849
+ tweakIngresses : func (newIngress , oldIngress * networking.Ingress ) {
1850
+ oldIngress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1851
+ oldIngress .Spec .Rules = []networking.IngressRule {{
1852
+ Host : "*.foo.com" ,
1853
+ IngressRuleValue : networking.IngressRuleValue {
1854
+ HTTP : & networking.HTTPIngressRuleValue {
1855
+ Paths : []networking.HTTPIngressPath {{
1856
+ Path : "/foo" ,
1857
+ PathType : & exactPathType ,
1858
+ Backend : defaultBackend ,
1859
+ }},
1860
+ },
1861
+ },
1862
+ }}
1863
+ newIngress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1864
+ newIngress .Spec .Rules = []networking.IngressRule {{
1865
+ Host : "*.foo.com" ,
1866
+ IngressRuleValue : networking.IngressRuleValue {
1867
+ HTTP : & networking.HTTPIngressRuleValue {
1868
+ Paths : []networking.HTTPIngressPath {{
1869
+ Path : "foo" ,
1870
+ PathType : & exactPathType ,
1871
+ Backend : defaultBackend ,
1872
+ }},
1873
+ },
1874
+ },
1875
+ }}
1876
+ },
1877
+ expectedErrs : field.ErrorList {field .Invalid (field .NewPath ("spec" ).Child ("rules" ).Index (0 ).Child ("http" ).Child ("paths" ).Index (0 ).Child ("path" ), "foo" , `must be an absolute path` )},
1878
+ },
1879
+ "v1: change invalid rules with wildcard host -> invalid rules" : {
1880
+ gv : networkingv1 .SchemeGroupVersion ,
1881
+ tweakIngresses : func (newIngress , oldIngress * networking.Ingress ) {
1882
+ oldIngress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1883
+ oldIngress .Spec .Rules = []networking.IngressRule {{
1884
+ Host : "*.foo.com" ,
1885
+ IngressRuleValue : networking.IngressRuleValue {
1886
+ HTTP : & networking.HTTPIngressRuleValue {
1887
+ Paths : []networking.HTTPIngressPath {{
1888
+ Path : "foo" ,
1889
+ PathType : & exactPathType ,
1890
+ Backend : defaultBackend ,
1891
+ }},
1892
+ },
1893
+ },
1894
+ }}
1895
+ newIngress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1896
+ newIngress .Spec .Rules = []networking.IngressRule {{
1897
+ Host : "*.foo.com" ,
1898
+ IngressRuleValue : networking.IngressRuleValue {
1899
+ HTTP : & networking.HTTPIngressRuleValue {
1900
+ Paths : []networking.HTTPIngressPath {{
1901
+ Path : "bar" ,
1902
+ PathType : & exactPathType ,
1903
+ Backend : defaultBackend ,
1904
+ }},
1905
+ },
1906
+ },
1907
+ }}
1908
+ },
1909
+ },
1910
+ "v1beta1: change valid rules with wildcard host -> invalid rules" : {
1911
+ gv : networkingv1beta1 .SchemeGroupVersion ,
1912
+ tweakIngresses : func (newIngress , oldIngress * networking.Ingress ) {
1913
+ oldIngress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1914
+ oldIngress .Spec .Rules = []networking.IngressRule {{
1915
+ Host : "*.foo.com" ,
1916
+ IngressRuleValue : networking.IngressRuleValue {
1917
+ HTTP : & networking.HTTPIngressRuleValue {
1918
+ Paths : []networking.HTTPIngressPath {{
1919
+ Path : "/foo" ,
1920
+ PathType : & exactPathType ,
1921
+ Backend : defaultBackend ,
1922
+ }},
1923
+ },
1924
+ },
1925
+ }}
1926
+ newIngress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1927
+ newIngress .Spec .Rules = []networking.IngressRule {{
1928
+ Host : "*.foo.com" ,
1929
+ IngressRuleValue : networking.IngressRuleValue {
1930
+ HTTP : & networking.HTTPIngressRuleValue {
1931
+ Paths : []networking.HTTPIngressPath {{
1932
+ Path : "foo" ,
1933
+ PathType : & exactPathType ,
1934
+ Backend : defaultBackend ,
1935
+ }},
1936
+ },
1937
+ },
1938
+ }}
1939
+ },
1940
+ },
1941
+ "v1beta1: change invalid rules with wildcard host -> invalid rules" : {
1942
+ gv : networkingv1beta1 .SchemeGroupVersion ,
1943
+ tweakIngresses : func (newIngress , oldIngress * networking.Ingress ) {
1944
+ oldIngress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1945
+ oldIngress .Spec .Rules = []networking.IngressRule {{
1946
+ Host : "*.foo.com" ,
1947
+ IngressRuleValue : networking.IngressRuleValue {
1948
+ HTTP : & networking.HTTPIngressRuleValue {
1949
+ Paths : []networking.HTTPIngressPath {{
1950
+ Path : "foo" ,
1951
+ PathType : & exactPathType ,
1952
+ Backend : defaultBackend ,
1953
+ }},
1954
+ },
1955
+ },
1956
+ }}
1957
+ newIngress .Spec .TLS = []networking.IngressTLS {{Hosts : []string {"*.bar.com" }}}
1958
+ newIngress .Spec .Rules = []networking.IngressRule {{
1959
+ Host : "*.foo.com" ,
1960
+ IngressRuleValue : networking.IngressRuleValue {
1961
+ HTTP : & networking.HTTPIngressRuleValue {
1962
+ Paths : []networking.HTTPIngressPath {{
1963
+ Path : "bar" ,
1964
+ PathType : & exactPathType ,
1965
+ Backend : defaultBackend ,
1966
+ }},
1967
+ },
1968
+ },
1969
+ }}
1970
+ },
1971
+ },
1772
1972
}
1773
1973
1774
1974
for name , testCase := range testCases {
@@ -1984,6 +2184,7 @@ func TestValidateIngressClassUpdate(t *testing.T) {
1984
2184
}
1985
2185
1986
2186
func TestValidateIngressTLS (t * testing.T ) {
2187
+ pathTypeImplementationSpecific := networking .PathTypeImplementationSpecific
1987
2188
serviceBackend := & networking.IngressServiceBackend {
1988
2189
Name : "defaultbackend" ,
1989
2190
Port : networking.ServiceBackendPort {
@@ -2008,8 +2209,9 @@ func TestValidateIngressTLS(t *testing.T) {
2008
2209
HTTP : & networking.HTTPIngressRuleValue {
2009
2210
Paths : []networking.HTTPIngressPath {
2010
2211
{
2011
- Path : "/foo" ,
2012
- Backend : defaultBackend ,
2212
+ Path : "/foo" ,
2213
+ PathType : & pathTypeImplementationSpecific ,
2214
+ Backend : defaultBackend ,
2013
2215
},
2014
2216
},
2015
2217
},
0 commit comments