mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-27 12:00:07 +00:00
https://github.com/XTLS/Xray-core/pull/7238#issuecomment-6467092152 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6484050347 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6484439860 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6621021705 https://github.com/XTLS/Xray-core/pull/7329#issuecomment-6623818990 https://github.com/XTLS/Xray-core/pull/7329#issuecomment-6624149740 https://github.com/XTLS/Xray-core/pull/7329#issuecomment-6625219097 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6627156942 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6850640864 https://github.com/XTLS/Xray-core/pull/7281#issuecomment-6973501579 --------- Co-authored-by: Codex <codex@openai.com>
75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package conf_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/xtls/xray-core/common/log"
|
|
. "github.com/xtls/xray-core/infra/conf"
|
|
"github.com/xtls/xray-core/proxy/freedom"
|
|
)
|
|
|
|
func TestHTTPResponseJSON(t *testing.T) {
|
|
creator := func() Buildable {
|
|
return new(BlackholeConfig)
|
|
}
|
|
|
|
runMultiTestCase(t, []TestCase{
|
|
{
|
|
Input: `{
|
|
"response": {
|
|
"type": "http"
|
|
}
|
|
}`,
|
|
Parser: loadJSON(creator),
|
|
Output: &freedom.Config{
|
|
Firewall: []*freedom.FirewallConfig{{
|
|
Action: freedom.RuleAction_Block,
|
|
Delay: &freedom.Range{},
|
|
LogLevel: log.Severity_Unknown.Enum(),
|
|
Reply: &freedom.Reply{Type: "http"},
|
|
}},
|
|
},
|
|
},
|
|
{
|
|
Input: `{}`,
|
|
Parser: loadJSON(creator),
|
|
Output: &freedom.Config{
|
|
Firewall: []*freedom.FirewallConfig{{
|
|
Action: freedom.RuleAction_Block,
|
|
Delay: &freedom.Range{},
|
|
LogLevel: log.Severity_Unknown.Enum(),
|
|
}},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestCustomResponseJSON(t *testing.T) {
|
|
creator := func() Buildable {
|
|
return new(BlackholeConfig)
|
|
}
|
|
|
|
runMultiTestCase(t, []TestCase{
|
|
{
|
|
Input: `{
|
|
"response": {
|
|
"type": "custom",
|
|
"customResponseData": "Y3VzdG9tIHJlc3BvbnNl"
|
|
}
|
|
}`,
|
|
Parser: loadJSON(creator),
|
|
Output: &freedom.Config{
|
|
Firewall: []*freedom.FirewallConfig{{
|
|
Action: freedom.RuleAction_Block,
|
|
Delay: &freedom.Range{},
|
|
LogLevel: log.Severity_Unknown.Enum(),
|
|
Reply: &freedom.Reply{
|
|
Type: "custom",
|
|
CustomResponseData: []byte("custom response"),
|
|
},
|
|
}},
|
|
},
|
|
},
|
|
})
|
|
}
|