Handle hex strings and quoted strings in HTTP params

Use 0x-prefixed hex strings in client

server: Decode hex string args

Encode all string args as 0x<hex> without trying to encode as JSON

Added tests for special string arguments

Fix server handling quoted string args

Added string arg handling test cases to bash test script
This commit is contained in:
Matt Bell
2017-01-02 09:50:20 -08:00
parent 161e36fd56
commit 34a806578a
4 changed files with 111 additions and 10 deletions

View File

@ -164,3 +164,39 @@ func TestWS_UNIX(t *testing.T) {
}
testWS(t, cl)
}
func TestHexStringArg(t *testing.T) {
cl := rpcclient.NewClientURI(tcpAddr)
// should NOT be handled as hex
val := "0xabc"
params := map[string]interface{}{
"arg": val,
}
var result Result
_, err := cl.Call("status", params, &result)
if err != nil {
t.Fatal(err)
}
got := result.(*ResultStatus).Value
if got != val {
t.Fatalf("Got: %v .... Expected: %v \n", got, val)
}
}
func TestQuotedStringArg(t *testing.T) {
cl := rpcclient.NewClientURI(tcpAddr)
// should NOT be unquoted
val := "\"abc\""
params := map[string]interface{}{
"arg": val,
}
var result Result
_, err := cl.Call("status", params, &result)
if err != nil {
t.Fatal(err)
}
got := result.(*ResultStatus).Value
if got != val {
t.Fatalf("Got: %v .... Expected: %v \n", got, val)
}
}