mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 14:31:02 +00:00 
			
		
		
		
	chore: add integration test
Verify that PUT/DELETE requests return invalid CSRF token when no CSRF token is given with the request.
This commit is contained in:
		
					parent
					
						
							
								4dfb3facb4
							
						
					
				
			
			
				commit
				
					
						5fdd6ce9a6
					
				
			
		
					 1 changed files with 21 additions and 0 deletions
				
			
		|  | @ -1,4 +1,5 @@ | ||||||
| // Copyright 2017 The Gitea Authors. All rights reserved. | // Copyright 2017 The Gitea Authors. All rights reserved. | ||||||
|  | // Copyright 2025 The Forgejo Authors. All rights reserved. | ||||||
| // SPDX-License-Identifier: MIT | // SPDX-License-Identifier: MIT | ||||||
| 
 | 
 | ||||||
| package integration | package integration | ||||||
|  | @ -32,3 +33,23 @@ func TestCsrfProtection(t *testing.T) { | ||||||
| 	resp = session.MakeRequest(t, req, http.StatusBadRequest) | 	resp = session.MakeRequest(t, req, http.StatusBadRequest) | ||||||
| 	assert.Contains(t, resp.Body.String(), "Invalid CSRF token") | 	assert.Contains(t, resp.Body.String(), "Invalid CSRF token") | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func TestCSRFSafeMethods(t *testing.T) { | ||||||
|  | 	defer tests.PrepareTestEnv(t)() | ||||||
|  | 
 | ||||||
|  | 	t.Run("DELETE", func(t *testing.T) { | ||||||
|  | 		defer tests.PrintCurrentTest(t)() | ||||||
|  | 
 | ||||||
|  | 		session := loginUser(t, "user2") | ||||||
|  | 		resp := session.MakeRequest(t, NewRequest(t, "DELETE", "/user2/repo1/projects/1/2"), http.StatusBadRequest) | ||||||
|  | 		assert.Equal(t, "Invalid CSRF token.\n", resp.Body.String()) | ||||||
|  | 	}) | ||||||
|  | 
 | ||||||
|  | 	t.Run("PUT", func(t *testing.T) { | ||||||
|  | 		defer tests.PrintCurrentTest(t)() | ||||||
|  | 
 | ||||||
|  | 		session := loginUser(t, "user2") | ||||||
|  | 		resp := session.MakeRequest(t, NewRequest(t, "PUT", "/user2/repo1/projects/1/2"), http.StatusBadRequest) | ||||||
|  | 		assert.Equal(t, "Invalid CSRF token.\n", resp.Body.String()) | ||||||
|  | 	}) | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue