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
e6149fda
Commit
e6149fda
authored
Mar 15, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assert endpoints basePath starts with '/' or is empty
Fixes gh-12489
parent
b8e86473
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
WebEndpointProperties.java
...ate/autoconfigure/endpoint/web/WebEndpointProperties.java
+3
-0
WebEndpointPropertiesTests.java
...utoconfigure/endpoint/web/WebEndpointPropertiesTests.java
+22
-0
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java
View file @
e6149fda
...
...
@@ -22,6 +22,7 @@ import java.util.Map;
import
java.util.Set
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
/**
...
...
@@ -56,6 +57,8 @@ public class WebEndpointProperties {
}
public
void
setBasePath
(
String
basePath
)
{
Assert
.
isTrue
(
basePath
.
isEmpty
()
||
basePath
.
startsWith
(
"/"
),
"Base path must start with '/' or be empty"
);
this
.
basePath
=
cleanBasePath
(
basePath
);
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointPropertiesTests.java
View file @
e6149fda
...
...
@@ -16,7 +16,9 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
endpoint
.
web
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -27,6 +29,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public
class
WebEndpointPropertiesTests
{
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
@Test
public
void
defaultBasePathShouldBeApplication
()
{
WebEndpointProperties
properties
=
new
WebEndpointProperties
();
...
...
@@ -38,6 +43,23 @@ public class WebEndpointPropertiesTests {
WebEndpointProperties
properties
=
new
WebEndpointProperties
();
properties
.
setBasePath
(
"/"
);
assertThat
(
properties
.
getBasePath
()).
isEqualTo
(
""
);
properties
.
setBasePath
(
"/actuator/"
);
assertThat
(
properties
.
getBasePath
()).
isEqualTo
(
"/actuator"
);
}
@Test
public
void
basePathMustStartWithSlash
()
{
WebEndpointProperties
properties
=
new
WebEndpointProperties
();
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
this
.
thrown
.
expectMessage
(
"Base path must start with '/' or be empty"
);
properties
.
setBasePath
(
"admin"
);
}
@Test
public
void
basePathCanBeEmpty
()
{
WebEndpointProperties
properties
=
new
WebEndpointProperties
();
properties
.
setBasePath
(
""
);
assertThat
(
properties
.
getBasePath
()).
isEqualTo
(
""
);
}
}
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