You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/03/16 13:23:37 UTC

[GitHub] [cassandra] adelapena commented on a change in pull request #1453: CASSANDRA-17370 added enable for ALLOW FILTERING property

adelapena commented on a change in pull request #1453:
URL: https://github.com/apache/cassandra/pull/1453#discussion_r827991221



##########
File path: test/unit/org/apache/cassandra/db/guardrails/GuardrailAllowFilteringTest.java
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GuardrailAllowFilteringTest extends GuardrailTester
+{
+    private boolean enableState;
+
+    @Before
+    public void setupTest()
+    {
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)");
+        enableState = getGuardrial();
+    }
+
+    @After
+    public void teardownTest()
+    {
+        setGuardrail(enableState);
+    }
+
+    private void setGuardrail(boolean allowFilteringEnabled)
+    {
+        guardrails().setAllowFilteringEnabled(allowFilteringEnabled);
+    }
+
+    private boolean getGuardrial()
+    {
+        return guardrails().getAllowFilteringEnabled();
+    }
+
+    @Test
+    public void testAllowFilteringDisabled() throws Throwable
+    {
+        setGuardrail(false);
+        assertFails("SELECT * from %s WHERE a = 5 ALLOW FILTERING","Querying with ALLOW FILTERING is not allowed");
+    }
+
+    @Test
+    public void testAllowFilteringDisabedNotUsed() throws Throwable
+    {
+        setGuardrail(false);
+        execute("INSERT INTO %s (k, a, b) VALUES (1, 1, 1)");
+        assertAllRows(
+            row(1,1,1)
+        );

Review comment:
       Nit: not need to break the line, missed whitespaces.
   ```suggestion
           assertAllRows(row(1, 1, 1));
   ```

##########
File path: test/unit/org/apache/cassandra/db/guardrails/GuardrailAllowFilteringTest.java
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GuardrailAllowFilteringTest extends GuardrailTester
+{
+    private boolean enableState;
+
+    @Before
+    public void setupTest()
+    {
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)");
+        enableState = getGuardrial();
+    }
+
+    @After
+    public void teardownTest()
+    {
+        setGuardrail(enableState);
+    }
+
+    private void setGuardrail(boolean allowFilteringEnabled)
+    {
+        guardrails().setAllowFilteringEnabled(allowFilteringEnabled);
+    }
+
+    private boolean getGuardrial()
+    {
+        return guardrails().getAllowFilteringEnabled();
+    }
+
+    @Test
+    public void testAllowFilteringDisabled() throws Throwable
+    {
+        setGuardrail(false);
+        assertFails("SELECT * from %s WHERE a = 5 ALLOW FILTERING","Querying with ALLOW FILTERING is not allowed");

Review comment:
       Nit: missed whitespace
   ```suggestion
           assertFails("SELECT * from %s WHERE a = 5 ALLOW FILTERING", "Querying with ALLOW FILTERING is not allowed");
   ```

##########
File path: src/java/org/apache/cassandra/config/Config.java
##########
@@ -776,6 +776,7 @@ public static void setClientMode(boolean clientMode)
 
     public volatile DurationSpec streaming_state_expires = DurationSpec.inDays(3);
     public volatile DataStorageSpec streaming_state_size = DataStorageSpec.inMebibytes(40);
+    public volatile boolean allow_filtering_enabled = false;

Review comment:
       Also, the property should appear on `cassandra.yaml`, for example:
   ```
   # Guardrail to allow/disallow querying with ALLOW FILTERING. Defaults to true.
   # allow_filtering_enabled: true
   ```

##########
File path: test/unit/org/apache/cassandra/db/guardrails/GuardrailAllowFilteringTest.java
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GuardrailAllowFilteringTest extends GuardrailTester
+{
+    private boolean enableState;
+
+    @Before
+    public void setupTest()
+    {
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)");
+        enableState = getGuardrial();
+    }
+
+    @After
+    public void teardownTest()
+    {
+        setGuardrail(enableState);
+    }
+
+    private void setGuardrail(boolean allowFilteringEnabled)
+    {
+        guardrails().setAllowFilteringEnabled(allowFilteringEnabled);
+    }
+
+    private boolean getGuardrial()
+    {
+        return guardrails().getAllowFilteringEnabled();
+    }
+
+    @Test
+    public void testAllowFilteringDisabled() throws Throwable
+    {
+        setGuardrail(false);
+        assertFails("SELECT * from %s WHERE a = 5 ALLOW FILTERING","Querying with ALLOW FILTERING is not allowed");
+    }
+
+    @Test
+    public void testAllowFilteringDisabedNotUsed() throws Throwable
+    {
+        setGuardrail(false);
+        execute("INSERT INTO %s (k, a, b) VALUES (1, 1, 1)");
+        assertAllRows(
+            row(1,1,1)
+        );
+    }
+
+    @Test
+    public void testAllowFilteringEnabled() throws Throwable
+    {
+        setGuardrail(true);
+        execute("INSERT INTO %s (k, a, b) VALUES (1, 1, 1)");
+        assertValid("SELECT * from %s WHERE a = 5 ALLOW FILTERING");
+    }

Review comment:
       Multiple similar tests verify that the guardrail is not applied to excluded users, it can be done by adding this simple test:
   ```java
       @Test
       public void testExcludedUsers() throws Throwable
       {
           setGuardrail(false);
           testExcludedUsers(() -> "SELECT * FROM %s WHERE a = 5 ALLOW FILTERING");
       }
   ```

##########
File path: src/java/org/apache/cassandra/config/Config.java
##########
@@ -776,6 +776,7 @@ public static void setClientMode(boolean clientMode)
 
     public volatile DurationSpec streaming_state_expires = DurationSpec.inDays(3);
     public volatile DataStorageSpec streaming_state_size = DataStorageSpec.inMebibytes(40);
+    public volatile boolean allow_filtering_enabled = false;

Review comment:
       I would place this three lines above, so it's together with the other guardrail properties.

##########
File path: src/java/org/apache/cassandra/config/GuardrailsOptions.java
##########
@@ -322,6 +322,20 @@ public void setReadBeforeWriteListOperationsEnabled(boolean enabled)
                                   x -> config.read_before_write_list_operations_enabled = x);
     }
 
