mshahid6 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2835056433


##########
server/src/test/java/org/apache/druid/server/QueryBlocklistRuleTest.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.druid.server;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.apache.druid.query.Druids;
+import org.apache.druid.query.timeseries.TimeseriesQuery;
+import org.junit.Assert;
+import org.junit.Test;
+import java.util.Map;
+import java.util.Set;
+
+public class QueryBlocklistRuleTest
+{
+  @Test
+  public void testMatchAllCriteria_rejectsNullCriteria()
+  {
+    // Rule with all null criteria would block ALL queries - this should be 
rejected
+    Assert.assertThrows(
+        IllegalArgumentException.class,
+        () -> new QueryBlocklistRule("match-all", null, null, null)
+    );
+  }
+
+  @Test
+  public void testMatchAllCriteria_rejectsEmptyCollections()
+  {
+    // Rule with all empty collections should also be rejected (same as null)
+    Assert.assertThrows(
+        IllegalArgumentException.class,
+        () -> new QueryBlocklistRule("match-all", ImmutableSet.of(), 
ImmutableSet.of(), ImmutableMap.of())
+    );
+  }
+
+  @Test
+  public void testMatchByDataSource()
+  {
+    Set<String> dataSources = ImmutableSet.of("sensitive_data", "pii_table");
+    QueryBlocklistRule rule = new QueryBlocklistRule("block-sensitive", 
dataSources, null, null);
+
+    // Should match when datasource is in the list
+    TimeseriesQuery matchingQuery = Druids.newTimeseriesQueryBuilder()
+                                   .dataSource("sensitive_data")
+                                   .intervals("2020-01-01/2020-01-02")
+                                   .build();
+    Assert.assertTrue(rule.matches(matchingQuery));
+
+    // Should not match when datasource is not in the list
+    TimeseriesQuery nonMatchingQuery = Druids.newTimeseriesQueryBuilder()
+                                      .dataSource("safe_data")
+                                      .intervals("2020-01-01/2020-01-02")
+                                      .build();
+    Assert.assertFalse(rule.matches(nonMatchingQuery));
+  }
+
+  @Test
+  public void testMatchByContext()
+  {
+    Map<String, String> contextMatches = ImmutableMap.of("priority", "0", 
"application", "rogue-app");
+    QueryBlocklistRule rule = new QueryBlocklistRule("block-rogue-app", null, 
null, contextMatches);
+
+    // Should match when all context values match
+    TimeseriesQuery matchingQuery = Druids.newTimeseriesQueryBuilder()
+                                   .dataSource("test")
+                                   .intervals("2020-01-01/2020-01-02")
+                                   .context(ImmutableMap.of("priority", "0", 
"application", "rogue-app"))
+                                   .build();
+    Assert.assertTrue(rule.matches(matchingQuery));
+
+    // Should not match when context values don't match
+    TimeseriesQuery nonMatchingQuery = Druids.newTimeseriesQueryBuilder()
+                                      .dataSource("test")
+                                      .intervals("2020-01-01/2020-01-02")
+                                      .context(ImmutableMap.of("priority", 
"1", "application", "rogue-app"))
+                                      .build();
+    Assert.assertFalse(rule.matches(nonMatchingQuery));
+
+    // Should not match when context is missing
+    TimeseriesQuery noContextQuery = Druids.newTimeseriesQueryBuilder()
+                                    .dataSource("test")
+                                    .intervals("2020-01-01/2020-01-02")
+                                    .build();
+    Assert.assertFalse(rule.matches(noContextQuery));
+  }
+
+  @Test
+  public void testMatchByMultipleCriteria()
+  {
+    // Rule with multiple criteria - all must match (AND logic)
+    Set<String> dataSources = ImmutableSet.of("large_table");
+    Map<String, String> contextMatches = ImmutableMap.of("priority", "0");
+    QueryBlocklistRule rule = new QueryBlocklistRule(
+        "block-low-priority-large-table",
+        dataSources,
+        null,
+        contextMatches
+    );
+
+    // Should match when both datasource AND context match
+    TimeseriesQuery matchingQuery = Druids.newTimeseriesQueryBuilder()
+                                   .dataSource("large_table")
+                                   .intervals("2020-01-01/2020-01-02")
+                                   .context(ImmutableMap.of("priority", "0"))
+                                   .build();
+    Assert.assertTrue(rule.matches(matchingQuery));
+
+    // Should not match when only datasource matches
+    TimeseriesQuery onlyDataSourceMatches = Druids.newTimeseriesQueryBuilder()
+                                           .dataSource("large_table")
+                                           .intervals("2020-01-01/2020-01-02")
+                                           
.context(ImmutableMap.of("priority", "1"))
+                                           .build();
+    Assert.assertFalse(rule.matches(onlyDataSourceMatches));
+
+    // Should not match when only context matches
+    TimeseriesQuery onlyContextMatches = Druids.newTimeseriesQueryBuilder()
+                                        .dataSource("small_table")
+                                        .intervals("2020-01-01/2020-01-02")
+                                        .context(ImmutableMap.of("priority", 
"0"))
+                                        .build();
+    Assert.assertFalse(rule.matches(onlyContextMatches));
+  }
+
+  @Test
+  public void testWildcardBehavior_nullQueryTypes()
+  {
+    QueryBlocklistRule rule = new QueryBlocklistRule(
+        "block-datasource-all-types",
+        ImmutableSet.of("blocked_ds"),
+        null,  // null means match all query types

Review Comment:
   
https://github.com/apache/druid/pull/19011/changes/BASE..ab49ff09e6954ca00d9485650a55ce1b395dcfb6#diff-23b572e1c4ec981b4ca8ebdac28e9bb94dc71bb29c8342a68bd483c39f362ffeR857
 
   i can add to this?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to