config_json_test.go 732 B

12345678910111213141516171819202122232425262728293031323334
  1. // +build json
  2. package shadowsocks
  3. import (
  4. "encoding/json"
  5. "testing"
  6. "v2ray.com/core/testing/assert"
  7. )
  8. func TestConfigParsing(t *testing.T) {
  9. assert := assert.On(t)
  10. rawJson := `{
  11. "method": "aes-128-cfb",
  12. "password": "v2ray-password"
  13. }`
  14. config := new(ServerConfig)
  15. err := json.Unmarshal([]byte(rawJson), config)
  16. assert.Error(err).IsNil()
  17. rawAccount, err = config.User.GetTypedAccount()
  18. assert.Error(err).IsNil()
  19. account, ok := rawAccount.(*Account)
  20. assert.Bool(ok).IsTrue()
  21. cipher, err := account.GetCipher()
  22. assert.Error(err).IsNil()
  23. assert.Int(cipher.KeySize()).Equals(16)
  24. assert.Bytes(account.GetCipherKey()).Equals([]byte{160, 224, 26, 2, 22, 110, 9, 80, 65, 52, 80, 20, 38, 243, 224, 241})
  25. }