mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 03:18:24 +00:00 
			
		
		
		
	Backport #29642 by wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		
							
								
								
									
										39
									
								
								services/context/base_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								services/context/base_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| // Copyright 2024 The Gitea Authors. All rights reserved. | ||||
| // SPDX-License-Identifier: MIT | ||||
|  | ||||
| package context | ||||
|  | ||||
| import ( | ||||
| 	"net/http" | ||||
| 	"net/http/httptest" | ||||
| 	"testing" | ||||
|  | ||||
| 	"code.gitea.io/gitea/modules/context" | ||||
| 	"code.gitea.io/gitea/modules/setting" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func TestRedirect(t *testing.T) { | ||||
| 	req, _ := http.NewRequest("GET", "/", nil) | ||||
|  | ||||
| 	cases := []struct { | ||||
| 		url  string | ||||
| 		keep bool | ||||
| 	}{ | ||||
| 		{"http://test", false}, | ||||
| 		{"https://test", false}, | ||||
| 		{"//test", false}, | ||||
| 		{"/://test", true}, | ||||
| 		{"/test", true}, | ||||
| 	} | ||||
| 	for _, c := range cases { | ||||
| 		resp := httptest.NewRecorder() | ||||
| 		b, cleanup := context.NewBaseContext(resp, req) | ||||
| 		resp.Header().Add("Set-Cookie", (&http.Cookie{Name: setting.SessionConfig.CookieName, Value: "dummy"}).String()) | ||||
| 		b.Redirect(c.url) | ||||
| 		cleanup() | ||||
| 		has := resp.Header().Get("Set-Cookie") == "i_like_gitea=dummy" | ||||
| 		assert.Equal(t, c.keep, has, "url = %q", c.url) | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user