mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-02 09:17:55 -04:00
41 lines
994 B
Go
41 lines
994 B
Go
|
package conf_test
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"testing"
|
||
|
|
||
|
"v2ray.com/core/proxy/shadowsocks"
|
||
|
"v2ray.com/core/testing/assert"
|
||
|
. "v2ray.com/core/tools/conf"
|
||
|
)
|
||
|
|
||
|
func TestShadowsocksServerConfigParsing(t *testing.T) {
|
||
|
assert := assert.On(t)
|
||
|
|
||
|
rawJson := `{
|
||
|
"method": "aes-128-cfb",
|
||
|
"password": "v2ray-password"
|
||
|
}`
|
||
|
|
||
|
rawConfig := new(ShadowsocksServerConfig)
|
||
|
err := json.Unmarshal([]byte(rawJson), rawConfig)
|
||
|
assert.Error(err).IsNil()
|
||
|
|
||
|
ts, err := rawConfig.Build()
|
||
|
assert.Error(err).IsNil()
|
||
|
iConfig, err := ts.GetInstance()
|
||
|
assert.Error(err).IsNil()
|
||
|
config := iConfig.(*shadowsocks.ServerConfig)
|
||
|
|
||
|
rawAccount, err := config.User.GetTypedAccount()
|
||
|
assert.Error(err).IsNil()
|
||
|
|
||
|
account, ok := rawAccount.(*shadowsocks.Account)
|
||
|
assert.Bool(ok).IsTrue()
|
||
|
|
||
|
cipher, err := account.GetCipher()
|
||
|
assert.Error(err).IsNil()
|
||
|
assert.Int(cipher.KeySize()).Equals(16)
|
||
|
assert.Bytes(account.GetCipherKey()).Equals([]byte{160, 224, 26, 2, 22, 110, 9, 80, 65, 52, 80, 20, 38, 243, 224, 241})
|
||
|
}
|