2020-11-25 19:01:53 +08:00
|
|
|
package conf_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2020-12-04 09:36:16 +08:00
|
|
|
. "github.com/xtls/xray-core/infra/conf"
|
|
|
|
|
"github.com/xtls/xray-core/proxy/blackhole"
|
2020-11-25 19:01:53 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestHTTPResponseJSON(t *testing.T) {
|
|
|
|
|
creator := func() Buildable {
|
|
|
|
|
return new(BlackholeConfig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runMultiTestCase(t, []TestCase{
|
|
|
|
|
{
|
|
|
|
|
Input: `{
|
|
|
|
|
"response": {
|
|
|
|
|
"type": "http"
|
|
|
|
|
}
|
|
|
|
|
}`,
|
|
|
|
|
Parser: loadJSON(creator),
|
|
|
|
|
Output: &blackhole.Config{
|
2026-09-08 05:09:58 +08:00
|
|
|
Response: &blackhole.Response{Type: "http"},
|
2020-11-25 19:01:53 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Input: `{}`,
|
|
|
|
|
Parser: loadJSON(creator),
|
|
|
|
|
Output: &blackhole.Config{},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-09-08 05:09:58 +08:00
|
|
|
|
|
|
|
|
func TestCustomResponseJSON(t *testing.T) {
|
|
|
|
|
creator := func() Buildable {
|
|
|
|
|
return new(BlackholeConfig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runMultiTestCase(t, []TestCase{
|
|
|
|
|
{
|
|
|
|
|
Input: `{
|
|
|
|
|
"response": {
|
|
|
|
|
"type": "custom",
|
|
|
|
|
"customResponseData": "Y3VzdG9tIHJlc3BvbnNl"
|
|
|
|
|
}
|
|
|
|
|
}`,
|
|
|
|
|
Parser: loadJSON(creator),
|
|
|
|
|
Output: &blackhole.Config{
|
|
|
|
|
Response: &blackhole.Response{
|
|
|
|
|
Type: "custom",
|
|
|
|
|
CustomResponseData: []byte("custom response"),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|