mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 22:41:03 +00:00 
			
		
		
		
	- Massive replacement of changing `code.gitea.io/gitea` to `forgejo.org`. - Resolves forgejo/discussions#258 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7337 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Beowulf <beowulf@beocode.eu> Reviewed-by: Panagiotis "Ivory" Vasilopoulos <git@n0toose.net> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
		
			
				
	
	
		
			115 lines
		
	
	
	
		
			3.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			115 lines
		
	
	
	
		
			3.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2020 The Gitea Authors. All rights reserved.
 | |
| // Copyright 2025 The Forgejo Authors. All rights reserved
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package setting
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 
 | |
| 	"forgejo.org/modules/json"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| 	"github.com/stretchr/testify/require"
 | |
| )
 | |
| 
 | |
| func TestMakeAbsoluteAssetURL(t *testing.T) {
 | |
| 	assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL("https://localhost:1234", "https://localhost:2345"))
 | |
| 	assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL("https://localhost:1234/", "https://localhost:2345"))
 | |
| 	assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL("https://localhost:1234/", "https://localhost:2345/"))
 | |
| 	assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234", "/foo"))
 | |
| 	assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/", "/foo"))
 | |
| 	assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/", "/foo/"))
 | |
| 	assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/foo", "/foo"))
 | |
| 	assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/foo"))
 | |
| 	assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/foo/"))
 | |
| 	assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL("https://localhost:1234/foo", "/bar"))
 | |
| 	assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/bar"))
 | |
| 	assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/bar/"))
 | |
| }
 | |
| 
 | |
| func TestMakeManifestData(t *testing.T) {
 | |
| 	jsonBytes := MakeManifestData(`Example App '\"`, "https://example.com", "https://example.com/foo/bar")
 | |
| 	assert.True(t, json.Valid(jsonBytes))
 | |
| }
 | |
| 
 | |
| func TestLoadServiceDomainListsForFederation(t *testing.T) {
 | |
| 	oldAppURL := AppURL
 | |
| 	oldFederation := Federation
 | |
| 	oldService := Service
 | |
| 
 | |
| 	defer func() {
 | |
| 		AppURL = oldAppURL
 | |
| 		Federation = oldFederation
 | |
| 		Service = oldService
 | |
| 	}()
 | |
| 
 | |
| 	cfg, err := NewConfigProviderFromData(`
 | |
| [federation]
 | |
| ENABLED = true
 | |
| [service]
 | |
| EMAIL_DOMAIN_ALLOWLIST = *.allow.random
 | |
| EMAIL_DOMAIN_BLOCKLIST = *.block.random
 | |
| `)
 | |
| 
 | |
| 	require.NoError(t, err)
 | |
| 	loadServerFrom(cfg)
 | |
| 	loadFederationFrom(cfg)
 | |
| 	loadServiceFrom(cfg)
 | |
| 
 | |
| 	assert.True(t, match(Service.EmailDomainAllowList, "d1.allow.random"))
 | |
| 	assert.True(t, match(Service.EmailDomainAllowList, "localhost"))
 | |
| }
 | |
| 
 | |
| func TestLoadServiceDomainListsNoFederation(t *testing.T) {
 | |
| 	oldAppURL := AppURL
 | |
| 	oldFederation := Federation
 | |
| 	oldService := Service
 | |
| 
 | |
| 	defer func() {
 | |
| 		AppURL = oldAppURL
 | |
| 		Federation = oldFederation
 | |
| 		Service = oldService
 | |
| 	}()
 | |
| 
 | |
| 	cfg, err := NewConfigProviderFromData(`
 | |
| [federation]
 | |
| ENABLED = false
 | |
| [service]
 | |
| EMAIL_DOMAIN_ALLOWLIST = *.allow.random
 | |
| EMAIL_DOMAIN_BLOCKLIST = *.block.random
 | |
| `)
 | |
| 
 | |
| 	require.NoError(t, err)
 | |
| 	loadServerFrom(cfg)
 | |
| 	loadFederationFrom(cfg)
 | |
| 	loadServiceFrom(cfg)
 | |
| 
 | |
| 	assert.True(t, match(Service.EmailDomainAllowList, "d1.allow.random"))
 | |
| }
 | |
| 
 | |
| func TestLoadServiceDomainListsFederationEmptyAllowList(t *testing.T) {
 | |
| 	oldAppURL := AppURL
 | |
| 	oldFederation := Federation
 | |
| 	oldService := Service
 | |
| 
 | |
| 	defer func() {
 | |
| 		AppURL = oldAppURL
 | |
| 		Federation = oldFederation
 | |
| 		Service = oldService
 | |
| 	}()
 | |
| 
 | |
| 	cfg, err := NewConfigProviderFromData(`
 | |
| [federation]
 | |
| ENABLED = true
 | |
| [service]
 | |
| EMAIL_DOMAIN_BLOCKLIST = *.block.random
 | |
| `)
 | |
| 
 | |
| 	require.NoError(t, err)
 | |
| 	loadServerFrom(cfg)
 | |
| 	loadFederationFrom(cfg)
 | |
| 	loadServiceFrom(cfg)
 | |
| 
 | |
| 	assert.Empty(t, Service.EmailDomainAllowList)
 | |
| }
 |