33
33
import org .springframework .boot .actuate .endpoint .web .PathMappedEndpoints ;
34
34
import org .springframework .boot .actuate .endpoint .web .annotation .ServletEndpoint ;
35
35
import org .springframework .boot .autoconfigure .security .servlet .RequestMatcherProvider ;
36
- import org .springframework .boot .autoconfigure .web .servlet .DispatcherServletPath ;
37
36
import org .springframework .mock .web .MockHttpServletRequest ;
38
37
import org .springframework .mock .web .MockServletContext ;
39
38
import org .springframework .security .web .util .matcher .RequestMatcher ;
@@ -55,19 +54,19 @@ public class EndpointRequestTests {
55
54
@ Test
56
55
public void toAnyEndpointShouldMatchEndpointPath () {
57
56
RequestMatcher matcher = EndpointRequest .toAnyEndpoint ();
58
- assertMatcher (matcher , "/actuator" , "/" ).matches ("/actuator/foo" );
59
- assertMatcher (matcher , "/actuator" , "/" ).matches ("/actuator/foo/zoo/" );
60
- assertMatcher (matcher , "/actuator" , "/" ).matches ("/actuator/bar" );
61
- assertMatcher (matcher , "/actuator" , "/" ).matches ("/actuator/bar/baz" );
62
- assertMatcher (matcher , "/actuator" , "/" ).matches ("/actuator" );
57
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator/foo" );
58
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator/foo/zoo/" );
59
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator/bar" );
60
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator/bar/baz" );
61
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator" );
63
62
}
64
63
65
64
@ Test
66
65
public void toAnyEndpointShouldMatchEndpointPathWithTrailingSlash () {
67
66
RequestMatcher matcher = EndpointRequest .toAnyEndpoint ();
68
- assertMatcher (matcher , "/actuator" , "/" ).matches ("/actuator/foo/" );
69
- assertMatcher (matcher , "/actuator" , "/" ).matches ("/actuator/bar/" );
70
- assertMatcher (matcher , "/actuator" , "/" ).matches ("/actuator/" );
67
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator/foo/" );
68
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator/bar/" );
69
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator/" );
71
70
}
72
71
73
72
@ Test
@@ -85,26 +84,13 @@ public void toAnyEndpointShouldNotMatchOtherPath() {
85
84
assertMatcher (matcher ).doesNotMatch ("/actuator/baz" );
86
85
}
87
86
88
- @ Test
89
- public void toAnyEndpointWhenServletPathNotEmptyShouldMatch () {
90
- RequestMatcher matcher = EndpointRequest .toAnyEndpoint ();
91
- assertMatcher (matcher , "/actuator" , "/spring" ).matches ("/spring" ,
92
- "/actuator/foo" );
93
- assertMatcher (matcher , "/actuator" , "/spring" ).matches ("/spring" ,
94
- "/actuator/bar" );
95
- assertMatcher (matcher , "/actuator" , "/spring" ).matches ("/spring" , "/actuator" );
96
- assertMatcher (matcher , "/actuator" , "/spring" ).doesNotMatch ("/spring" ,
97
- "/actuator/baz" );
98
- assertMatcher (matcher , "/actuator" , "/spring" ).doesNotMatch ("" , "/actuator/foo" );
99
- }
100
-
101
87
@ Test
102
88
public void toAnyEndpointWhenDispatcherServletPathProviderNotAvailableUsesEmptyPath () {
103
89
RequestMatcher matcher = EndpointRequest .toAnyEndpoint ();
104
- assertMatcher (matcher , "/actuator" , null ).matches ("/actuator/foo" );
105
- assertMatcher (matcher , "/actuator" , null ).matches ("/actuator/bar" );
106
- assertMatcher (matcher , "/actuator" , null ).matches ("/actuator" );
107
- assertMatcher (matcher , "/actuator" , null ).doesNotMatch ("/actuator/baz" );
90
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator/foo" );
91
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator/bar" );
92
+ assertMatcher (matcher , "/actuator" ).matches ("/actuator" );
93
+ assertMatcher (matcher , "/actuator" ).doesNotMatch ("/actuator/baz" );
108
94
}
109
95
110
96
@ Test
@@ -151,14 +137,6 @@ public void toLinksWhenBasePathEmptyShouldNotMatch() {
151
137
assertMatcher .doesNotMatch ("/" );
152
138
}
153
139
154
- @ Test
155
- public void toLinksWhenServletPathNotEmptyShouldMatch () {
156
- RequestMatcher matcher = EndpointRequest .toLinks ();
157
- RequestMatcherAssert assertMatcher = assertMatcher (matcher , "/actuator" ,
158
- "/spring" );
159
- assertMatcher .matches ("/spring/actuator" );
160
- }
161
-
162
140
@ Test
163
141
public void excludeByClassShouldNotMatchExcluded () {
164
142
RequestMatcher matcher = EndpointRequest .toAnyEndpoint ()
@@ -221,7 +199,7 @@ public void endpointRequestMatcherShouldUseCustomRequestMatcherProvider() {
221
199
RequestMatcher matcher = EndpointRequest .toAnyEndpoint ();
222
200
RequestMatcher mockRequestMatcher = (request ) -> false ;
223
201
RequestMatcherAssert assertMatcher = assertMatcher (matcher ,
224
- mockPathMappedEndpoints ("" ), "" , (pattern ) -> mockRequestMatcher );
202
+ mockPathMappedEndpoints ("" ), (pattern ) -> mockRequestMatcher );
225
203
assertMatcher .doesNotMatch ("/foo" );
226
204
assertMatcher .doesNotMatch ("/bar" );
227
205
}
@@ -231,8 +209,7 @@ public void linksRequestMatcherShouldUseCustomRequestMatcherProvider() {
231
209
RequestMatcher matcher = EndpointRequest .toLinks ();
232
210
RequestMatcher mockRequestMatcher = (request ) -> false ;
233
211
RequestMatcherAssert assertMatcher = assertMatcher (matcher ,
234
- mockPathMappedEndpoints ("/actuator" ), "" ,
235
- (pattern ) -> mockRequestMatcher );
212
+ mockPathMappedEndpoints ("/actuator" ), (pattern ) -> mockRequestMatcher );
236
213
assertMatcher .doesNotMatch ("/actuator" );
237
214
}
238
215
@@ -248,13 +225,7 @@ private RequestMatcherAssert assertMatcher(RequestMatcher matcher) {
248
225
}
249
226
250
227
private RequestMatcherAssert assertMatcher (RequestMatcher matcher , String basePath ) {
251
- return assertMatcher (matcher , mockPathMappedEndpoints (basePath ));
252
- }
253
-
254
- private RequestMatcherAssert assertMatcher (RequestMatcher matcher , String basePath ,
255
- String servletPath ) {
256
- return assertMatcher (matcher , mockPathMappedEndpoints (basePath ), servletPath ,
257
- null );
228
+ return assertMatcher (matcher , mockPathMappedEndpoints (basePath ), null );
258
229
}
259
230
260
231
private PathMappedEndpoints mockPathMappedEndpoints (String basePath ) {
@@ -273,11 +244,11 @@ private TestEndpoint mockEndpoint(EndpointId id, String rootPath) {
273
244
274
245
private RequestMatcherAssert assertMatcher (RequestMatcher matcher ,
275
246
PathMappedEndpoints pathMappedEndpoints ) {
276
- return assertMatcher (matcher , pathMappedEndpoints , "" , null );
247
+ return assertMatcher (matcher , pathMappedEndpoints , null );
277
248
}
278
249
279
250
private RequestMatcherAssert assertMatcher (RequestMatcher matcher ,
280
- PathMappedEndpoints pathMappedEndpoints , String dispatcherServletPath ,
251
+ PathMappedEndpoints pathMappedEndpoints ,
281
252
RequestMatcherProvider matcherProvider ) {
282
253
StaticWebApplicationContext context = new StaticWebApplicationContext ();
283
254
context .registerBean (WebEndpointProperties .class );
@@ -289,10 +260,6 @@ private RequestMatcherAssert assertMatcher(RequestMatcher matcher,
289
260
properties .setBasePath (pathMappedEndpoints .getBasePath ());
290
261
}
291
262
}
292
- if (dispatcherServletPath != null ) {
293
- DispatcherServletPath path = () -> dispatcherServletPath ;
294
- context .registerBean (DispatcherServletPath .class , () -> path );
295
- }
296
263
if (matcherProvider != null ) {
297
264
context .registerBean (RequestMatcherProvider .class , () -> matcherProvider );
298
265
}
@@ -314,10 +281,6 @@ public void matches(String servletPath) {
314
281
matches (mockRequest (servletPath ));
315
282
}
316
283
317
- public void matches (String servletPath , String pathInfo ) {
318
- matches (mockRequest (servletPath , pathInfo ));
319
- }
320
-
321
284
private void matches (HttpServletRequest request ) {
322
285
assertThat (this .matcher .matches (request ))
323
286
.as ("Matches " + getRequestPath (request )).isTrue ();
@@ -327,20 +290,12 @@ public void doesNotMatch(String servletPath) {
327
290
doesNotMatch (mockRequest (servletPath ));
328
291
}
329
292
330
- public void doesNotMatch (String servletPath , String pathInfo ) {
331
- doesNotMatch (mockRequest (servletPath , pathInfo ));
332
- }
333
-
334
293
private void doesNotMatch (HttpServletRequest request ) {
335
294
assertThat (this .matcher .matches (request ))
336
295
.as ("Does not match " + getRequestPath (request )).isFalse ();
337
296
}
338
297
339
298
private MockHttpServletRequest mockRequest (String servletPath ) {
340
- return mockRequest (servletPath , null );
341
- }
342
-
343
- private MockHttpServletRequest mockRequest (String servletPath , String path ) {
344
299
MockServletContext servletContext = new MockServletContext ();
345
300
servletContext .setAttribute (
346
301
WebApplicationContext .ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE ,
@@ -349,7 +304,6 @@ private MockHttpServletRequest mockRequest(String servletPath, String path) {
349
304
if (servletPath != null ) {
350
305
request .setServletPath (servletPath );
351
306
}
352
- request .setPathInfo (path );
353
307
return request ;
354
308
}
355
309
0 commit comments