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
f3dbd946
Commit
f3dbd946
authored
Aug 31, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document how to test secure mockmvc tests
See gh-14227
parent
8b753297
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
howto.adoc
...oot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
+25
-0
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+5
-0
No files found.
spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
View file @
f3dbd946
...
@@ -1417,6 +1417,31 @@ For more detail, see the following sections:
...
@@ -1417,6 +1417,31 @@ For more detail, see the following sections:
[[howto-use-test-with-spring-security]]
== Testing With Spring Security
Spring Security provides support for running tests as a specific user.
For example, the test in the snippet below will run with an authenticated user
that has the `ADMIN` role.
[source,java,indent=0]
----
@Test
@WithMockUser(roles="ADMIN")
public void requestProtectedUrlWithUser() throws Exception {
mvc
.perform(get("/"))
...
}
----
Spring Security provides comprehensive integration with Spring MVC Test and
this can also be used when testing controllers using the `@WebMvcTest` slice and `MockMvc`.
For additional details on Spring Security's testing support, refer to Spring Security's
https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#test[reference documentation]).
[[howto-jersey]]
[[howto-jersey]]
== Jersey
== Jersey
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
f3dbd946
...
@@ -6886,6 +6886,11 @@ that the driver exits after each test and that a new instance is injected. If yo
...
@@ -6886,6 +6886,11 @@ that the driver exits after each test and that a new instance is injected. If yo
not want this behavior, you can add `@Scope("singleton")` to your `WebDriver` `@Bean`
not want this behavior, you can add `@Scope("singleton")` to your `WebDriver` `@Bean`
definition.
definition.
If you have Spring Security on the classpath, `@WebMvcTest` will also scan `WebSecurityConfigurer`
beans. Instead of disabling security completely for such tests, you can use Spring Security's test support.
More details on how to use Spring Security's `MockMvc` support can be found in
this _<<howto.adoc#howto-use-test-with-spring-security>>_ how-to section.
TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you run
TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you run
<<boot-features-testing-spring-boot-applications-testing-with-running-server,
<<boot-features-testing-spring-boot-applications-testing-with-running-server,
full end-to-end tests with an actual server>>.
full end-to-end tests with an actual server>>.
...
...
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