Skip to content

Commit 1354343

Browse files
committed
Added unit test
1 parent b78e256 commit 1354343

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import json
2+
3+
from codemodder.codemods.test import BaseSASTCodemodTest
4+
from core_codemods.sonar.sonar_secure_cookie import SonarSecureCookie
5+
6+
7+
class TestSonarSecureCookie(BaseSASTCodemodTest):
8+
codemod = SonarSecureCookie
9+
tool = "sonar"
10+
11+
def test_name(self):
12+
assert self.codemod.name == "secure-cookie"
13+
14+
def test_simple(self, tmpdir):
15+
input_code = """
16+
import flask
17+
18+
response = flask.make_response()
19+
var = "hello"
20+
response.set_cookie("name", "value")
21+
22+
response2 = flask.Response()
23+
var = "hello"
24+
response2.set_cookie("name", "value")
25+
"""
26+
expected = """
27+
import flask
28+
29+
response = flask.make_response()
30+
var = "hello"
31+
response.set_cookie("name", "value", secure=True, httponly=True, samesite='Lax')
32+
33+
response2 = flask.Response()
34+
var = "hello"
35+
response2.set_cookie("name", "value", secure=True, httponly=True, samesite='Lax')
36+
"""
37+
issues = {
38+
"hotspots": [
39+
{
40+
"component": "code.py",
41+
"status": "TO_REVIEW",
42+
"textRange": {
43+
"startLine": 6,
44+
"endLine": 6,
45+
"startOffset": 0,
46+
"endOffset": 19,
47+
},
48+
"ruleKey": "python:S2092",
49+
},
50+
{
51+
"component": "code.py",
52+
"status": "TO_REVIEW",
53+
"textRange": {
54+
"startLine": 10,
55+
"endLine": 10,
56+
"startOffset": 0,
57+
"endOffset": 20,
58+
},
59+
"ruleKey": "python:S2092",
60+
},
61+
{
62+
"component": "code.py",
63+
"status": "TO_REVIEW",
64+
"textRange": {
65+
"startLine": 6,
66+
"endLine": 6,
67+
"startOffset": 0,
68+
"endOffset": 19,
69+
},
70+
"ruleKey": "python:S3330",
71+
},
72+
{
73+
"component": "code.py",
74+
"status": "TO_REVIEW",
75+
"textRange": {
76+
"startLine": 10,
77+
"endLine": 10,
78+
"startOffset": 0,
79+
"endOffset": 20,
80+
},
81+
"ruleKey": "python:S3330",
82+
},
83+
],
84+
}
85+
self.run_and_assert(
86+
tmpdir, input_code, expected, results=json.dumps(issues), num_changes=2
87+
)

0 commit comments

Comments
 (0)