@@ -68,4 +68,138 @@ var _ = framework.IngressNginxDescribe("[Ingress] [PathType] prefix checks", fun
68
68
Expect ().
69
69
Status (http .StatusOK )
70
70
})
71
+
72
+ ginkgo .It ("should test prefix path using simple regex pattern for /id/{int}" , func () {
73
+ host := "echo.com.br"
74
+
75
+ annotations := map [string ]string {
76
+ "nginx.ingress.kubernetes.io/use-regex" : `true` ,
77
+ }
78
+
79
+ ing := framework .NewSingleIngress (host , "/id/[0-9]+" , host , f .Namespace , framework .EchoService , 80 , annotations )
80
+ f .EnsureIngress (ing )
81
+
82
+ f .HTTPTestClient ().
83
+ GET ("/id/1" ).
84
+ WithHeader ("Host" , host ).
85
+ Expect ().
86
+ Status (http .StatusOK )
87
+
88
+ f .HTTPTestClient ().
89
+ GET ("/id/12" ).
90
+ WithHeader ("Host" , host ).
91
+ Expect ().
92
+ Status (http .StatusOK )
93
+
94
+ f .HTTPTestClient ().
95
+ GET ("/id/123" ).
96
+ WithHeader ("Host" , host ).
97
+ Expect ().
98
+ Status (http .StatusOK )
99
+
100
+ f .HTTPTestClient ().
101
+ GET ("/id/aaa" ).
102
+ WithHeader ("Host" , host ).
103
+ Expect ().
104
+ Status (http .StatusNotFound )
105
+
106
+ f .HTTPTestClient ().
107
+ GET ("/id/123a" ).
108
+ WithHeader ("Host" , host ).
109
+ Expect ().
110
+ Status (http .StatusOK )
111
+ })
112
+
113
+ ginkgo .It ("should test prefix path using regex pattern for /id/{int} ignoring non-digits characters at end of string" , func () {
114
+ host := "echo.regex.br"
115
+
116
+ annotations := map [string ]string {
117
+ "nginx.ingress.kubernetes.io/use-regex" : `true` ,
118
+ }
119
+
120
+ ing := framework .NewSingleIngress (host , "/id/[0-9]+$" , host , f .Namespace , framework .EchoService , 80 , annotations )
121
+ f .EnsureIngress (ing )
122
+
123
+ f .HTTPTestClient ().
124
+ GET ("/id/1" ).
125
+ WithHeader ("Host" , host ).
126
+ Expect ().
127
+ Status (http .StatusOK )
128
+
129
+ f .HTTPTestClient ().
130
+ GET ("/id/aaa" ).
131
+ WithHeader ("Host" , host ).
132
+ Expect ().
133
+ Status (http .StatusNotFound )
134
+
135
+ f .HTTPTestClient ().
136
+ GET ("/id/123a" ).
137
+ WithHeader ("Host" , host ).
138
+ Expect ().
139
+ Status (http .StatusNotFound )
140
+ })
141
+
142
+ ginkgo .It ("should test prefix path using fixed path size regex pattern /id/{int}{3}" , func () {
143
+ host := "echo.regex.size.br"
144
+
145
+ annotations := map [string ]string {
146
+ "nginx.ingress.kubernetes.io/use-regex" : `true` ,
147
+ }
148
+
149
+ ing := framework .NewSingleIngress (host , "/id/[0-9]{3}$" , host , f .Namespace , framework .EchoService , 80 , annotations )
150
+ f .EnsureIngress (ing )
151
+
152
+ f .HTTPTestClient ().
153
+ GET ("/id/99" ).
154
+ WithHeader ("Host" , host ).
155
+ Expect ().
156
+ Status (http .StatusNotFound )
157
+
158
+ f .HTTPTestClient ().
159
+ GET ("/id/123" ).
160
+ WithHeader ("Host" , host ).
161
+ Expect ().
162
+ Status (http .StatusOK )
163
+
164
+ f .HTTPTestClient ().
165
+ GET ("/id/9999" ).
166
+ WithHeader ("Host" , host ).
167
+ Expect ().
168
+ Status (http .StatusNotFound )
169
+
170
+ f .HTTPTestClient ().
171
+ GET ("/id/123a" ).
172
+ WithHeader ("Host" , host ).
173
+ Expect ().
174
+ Status (http .StatusNotFound )
175
+ })
176
+
177
+ ginkgo .It ("should correctly route multi-segment path patterns" , func () {
178
+ host := "echo.multi.segment.br"
179
+
180
+ annotations := map [string ]string {
181
+ "nginx.ingress.kubernetes.io/use-regex" : `true` ,
182
+ }
183
+
184
+ ing := framework .NewSingleIngress (host , "/id/[0-9]+/post/[a-zA-Z]+$" , host , f .Namespace , framework .EchoService , 80 , annotations )
185
+ f .EnsureIngress (ing )
186
+
187
+ f .HTTPTestClient ().
188
+ GET ("/id/123/post/abc" ).
189
+ WithHeader ("Host" , host ).
190
+ Expect ().
191
+ Status (http .StatusOK )
192
+
193
+ f .HTTPTestClient ().
194
+ GET ("/id/123/post/abc123" ).
195
+ WithHeader ("Host" , host ).
196
+ Expect ().
197
+ Status (http .StatusNotFound )
198
+
199
+ f .HTTPTestClient ().
200
+ GET ("/id/abc/post/abc" ).
201
+ WithHeader ("Host" , host ).
202
+ Expect ().
203
+ Status (http .StatusNotFound )
204
+ })
71
205
})
0 commit comments