2020-11-25 19:01:53 +08:00
|
|
|
package conf_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-05-02 09:54:34 +08:00
|
|
|
"github.com/xtls/xray-core/common/geodata"
|
2020-12-04 09:36:16 +08:00
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
|
"github.com/xtls/xray-core/common/protocol"
|
|
|
|
|
. "github.com/xtls/xray-core/infra/conf"
|
|
|
|
|
"github.com/xtls/xray-core/proxy/freedom"
|
2025-08-19 16:03:12 +02:00
|
|
|
"github.com/xtls/xray-core/transport/internet"
|
2020-11-25 19:01:53 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestFreedomConfig(t *testing.T) {
|
|
|
|
|
creator := func() Buildable {
|
|
|
|
|
return new(FreedomConfig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runMultiTestCase(t, []TestCase{
|
|
|
|
|
{
|
|
|
|
|
Input: `{
|
|
|
|
|
"domainStrategy": "AsIs",
|
|
|
|
|
"redirect": "127.0.0.1:3366",
|
|
|
|
|
"userLevel": 1
|
|
|
|
|
}`,
|
|
|
|
|
Parser: loadJSON(creator),
|
|
|
|
|
Output: &freedom.Config{
|
2025-08-19 16:03:12 +02:00
|
|
|
DomainStrategy: internet.DomainStrategy_AS_IS,
|
2020-11-25 19:01:53 +08:00
|
|
|
DestinationOverride: &freedom.DestinationOverride{
|
|
|
|
|
Server: &protocol.ServerEndpoint{
|
|
|
|
|
Address: &net.IPOrDomain{
|
|
|
|
|
Address: &net.IPOrDomain_Ip{
|
|
|
|
|
Ip: []byte{127, 0, 0, 1},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Port: 3366,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
UserLevel: 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-05-02 09:54:34 +08:00
|
|
|
{
|
|
|
|
|
Input: `{
|
|
|
|
|
"finalRules": [{
|
|
|
|
|
"action": "block",
|
|
|
|
|
"network": "tcp,udp",
|
|
|
|
|
"port": "53,443",
|
2026-05-03 04:40:46 +08:00
|
|
|
"ip": ["10.0.0.0/8", "2001:db8::/32"],
|
|
|
|
|
"blockDelay": "30-60"
|
2026-05-02 09:54:34 +08:00
|
|
|
}, {
|
|
|
|
|
"action": "allow",
|
|
|
|
|
"network": ["udp"]
|
|
|
|
|
}]
|
|
|
|
|
}`,
|
|
|
|
|
Parser: loadJSON(creator),
|
|
|
|
|
Output: &freedom.Config{
|
|
|
|
|
FinalRules: []*freedom.FinalRuleConfig{
|
|
|
|
|
{
|
|
|
|
|
Action: freedom.RuleAction_Block,
|
|
|
|
|
Networks: []net.Network{net.Network_TCP, net.Network_UDP},
|
|
|
|
|
PortList: &net.PortList{
|
|
|
|
|
Range: []*net.PortRange{
|
|
|
|
|
{From: 53, To: 53},
|
|
|
|
|
{From: 443, To: 443},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Ip: []*geodata.IPRule{
|
|
|
|
|
{
|
|
|
|
|
Value: &geodata.IPRule_Custom{
|
|
|
|
|
Custom: &geodata.CIDRRule{
|
|
|
|
|
Cidr: &geodata.CIDR{
|
|
|
|
|
Ip: []byte{10, 0, 0, 0},
|
|
|
|
|
Prefix: 8,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Value: &geodata.IPRule_Custom{
|
|
|
|
|
Custom: &geodata.CIDRRule{
|
|
|
|
|
Cidr: &geodata.CIDR{
|
|
|
|
|
Ip: net.ParseAddress("2001:db8::").IP(),
|
|
|
|
|
Prefix: 32,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-05-03 04:40:46 +08:00
|
|
|
BlockDelay: &freedom.Range{
|
|
|
|
|
Min: 30,
|
|
|
|
|
Max: 60,
|
|
|
|
|
},
|
2026-05-02 09:54:34 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Action: freedom.RuleAction_Allow,
|
|
|
|
|
Networks: []net.Network{net.Network_UDP},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2020-11-25 19:01:53 +08:00
|
|
|
})
|
|
|
|
|
}
|