cql-proxy icon indicating copy to clipboard operation
cql-proxy copied to clipboard

Remove quotes from keyspace names before sending them back in set_keyspace result messages

Open absurdfarce opened this issue 1 year ago • 3 comments

As discussed in #128

absurdfarce avatar Jun 25 '24 05:06 absurdfarce

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)
		})
	}
}

lukasz-antoniak avatar Jun 25 '24 07:06 lukasz-antoniak

Excellent idea @lukasz-antoniak! I'll add a test in there forthwith!

absurdfarce avatar Jun 25 '24 16:06 absurdfarce

What's wrong with the original patch? https://github.com/datastax/cql-proxy/pull/127. It handles double quoting in the identifier.

mpenick avatar Jul 02 '24 14:07 mpenick

👍 Looks good... thanks for getting this over the finish line @lukasz-antoniak !

absurdfarce avatar Jul 30 '24 16:07 absurdfarce