Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
d4cad5e9
Commit
d4cad5e9
authored
Oct 16, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Servlet path not explicitly required for EndpointRequest"
Closes gh-14503
parent
0fd873f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
64 deletions
+31
-64
AbstractEndpointRequestIntegrationTests.java
...rity/servlet/AbstractEndpointRequestIntegrationTests.java
+2
-1
EndpointRequestTests.java
.../autoconfigure/security/servlet/EndpointRequestTests.java
+17
-63
MvcEndpointRequestIntegrationTests.java
.../security/servlet/MvcEndpointRequestIntegrationTests.java
+12
-0
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java
View file @
d4cad5e9
...
@@ -21,6 +21,7 @@ import java.util.List;
...
@@ -21,6 +21,7 @@ import java.util.List;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.endpoint.EndpointId
;
import
org.springframework.boot.actuate.endpoint.ExposableEndpoint
;
import
org.springframework.boot.actuate.endpoint.ExposableEndpoint
;
import
org.springframework.boot.actuate.endpoint.Operation
;
import
org.springframework.boot.actuate.endpoint.Operation
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
...
@@ -118,7 +119,7 @@ public abstract class AbstractEndpointRequestIntegrationTests {
...
@@ -118,7 +119,7 @@ public abstract class AbstractEndpointRequestIntegrationTests {
private
TestPathMappedEndpoint
mockEndpoint
(
String
id
)
{
private
TestPathMappedEndpoint
mockEndpoint
(
String
id
)
{
TestPathMappedEndpoint
endpoint
=
mock
(
TestPathMappedEndpoint
.
class
);
TestPathMappedEndpoint
endpoint
=
mock
(
TestPathMappedEndpoint
.
class
);
given
(
endpoint
.
get
Id
()).
willReturn
(
id
);
given
(
endpoint
.
get
EndpointId
()).
willReturn
(
EndpointId
.
of
(
id
)
);
given
(
endpoint
.
getRootPath
()).
willReturn
(
id
);
given
(
endpoint
.
getRootPath
()).
willReturn
(
id
);
return
endpoint
;
return
endpoint
;
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java
View file @
d4cad5e9
...
@@ -33,7 +33,6 @@ import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoint;
...
@@ -33,7 +33,6 @@ import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoint;
import
org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints
;
import
org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints
;
import
org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint
;
import
org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint
;
import
org.springframework.boot.autoconfigure.security.servlet.RequestMatcherProvider
;
import
org.springframework.boot.autoconfigure.security.servlet.RequestMatcherProvider
;
import
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.security.web.util.matcher.RequestMatcher
;
import
org.springframework.security.web.util.matcher.RequestMatcher
;
...
@@ -55,19 +54,19 @@ public class EndpointRequestTests {
...
@@ -55,19 +54,19 @@ public class EndpointRequestTests {
@Test
@Test
public
void
toAnyEndpointShouldMatchEndpointPath
()
{
public
void
toAnyEndpointShouldMatchEndpointPath
()
{
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
assertMatcher
(
matcher
,
"/actuator"
,
"/"
).
matches
(
"/actuator/foo"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator/foo"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/"
).
matches
(
"/actuator/foo/zoo/"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator/foo/zoo/"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/"
).
matches
(
"/actuator/bar"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator/bar"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/"
).
matches
(
"/actuator/bar/baz"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator/bar/baz"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/"
).
matches
(
"/actuator"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator"
);
}
}
@Test
@Test
public
void
toAnyEndpointShouldMatchEndpointPathWithTrailingSlash
()
{
public
void
toAnyEndpointShouldMatchEndpointPathWithTrailingSlash
()
{
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
assertMatcher
(
matcher
,
"/actuator"
,
"/"
).
matches
(
"/actuator/foo/"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator/foo/"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/"
).
matches
(
"/actuator/bar/"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator/bar/"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/"
).
matches
(
"/actuator/"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator/"
);
}
}
@Test
@Test
...
@@ -85,26 +84,13 @@ public class EndpointRequestTests {
...
@@ -85,26 +84,13 @@ public class EndpointRequestTests {
assertMatcher
(
matcher
).
doesNotMatch
(
"/actuator/baz"
);
assertMatcher
(
matcher
).
doesNotMatch
(
"/actuator/baz"
);
}
}
@Test
public
void
toAnyEndpointWhenServletPathNotEmptyShouldMatch
()
{
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
assertMatcher
(
matcher
,
"/actuator"
,
"/spring"
).
matches
(
"/spring"
,
"/actuator/foo"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/spring"
).
matches
(
"/spring"
,
"/actuator/bar"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/spring"
).
matches
(
"/spring"
,
"/actuator"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/spring"
).
doesNotMatch
(
"/spring"
,
"/actuator/baz"
);
assertMatcher
(
matcher
,
"/actuator"
,
"/spring"
).
doesNotMatch
(
""
,
"/actuator/foo"
);
}
@Test
@Test
public
void
toAnyEndpointWhenDispatcherServletPathProviderNotAvailableUsesEmptyPath
()
{
public
void
toAnyEndpointWhenDispatcherServletPathProviderNotAvailableUsesEmptyPath
()
{
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
assertMatcher
(
matcher
,
"/actuator"
,
null
).
matches
(
"/actuator/foo"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator/foo"
);
assertMatcher
(
matcher
,
"/actuator"
,
null
).
matches
(
"/actuator/bar"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator/bar"
);
assertMatcher
(
matcher
,
"/actuator"
,
null
).
matches
(
"/actuator"
);
assertMatcher
(
matcher
,
"/actuator"
).
matches
(
"/actuator"
);
assertMatcher
(
matcher
,
"/actuator"
,
null
).
doesNotMatch
(
"/actuator/baz"
);
assertMatcher
(
matcher
,
"/actuator"
).
doesNotMatch
(
"/actuator/baz"
);
}
}
@Test
@Test
...
@@ -151,14 +137,6 @@ public class EndpointRequestTests {
...
@@ -151,14 +137,6 @@ public class EndpointRequestTests {
assertMatcher
.
doesNotMatch
(
"/"
);
assertMatcher
.
doesNotMatch
(
"/"
);
}
}
@Test
public
void
toLinksWhenServletPathNotEmptyShouldMatch
()
{
RequestMatcher
matcher
=
EndpointRequest
.
toLinks
();
RequestMatcherAssert
assertMatcher
=
assertMatcher
(
matcher
,
"/actuator"
,
"/spring"
);
assertMatcher
.
matches
(
"/spring/actuator"
);
}
@Test
@Test
public
void
excludeByClassShouldNotMatchExcluded
()
{
public
void
excludeByClassShouldNotMatchExcluded
()
{
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
()
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
()
...
@@ -221,7 +199,7 @@ public class EndpointRequestTests {
...
@@ -221,7 +199,7 @@ public class EndpointRequestTests {
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
RequestMatcher
mockRequestMatcher
=
(
request
)
->
false
;
RequestMatcher
mockRequestMatcher
=
(
request
)
->
false
;
RequestMatcherAssert
assertMatcher
=
assertMatcher
(
matcher
,
RequestMatcherAssert
assertMatcher
=
assertMatcher
(
matcher
,
mockPathMappedEndpoints
(
""
),
""
,
(
pattern
)
->
mockRequestMatcher
);
mockPathMappedEndpoints
(
""
),
(
pattern
)
->
mockRequestMatcher
);
assertMatcher
.
doesNotMatch
(
"/foo"
);
assertMatcher
.
doesNotMatch
(
"/foo"
);
assertMatcher
.
doesNotMatch
(
"/bar"
);
assertMatcher
.
doesNotMatch
(
"/bar"
);
}
}
...
@@ -231,8 +209,7 @@ public class EndpointRequestTests {
...
@@ -231,8 +209,7 @@ public class EndpointRequestTests {
RequestMatcher
matcher
=
EndpointRequest
.
toLinks
();
RequestMatcher
matcher
=
EndpointRequest
.
toLinks
();
RequestMatcher
mockRequestMatcher
=
(
request
)
->
false
;
RequestMatcher
mockRequestMatcher
=
(
request
)
->
false
;
RequestMatcherAssert
assertMatcher
=
assertMatcher
(
matcher
,
RequestMatcherAssert
assertMatcher
=
assertMatcher
(
matcher
,
mockPathMappedEndpoints
(
"/actuator"
),
""
,
mockPathMappedEndpoints
(
"/actuator"
),
(
pattern
)
->
mockRequestMatcher
);
(
pattern
)
->
mockRequestMatcher
);
assertMatcher
.
doesNotMatch
(
"/actuator"
);
assertMatcher
.
doesNotMatch
(
"/actuator"
);
}
}
...
@@ -248,13 +225,7 @@ public class EndpointRequestTests {
...
@@ -248,13 +225,7 @@ public class EndpointRequestTests {
}
}
private
RequestMatcherAssert
assertMatcher
(
RequestMatcher
matcher
,
String
basePath
)
{
private
RequestMatcherAssert
assertMatcher
(
RequestMatcher
matcher
,
String
basePath
)
{
return
assertMatcher
(
matcher
,
mockPathMappedEndpoints
(
basePath
));
return
assertMatcher
(
matcher
,
mockPathMappedEndpoints
(
basePath
),
null
);
}
private
RequestMatcherAssert
assertMatcher
(
RequestMatcher
matcher
,
String
basePath
,
String
servletPath
)
{
return
assertMatcher
(
matcher
,
mockPathMappedEndpoints
(
basePath
),
servletPath
,
null
);
}
}
private
PathMappedEndpoints
mockPathMappedEndpoints
(
String
basePath
)
{
private
PathMappedEndpoints
mockPathMappedEndpoints
(
String
basePath
)
{
...
@@ -273,11 +244,11 @@ public class EndpointRequestTests {
...
@@ -273,11 +244,11 @@ public class EndpointRequestTests {
private
RequestMatcherAssert
assertMatcher
(
RequestMatcher
matcher
,
private
RequestMatcherAssert
assertMatcher
(
RequestMatcher
matcher
,
PathMappedEndpoints
pathMappedEndpoints
)
{
PathMappedEndpoints
pathMappedEndpoints
)
{
return
assertMatcher
(
matcher
,
pathMappedEndpoints
,
""
,
null
);
return
assertMatcher
(
matcher
,
pathMappedEndpoints
,
null
);
}
}
private
RequestMatcherAssert
assertMatcher
(
RequestMatcher
matcher
,
private
RequestMatcherAssert
assertMatcher
(
RequestMatcher
matcher
,
PathMappedEndpoints
pathMappedEndpoints
,
String
dispatcherServletPath
,
PathMappedEndpoints
pathMappedEndpoints
,
RequestMatcherProvider
matcherProvider
)
{
RequestMatcherProvider
matcherProvider
)
{
StaticWebApplicationContext
context
=
new
StaticWebApplicationContext
();
StaticWebApplicationContext
context
=
new
StaticWebApplicationContext
();
context
.
registerBean
(
WebEndpointProperties
.
class
);
context
.
registerBean
(
WebEndpointProperties
.
class
);
...
@@ -289,10 +260,6 @@ public class EndpointRequestTests {
...
@@ -289,10 +260,6 @@ public class EndpointRequestTests {
properties
.
setBasePath
(
pathMappedEndpoints
.
getBasePath
());
properties
.
setBasePath
(
pathMappedEndpoints
.
getBasePath
());
}
}
}
}
if
(
dispatcherServletPath
!=
null
)
{
DispatcherServletPath
path
=
()
->
dispatcherServletPath
;
context
.
registerBean
(
DispatcherServletPath
.
class
,
()
->
path
);
}
if
(
matcherProvider
!=
null
)
{
if
(
matcherProvider
!=
null
)
{
context
.
registerBean
(
RequestMatcherProvider
.
class
,
()
->
matcherProvider
);
context
.
registerBean
(
RequestMatcherProvider
.
class
,
()
->
matcherProvider
);
}
}
...
@@ -314,10 +281,6 @@ public class EndpointRequestTests {
...
@@ -314,10 +281,6 @@ public class EndpointRequestTests {
matches
(
mockRequest
(
servletPath
));
matches
(
mockRequest
(
servletPath
));
}
}
public
void
matches
(
String
servletPath
,
String
pathInfo
)
{
matches
(
mockRequest
(
servletPath
,
pathInfo
));
}
private
void
matches
(
HttpServletRequest
request
)
{
private
void
matches
(
HttpServletRequest
request
)
{
assertThat
(
this
.
matcher
.
matches
(
request
))
assertThat
(
this
.
matcher
.
matches
(
request
))
.
as
(
"Matches "
+
getRequestPath
(
request
)).
isTrue
();
.
as
(
"Matches "
+
getRequestPath
(
request
)).
isTrue
();
...
@@ -327,20 +290,12 @@ public class EndpointRequestTests {
...
@@ -327,20 +290,12 @@ public class EndpointRequestTests {
doesNotMatch
(
mockRequest
(
servletPath
));
doesNotMatch
(
mockRequest
(
servletPath
));
}
}
public
void
doesNotMatch
(
String
servletPath
,
String
pathInfo
)
{
doesNotMatch
(
mockRequest
(
servletPath
,
pathInfo
));
}
private
void
doesNotMatch
(
HttpServletRequest
request
)
{
private
void
doesNotMatch
(
HttpServletRequest
request
)
{
assertThat
(
this
.
matcher
.
matches
(
request
))
assertThat
(
this
.
matcher
.
matches
(
request
))
.
as
(
"Does not match "
+
getRequestPath
(
request
)).
isFalse
();
.
as
(
"Does not match "
+
getRequestPath
(
request
)).
isFalse
();
}
}
private
MockHttpServletRequest
mockRequest
(
String
servletPath
)
{
private
MockHttpServletRequest
mockRequest
(
String
servletPath
)
{
return
mockRequest
(
servletPath
,
null
);
}
private
MockHttpServletRequest
mockRequest
(
String
servletPath
,
String
path
)
{
MockServletContext
servletContext
=
new
MockServletContext
();
MockServletContext
servletContext
=
new
MockServletContext
();
servletContext
.
setAttribute
(
servletContext
.
setAttribute
(
WebApplicationContext
.
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
,
WebApplicationContext
.
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
,
...
@@ -349,7 +304,6 @@ public class EndpointRequestTests {
...
@@ -349,7 +304,6 @@ public class EndpointRequestTests {
if
(
servletPath
!=
null
)
{
if
(
servletPath
!=
null
)
{
request
.
setServletPath
(
servletPath
);
request
.
setServletPath
(
servletPath
);
}
}
request
.
setPathInfo
(
path
);
return
request
;
return
request
;
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/MvcEndpointRequestIntegrationTests.java
View file @
d4cad5e9
...
@@ -57,6 +57,18 @@ import org.springframework.web.cors.CorsConfiguration;
...
@@ -57,6 +57,18 @@ import org.springframework.web.cors.CorsConfiguration;
public
class
MvcEndpointRequestIntegrationTests
public
class
MvcEndpointRequestIntegrationTests
extends
AbstractEndpointRequestIntegrationTests
{
extends
AbstractEndpointRequestIntegrationTests
{
@Test
public
void
toLinksWhenServletPathSetShouldMatch
()
{
getContextRunner
().
withPropertyValues
(
"server.servlet.path=/admin"
)
.
run
((
context
)
->
{
WebTestClient
webTestClient
=
getWebTestClient
(
context
);
webTestClient
.
get
().
uri
(
"/admin/actuator/"
).
exchange
().
expectStatus
()
.
isOk
();
webTestClient
.
get
().
uri
(
"/admin/actuator"
).
exchange
().
expectStatus
()
.
isOk
();
});
}
@Test
@Test
public
void
toEndpointWhenServletPathSetShouldMatch
()
{
public
void
toEndpointWhenServletPathSetShouldMatch
()
{
getContextRunner
().
withPropertyValues
(
"server.servlet.path=/admin"
)
getContextRunner
().
withPropertyValues
(
"server.servlet.path=/admin"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment