mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-11-04 08:39:05 +00:00 
			
		
		
		
	
		
			
	
	
		
			29 lines
		
	
	
		
			418 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
		
		
			
		
	
	
			29 lines
		
	
	
		
			418 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| 
								 | 
							
								= Testing with CSRF
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								Spring Security also provides support for CSRF testing with `WebTestClient`.
							 | 
						||
| 
								 | 
							
								For example:
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								====
							 | 
						||
| 
								 | 
							
								.Java
							 | 
						||
| 
								 | 
							
								[source,java,role="primary"]
							 | 
						||
| 
								 | 
							
								----
							 | 
						||
| 
								 | 
							
								this.rest
							 | 
						||
| 
								 | 
							
									// provide a valid CSRF token
							 | 
						||
| 
								 | 
							
									.mutateWith(csrf())
							 | 
						||
| 
								 | 
							
									.post()
							 | 
						||
| 
								 | 
							
									.uri("/login")
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								----
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								.Kotlin
							 | 
						||
| 
								 | 
							
								[source,kotlin,role="secondary"]
							 | 
						||
| 
								 | 
							
								----
							 | 
						||
| 
								 | 
							
								this.rest
							 | 
						||
| 
								 | 
							
								    // provide a valid CSRF token
							 | 
						||
| 
								 | 
							
								    .mutateWith(csrf())
							 | 
						||
| 
								 | 
							
								    .post()
							 | 
						||
| 
								 | 
							
								    .uri("/login")
							 | 
						||
| 
								 | 
							
								    ...
							 | 
						||
| 
								 | 
							
								----
							 | 
						||
| 
								 | 
							
								====
							 |