mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	Fix #33966 ``` ;; User must sign in to view anything. ;; It could be set to "expensive" to block anonymous users accessing some pages which consume a lot of resources, ;; for example: block anonymous AI crawlers from accessing repo code pages. ;; The "expensive" mode is experimental and subject to change. ;REQUIRE_SIGNIN_VIEW = false ```
		
			
				
	
	
		
			31 lines
		
	
	
		
			738 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			738 B
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2025 The Gitea Authors. All rights reserved.
 | 
						|
// SPDX-License-Identifier: MIT
 | 
						|
 | 
						|
package common
 | 
						|
 | 
						|
import (
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"github.com/stretchr/testify/assert"
 | 
						|
)
 | 
						|
 | 
						|
func TestBlockExpensive(t *testing.T) {
 | 
						|
	cases := []struct {
 | 
						|
		expensive bool
 | 
						|
		routePath string
 | 
						|
	}{
 | 
						|
		{false, "/user/xxx"},
 | 
						|
		{false, "/login/xxx"},
 | 
						|
		{true, "/{username}/{reponame}/archive/xxx"},
 | 
						|
		{true, "/{username}/{reponame}/graph"},
 | 
						|
		{true, "/{username}/{reponame}/src/xxx"},
 | 
						|
		{true, "/{username}/{reponame}/wiki/xxx"},
 | 
						|
		{true, "/{username}/{reponame}/activity/xxx"},
 | 
						|
	}
 | 
						|
	for _, c := range cases {
 | 
						|
		assert.Equal(t, c.expensive, isRoutePathExpensive(c.routePath), "routePath: %s", c.routePath)
 | 
						|
	}
 | 
						|
 | 
						|
	assert.True(t, isRoutePathForLongPolling("/user/events"))
 | 
						|
}
 |