cql-proxy
cql-proxy copied to clipboard
Remove quotes from keyspace names before sending them back in set_keyspace result messages
As discussed in #128
Maybe also change below test accordingly to test USE statement with quoted keyspace:
func TestProxy_UseKeyspace(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
tester, proxyContactPoint, err := setupProxyTest(ctx, 1, nil)
defer func() {
cancel()
tester.shutdown()
}()
require.NoError(t, err)
cl := connectTestClient(t, ctx, proxyContactPoint)
tests := []struct {
name string
keyspaceRequested string
keyspaceExpected string
}{
{"UnquotedKeyspace", "system", "system"},
{"QuotedKeyspace", "\"system\"", "system"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
resp, err := cl.SendAndReceive(ctx, frame.NewFrame(primitive.ProtocolVersion4, 0, &message.Query{Query: "USE " + test.keyspaceRequested}))
require.NoError(t, err)
assert.Equal(t, primitive.OpCodeResult, resp.Header.OpCode)
res, ok := resp.Body.Message.(*message.SetKeyspaceResult)
require.True(t, ok, "expected set keyspace result")
assert.Equal(t, test.keyspaceExpected, res.Keyspace)
})
}
}
Excellent idea @lukasz-antoniak! I'll add a test in there forthwith!
What's wrong with the original patch? https://github.com/datastax/cql-proxy/pull/127. It handles double quoting in the identifier.
👍 Looks good... thanks for getting this over the finish line @lukasz-antoniak !