Remove comments from the query before checking for restricted keywords

This commit is contained in:
Dan Sosedoff
2019-02-25 11:43:04 -06:00
parent b83f52707a
commit 2a0fd54855
2 changed files with 20 additions and 5 deletions

View File

@@ -440,16 +440,22 @@ func testReadOnlyMode(t *testing.T) {
err := client.SetReadOnlyMode()
assert.NoError(t, err)
_, err = client.Query("CREATE TABLE foobar(id integer);")
_, err = client.Query("\nCREATE TABLE foobar(id integer);\n")
assert.NotNil(t, err)
assert.Error(t, err, "query contains keywords not allowed in read-only mode")
// Turn off guard
client.db.Exec("SET default_transaction_read_only=off;")
_, err = client.Query("CREATE TABLE foobar(id integer);")
_, err = client.Query("\nCREATE TABLE foobar(id integer);\n")
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "query contains keywords not allowed in read-only mode")
_, err = client.Query("-- CREATE TABLE foobar(id integer);\nSELECT 'foo';")
assert.NoError(t, err)
_, err = client.Query("/* CREATE TABLE foobar(id integer); */ SELECT 'foo';")
assert.NoError(t, err)
}
func TestAll(t *testing.T) {