+    @Override
+    public boolean getAllowFilteringEnabled()
+   {
+        return config.allow_filtering_enabled;
+   }
+
+   public void setAllowFilteringEnabled(boolean enabled)
+   {
+       updatePropertyWithLogging("allow_filtering_enabled",
+                                 enabled,
+                                 () -> config.allow_filtering_enabled,
+                                 x -> config.allow_filtering_enabled = x);
+   }
+

Review comment:
       It seems that this remains misaligned after the last commits.

##########
File path: test/unit/org/apache/cassandra/db/guardrails/GuardrailAllowFilteringTest.java
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GuardrailAllowFilteringTest extends GuardrailTester
+{
+    private boolean enableState;
+
+    @Before
+    public void setupTest()
+    {
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)");
+        enableState = getGuardrial();
+    }
+
+    @After
+    public void teardownTest()
+    {
+        setGuardrail(enableState);
+    }
+
+    private void setGuardrail(boolean allowFilteringEnabled)
+    {
+        guardrails().setAllowFilteringEnabled(allowFilteringEnabled);
+    }
+
+    private boolean getGuardrial()
+    {
+        return guardrails().getAllowFilteringEnabled();
+    }
+
+    @Test
+    public void testAllowFilteringDisabled() throws Throwable
+    {
+        setGuardrail(false);
+        assertFails("SELECT * from %s WHERE a = 5 ALLOW FILTERING","Querying with ALLOW FILTERING is not allowed");
+    }
+
+    @Test
+    public void testAllowFilteringDisabedNotUsed() throws Throwable

Review comment:
       Nit: doesn't need the `throws Throwable` part if we are removing it from `CQLTester#execute`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org