-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a3a6a9
commit 6aba43a
Showing
9 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import requests | ||
|
||
requests.get('https://gmail.com') | ||
requests.get('https://gmail.com', timeout=None) | ||
requests.get('https://gmail.com', timeout=5) | ||
requests.post('https://gmail.com') | ||
requests.post('https://gmail.com', timeout=None) | ||
requests.post('https://gmail.com', timeout=5) | ||
requests.put('https://gmail.com') | ||
requests.put('https://gmail.com', timeout=None) | ||
requests.put('https://gmail.com', timeout=5) | ||
requests.delete('https://gmail.com') | ||
requests.delete('https://gmail.com', timeout=None) | ||
requests.delete('https://gmail.com', timeout=5) | ||
requests.patch('https://gmail.com') | ||
requests.patch('https://gmail.com', timeout=None) | ||
requests.patch('https://gmail.com', timeout=5) | ||
requests.options('https://gmail.com') | ||
requests.options('https://gmail.com', timeout=None) | ||
requests.options('https://gmail.com', timeout=5) | ||
requests.head('https://gmail.com') | ||
requests.head('https://gmail.com', timeout=None) | ||
requests.head('https://gmail.com', timeout=5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -927,6 +927,8 @@ | |
"S106", | ||
"S107", | ||
"S108", | ||
"S11", | ||
"S113", | ||
"S3", | ||
"S32", | ||
"S324", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use rustc_hash::{FxHashMap, FxHashSet}; | ||
use rustpython_ast::{Expr, ExprKind, Keyword}; | ||
use rustpython_parser::ast::Constant; | ||
|
||
use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path, SimpleCallArgs}; | ||
use crate::ast::types::Range; | ||
use crate::registry::{Check, CheckKind}; | ||
|
||
const HTTP_VERBS: [&str; 7] = ["get", "options", "head", "post", "put", "patch", "delete"]; | ||
|
||
/// S113 | ||
pub fn request_without_timeout( | ||
func: &Expr, | ||
args: &[Expr], | ||
keywords: &[Keyword], | ||
from_imports: &FxHashMap<&str, FxHashSet<&str>>, | ||
import_aliases: &FxHashMap<&str, &str>, | ||
) -> Option<Check> { | ||
let call_path = dealias_call_path(collect_call_paths(func), import_aliases); | ||
for func_name in &HTTP_VERBS { | ||
if match_call_path(&call_path, "requests", func_name, from_imports) { | ||
let call_args = SimpleCallArgs::new(args, keywords); | ||
if let Some(timeout_arg) = call_args.get_argument("timeout", None) { | ||
if let Some(timeout) = match &timeout_arg.node { | ||
ExprKind::Constant { | ||
value: value @ Constant::None, | ||
.. | ||
} => Some(value.to_string()), | ||
_ => None, | ||
} { | ||
return Some(Check::new( | ||
CheckKind::RequestWithoutTimeout(Some(timeout)), | ||
Range::from_located(timeout_arg), | ||
)); | ||
} | ||
} else { | ||
return Some(Check::new( | ||
CheckKind::RequestWithoutTimeout(None), | ||
Range::from_located(func), | ||
)); | ||
} | ||
} | ||
} | ||
None | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
src/flake8_bandit/snapshots/ruff__flake8_bandit__tests__S113_S113.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
--- | ||
source: src/flake8_bandit/mod.rs | ||
expression: checks | ||
--- | ||
- kind: | ||
RequestWithoutTimeout: ~ | ||
location: | ||
row: 3 | ||
column: 0 | ||
end_location: | ||
row: 3 | ||
column: 12 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: None | ||
location: | ||
row: 4 | ||
column: 42 | ||
end_location: | ||
row: 4 | ||
column: 46 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: ~ | ||
location: | ||
row: 6 | ||
column: 0 | ||
end_location: | ||
row: 6 | ||
column: 13 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: None | ||
location: | ||
row: 7 | ||
column: 43 | ||
end_location: | ||
row: 7 | ||
column: 47 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: ~ | ||
location: | ||
row: 9 | ||
column: 0 | ||
end_location: | ||
row: 9 | ||
column: 12 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: None | ||
location: | ||
row: 10 | ||
column: 42 | ||
end_location: | ||
row: 10 | ||
column: 46 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: ~ | ||
location: | ||
row: 12 | ||
column: 0 | ||
end_location: | ||
row: 12 | ||
column: 15 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: None | ||
location: | ||
row: 13 | ||
column: 45 | ||
end_location: | ||
row: 13 | ||
column: 49 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: ~ | ||
location: | ||
row: 15 | ||
column: 0 | ||
end_location: | ||
row: 15 | ||
column: 14 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: None | ||
location: | ||
row: 16 | ||
column: 44 | ||
end_location: | ||
row: 16 | ||
column: 48 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: ~ | ||
location: | ||
row: 18 | ||
column: 0 | ||
end_location: | ||
row: 18 | ||
column: 16 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: None | ||
location: | ||
row: 19 | ||
column: 46 | ||
end_location: | ||
row: 19 | ||
column: 50 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: ~ | ||
location: | ||
row: 21 | ||
column: 0 | ||
end_location: | ||
row: 21 | ||
column: 13 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
RequestWithoutTimeout: None | ||
location: | ||
row: 22 | ||
column: 43 | ||
end_location: | ||
row: 22 | ||
column: 47 | ||
fix: ~ | ||
parent: ~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters