-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new sonar tmpfile codemod * update integration tests * add assertions for sonar integration test * add docs
- Loading branch information
1 parent
06807ba
commit 9aa6fb2
Showing
11 changed files
with
141 additions
and
38 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,12 @@ | ||
from codemodder.codemods.test import SonarIntegrationTest | ||
from core_codemods.sonar.sonar_tempfile_mktemp import SonarTempfileMktemp | ||
from core_codemods.tempfile_mktemp import TempfileMktempTransformer | ||
|
||
|
||
class TestTempfileMktemp(SonarIntegrationTest): | ||
codemod = SonarTempfileMktemp | ||
code_path = "tests/samples/tempfile_mktemp.py" | ||
replacement_lines = [(3, "tempfile.mkstemp()\n")] | ||
expected_diff = "--- \n+++ \n@@ -1,3 +1,3 @@\n import tempfile\n \n-tempfile.mktemp()\n+tempfile.mkstemp()\n" | ||
expected_line_change = "3" | ||
change_description = TempfileMktempTransformer.change_description |
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
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,10 @@ | ||
from codemodder.codemods.sonar import SonarCodemod | ||
from core_codemods.tempfile_mktemp import TempfileMktemp | ||
|
||
SonarTempfileMktemp = SonarCodemod.from_core_codemod( | ||
name="secure-tempfile-S5445", | ||
other=TempfileMktemp, | ||
rule_id="python:S5445", | ||
rule_name="Insecure temporary file creation methods should not be used", | ||
rule_url="https://rules.sonarsource.com/python/type/Vulnerability/RSPEC-5445/", | ||
) |
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,40 @@ | ||
import json | ||
|
||
from codemodder.codemods.test import BaseSASTCodemodTest | ||
from core_codemods.sonar.sonar_tempfile_mktemp import SonarTempfileMktemp | ||
|
||
|
||
class TestSonarTempfileMktemp(BaseSASTCodemodTest): | ||
codemod = SonarTempfileMktemp | ||
tool = "sonar" | ||
|
||
def test_name(self): | ||
assert self.codemod.name == "secure-tempfile-S5445" | ||
|
||
def test_simple(self, tmpdir): | ||
input_code = """ | ||
import tempfile | ||
tempfile.mktemp() | ||
""" | ||
expected = """ | ||
import tempfile | ||
tempfile.mkstemp() | ||
""" | ||
issues = { | ||
"issues": [ | ||
{ | ||
"rule": "python:S5445", | ||
"status": "OPEN", | ||
"component": "code.py", | ||
"textRange": { | ||
"startLine": 4, | ||
"endLine": 4, | ||
"startOffset": 0, | ||
"endOffset": 17, | ||
}, | ||
} | ||
] | ||
} | ||
self.run_and_assert(tmpdir, input_code, expected, results=json.dumps(issues)) |
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,3 @@ | ||
import tempfile | ||
|
||
tempfile.mktemp() |