Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions infra/conf/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
}

func buildShadowsocks2022(v *ShadowsocksServerConfig) (proto.Message, error) {
if len(v.Users) == 0 {
if v.Users == nil {
config := new(shadowsocks_2022.ServerConfig)
config.Method = v.Cipher
config.Key = v.Password
Expand All @@ -115,7 +115,7 @@ func buildShadowsocks2022(v *ShadowsocksServerConfig) (proto.Message, error) {
return nil, errors.New("shadowsocks 2022 (multi-user): only blake3-aes-*-gcm methods are supported")
}

if v.Users[0].Address == nil {
if len(v.Users) == 0 || v.Users[0].Address == nil {
config := new(shadowsocks_2022.MultiUserServerConfig)
config.Method = v.Cipher
config.Key = v.Password
Expand Down
37 changes: 37 additions & 0 deletions infra/conf/shadowsocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/xtls/xray-core/common/serial"
. "github.com/xtls/xray-core/infra/conf"
"github.com/xtls/xray-core/proxy/shadowsocks"
"github.com/xtls/xray-core/proxy/shadowsocks_2022"
)

func TestShadowsocksServerConfigParsing(t *testing.T) {
Expand All @@ -34,3 +35,39 @@ func TestShadowsocksServerConfigParsing(t *testing.T) {
},
})
}

func TestShadowsocks2022ServerConfigParsing(t *testing.T) {
creator := func() Buildable {
return new(ShadowsocksServerConfig)
}

runMultiTestCase(t, []TestCase{
{
// No clients field: should produce single-user ServerConfig
Input: `{
"method": "2022-blake3-aes-128-gcm",
"password": "aGVsbG93b3JsZDEyMzQ1Ng=="
}`,
Parser: loadJSON(creator),
Output: &shadowsocks_2022.ServerConfig{
Method: "2022-blake3-aes-128-gcm",
Key: "aGVsbG93b3JsZDEyMzQ1Ng==",
Network: []net.Network{net.Network_TCP},
},
},
{
// Empty clients array: should produce multi-user MultiUserServerConfig
Input: `{
"method": "2022-blake3-aes-128-gcm",
"password": "aGVsbG93b3JsZDEyMzQ1Ng==",
"clients": []
}`,
Parser: loadJSON(creator),
Output: &shadowsocks_2022.MultiUserServerConfig{
Method: "2022-blake3-aes-128-gcm",
Key: "aGVsbG93b3JsZDEyMzQ1Ng==",
Network: []net.Network{net.Network_TCP},
},
},
})
}