mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-26 20:28:44 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			35 lines
		
	
	
		
			639 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			639 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| = Testing with CSRF
 | |
| 
 | |
| Spring Security also provides support for CSRF testing with `WebTestClient` -- for example:
 | |
| 
 | |
| [tabs]
 | |
| ======
 | |
| Java::
 | |
| +
 | |
| [source,java,role="primary"]
 | |
| ----
 | |
| import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf;
 | |
| 
 | |
| this.rest
 | |
| 	// provide a valid CSRF token
 | |
| 	.mutateWith(csrf())
 | |
| 	.post()
 | |
| 	.uri("/login")
 | |
| 	...
 | |
| ----
 | |
| 
 | |
| Kotlin::
 | |
| +
 | |
| [source,kotlin,role="secondary"]
 | |
| ----
 | |
| import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf
 | |
| 
 | |
| this.rest
 | |
|     // provide a valid CSRF token
 | |
|     .mutateWith(csrf())
 | |
|     .post()
 | |
|     .uri("/login")
 | |
|     ...
 | |
| ----
 | |
| ======
 |