Move "Testing With Spring Security" How-to

See gh-26262
This commit is contained in:
Phillip Webb 2021-05-18 11:14:26 -07:00
parent 5f7e3d3952
commit 72d50ed2f8
6 changed files with 16 additions and 9 deletions

View File

@ -2527,7 +2527,7 @@ howto.spring-mvc.customize-view-resolvers
# 2 == Testing With Spring Security # 2 == Testing With Spring Security
howto-use-test-with-spring-security=\ howto-use-test-with-spring-security=\
howto.testing-with-spring-security howto.spring-mvc.testing.with-spring-security
# 2 == Jersey # 2 == Jersey
howto-jersey=\ howto-jersey=\

View File

@ -404,7 +404,7 @@ If you define your own `webDriver` scope you may find it stops working when you
If you have Spring Security on the classpath, `@WebMvcTest` will also scan `WebSecurityConfigurer` beans. 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. 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#howto.testing-with-spring-security>>_ how-to section. More details on how to use Spring Security's `MockMvc` support can be found in this _<<howto#howto.testing.with-spring-security>>_ how-to section.
TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you run <<features#features.testing.spring-boot-applications.with-running-server, full end-to-end tests with an actual server>>. TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you run <<features#features.testing.spring-boot-applications.with-running-server, full end-to-end tests with an actual server>>.

View File

@ -23,8 +23,6 @@ include::howto/webserver.adoc[]
include::howto/spring-mvc.adoc[] include::howto/spring-mvc.adoc[]
include::howto/testing-with-spring-security.adoc[]
include::howto/jersey.adoc[] include::howto/jersey.adoc[]
include::howto/http-clients.adoc[] include::howto/http-clients.adoc[]
@ -45,6 +43,8 @@ include::howto/security.adoc[]
include::howto/hotswapping.adoc[] include::howto/hotswapping.adoc[]
include::howto/testing.adoc[]
include::howto/build.adoc[] include::howto/build.adoc[]
include::howto/traditional-deployment.adoc[] include::howto/traditional-deployment.adoc[]

View File

@ -1,11 +1,18 @@
[[howto.testing-with-spring-security]] [[howto.testing]]
== Testing With Spring Security == Testing
Spring Boot includes a number of testing utilities and support classes as well as a dedicated starter that provides common test dependencies.
This section answers common questions about testing.
[[howto.testing.with-spring-security]]
=== Testing With Spring Security
Spring Security provides support for running tests as a specific user. 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. For example, the test in the snippet below will run with an authenticated user that has the `ADMIN` role.
[source,java,indent=0,subs="verbatim"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/testingwithspringsecurity/MySecurityTests.java[] include::{docs-java}/howto/testing/withspringsecurity/MySecurityTests.java[]
---- ----
Spring Security provides comprehensive integration with Spring MVC Test and this can also be used when testing controllers using the `@WebMvcTest` slice and `MockMvc`. Spring Security provides comprehensive integration with Spring MVC Test and this can also be used when testing controllers using the `@WebMvcTest` slice and `MockMvc`.

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.docs.howto.testingwithspringsecurity; package org.springframework.boot.docs.howto.testing.withspringsecurity;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.docs.howto.testingwithspringsecurity; package org.springframework.boot.docs.howto.testing.withspringsecurity;
class UserController { class UserController {