|
| 1 | +import pytest |
| 2 | + |
1 | 3 | from codemodder.codemods.test import BaseCodemodTest |
2 | 4 | from core_codemods.sql_parameterization import SQLQueryParameterization |
3 | 5 |
|
@@ -183,6 +185,56 @@ def test_simple_concatenated_strings(self, tmpdir): |
183 | 185 | """ |
184 | 186 | self.run_and_assert(tmpdir, input_code, expected) |
185 | 187 |
|
| 188 | + @pytest.mark.xfail(reason="https://github.com/pixee/codemodder-python/issues/441") |
| 189 | + def test_donot_remove_variables(self, tmpdir): |
| 190 | + input_code = """ |
| 191 | + def sql_lab(request): |
| 192 | + if request.user.is_authenticated: |
| 193 | + name=request.POST.get('name') |
| 194 | + password=request.POST.get('pass') |
| 195 | + if name: |
| 196 | + if login.objects.filter(user=name): |
| 197 | + sql_query = "SELECT * FROM introduction_login WHERE user='"+name+"'AND password='"+password+"'" |
| 198 | + print(sql_query) |
| 199 | + try: |
| 200 | + val=login.objects.execute(sql_query) |
| 201 | + except: |
| 202 | + pass |
| 203 | + if val: |
| 204 | + user=val[0].user |
| 205 | + return render(request, 'Lab/SQL/sql_lab.html',{"user1":user}) |
| 206 | + @csrf_exempt |
| 207 | + def xxe_parse(request): |
| 208 | + text='hi' |
| 209 | + p=comments.objects.filter(id=1).update(comment=text) |
| 210 | + return render(request, 'Lab/XXE/xxe_lab.html') |
| 211 | +
|
| 212 | + """ |
| 213 | + expected = """ |
| 214 | + def sql_lab(request): |
| 215 | + if request.user.is_authenticated: |
| 216 | + name=request.POST.get('name') |
| 217 | + password=request.POST.get('pass') |
| 218 | + if name: |
| 219 | + if login.objects.filter(user=name): |
| 220 | + sql_query = "SELECT * FROM introduction_login WHERE user=?"+"AND password=?" |
| 221 | + print(sql_query) |
| 222 | + try: |
| 223 | + val=login.objects.execute(sql_query, (name, password, )) |
| 224 | + except: |
| 225 | + pass |
| 226 | + if val: |
| 227 | + user=val[0].user |
| 228 | + return render(request, 'Lab/SQL/sql_lab.html',{"user1":user}) |
| 229 | + @csrf_exempt |
| 230 | + def xxe_parse(request): |
| 231 | + text='hi' |
| 232 | + p=comments.objects.filter(id=1).update(comment=text) |
| 233 | + return render(request, 'Lab/XXE/xxe_lab.html') |
| 234 | +
|
| 235 | + """ |
| 236 | + self.run_and_assert(tmpdir, input_code, expected) |
| 237 | + |
186 | 238 |
|
187 | 239 | class TestSQLQueryParameterizationFormattedString(BaseCodemodTest): |
188 | 240 | codemod = SQLQueryParameterization |
|
0 commit comments