Skip to content

Commit b0efe99

Browse files
authored
feat: block all query requests (apache#751)
* block all query or insert requests * rename
1 parent ca9b999 commit b0efe99

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

server/src/limiter.rs

+14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ define_result!(Error);
2929
#[derive(Clone, Copy, Deserialize, Debug, PartialEq, Eq, Hash, Serialize, PartialOrd, Ord)]
3030
pub enum BlockRule {
3131
QueryWithoutPredicate,
32+
AnyQuery,
33+
AnyInsert,
3234
}
3335

3436
#[derive(Default, Clone, Deserialize, Debug, Serialize)]
@@ -43,6 +45,8 @@ impl BlockRule {
4345
fn should_limit(&self, plan: &Plan) -> bool {
4446
match self {
4547
BlockRule::QueryWithoutPredicate => self.is_query_without_predicate(plan),
48+
BlockRule::AnyQuery => matches!(plan, Plan::Query(_)),
49+
BlockRule::AnyInsert => matches!(plan, Plan::Insert(_)),
4650
}
4751
}
4852

@@ -270,6 +274,16 @@ mod tests {
270274
let insert="INSERT INTO test_table(key1, key2, field1, field2) VALUES('tagk', 1638428434000, 100, 'hello3')";
271275
let insert_plan = sql_to_plan(&mock, insert);
272276
assert!(limiter.try_limit(&insert_plan).is_ok());
277+
278+
let (mock, limiter) = prepare_limiter_with_rules(vec![BlockRule::AnyQuery]);
279+
let query = "select * from test_table";
280+
let query_plan = sql_to_plan(&mock, query);
281+
assert!(limiter.try_limit(&query_plan).is_err());
282+
283+
let (mock, limiter) = prepare_limiter_with_rules(vec![BlockRule::AnyInsert]);
284+
let insert="INSERT INTO test_table(key1, key2, field1, field2) VALUES('tagk', 1638428434000, 100, 'hello3')";
285+
let insert_plan = sql_to_plan(&mock, insert);
286+
assert!(limiter.try_limit(&insert_plan).is_err());
273287
}
274288

275289
#[test]

0 commit comments

Comments
 (0)