mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-28 13:36:38 +08:00
防盗链功能增加禁止的来源域名
This commit is contained in:
48
pkg/serverconfigs/referers_config_test.go
Normal file
48
pkg/serverconfigs/referers_config_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package serverconfigs_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReferersConfig_MatchDomain(t *testing.T) {
|
||||
var a = assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
var config = &serverconfigs.ReferersConfig{
|
||||
IsOn: true,
|
||||
AllowDomains: []string{},
|
||||
DenyDomains: []string{"a.com", "b.com"},
|
||||
}
|
||||
a.IsTrue(config.MatchDomain("example.com", "c.com"))
|
||||
a.IsTrue(config.MatchDomain("example.com", "d.com"))
|
||||
a.IsFalse(config.MatchDomain("example.com", "a.com"))
|
||||
}
|
||||
|
||||
{
|
||||
var config = &serverconfigs.ReferersConfig{
|
||||
IsOn: true,
|
||||
AllowDomains: []string{"c.com", "e.com"},
|
||||
DenyDomains: []string{"a.com", "b.com", "e.com"},
|
||||
}
|
||||
a.IsTrue(config.MatchDomain("example.com", "c.com"))
|
||||
a.IsFalse(config.MatchDomain("example.com", "d.com"))
|
||||
a.IsFalse(config.MatchDomain("example.com", "e.com"))
|
||||
a.IsFalse(config.MatchDomain("example.com", "a.com"))
|
||||
}
|
||||
|
||||
{
|
||||
var config = &serverconfigs.ReferersConfig{
|
||||
IsOn: true,
|
||||
AllowDomains: []string{"c.com", "e.com"},
|
||||
DenyDomains: []string{},
|
||||
}
|
||||
a.IsTrue(config.MatchDomain("example.com", "c.com"))
|
||||
a.IsFalse(config.MatchDomain("example.com", "d.com"))
|
||||
a.IsTrue(config.MatchDomain("example.com", "e.com"))
|
||||
a.IsFalse(config.MatchDomain("example.com", "a.com"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user