Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit test for sql removal vars #791

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions tests/codemods/test_sql_parameterization.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from codemodder.codemods.test import BaseCodemodTest
from core_codemods.sql_parameterization import SQLQueryParameterization

Expand Down Expand Up @@ -183,6 +185,56 @@ def test_simple_concatenated_strings(self, tmpdir):
"""
self.run_and_assert(tmpdir, input_code, expected)

@pytest.mark.xfail(reason="https://github.com/pixee/codemodder-python/issues/441")
def test_donot_remove_variables(self, tmpdir):
input_code = """
def sql_lab(request):
if request.user.is_authenticated:
name=request.POST.get('name')
password=request.POST.get('pass')
if name:
if login.objects.filter(user=name):
sql_query = "SELECT * FROM introduction_login WHERE user='"+name+"'AND password='"+password+"'"
print(sql_query)
try:
val=login.objects.execute(sql_query)
except:
pass
if val:
user=val[0].user
return render(request, 'Lab/SQL/sql_lab.html',{"user1":user})
@csrf_exempt
def xxe_parse(request):
text='hi'
p=comments.objects.filter(id=1).update(comment=text)
return render(request, 'Lab/XXE/xxe_lab.html')

"""
expected = """
def sql_lab(request):
if request.user.is_authenticated:
name=request.POST.get('name')
password=request.POST.get('pass')
if name:
if login.objects.filter(user=name):
sql_query = "SELECT * FROM introduction_login WHERE user=?"+"AND password=?"
print(sql_query)
try:
val=login.objects.execute(sql_query, (name, password, ))
except:
pass
if val:
user=val[0].user
return render(request, 'Lab/SQL/sql_lab.html',{"user1":user})
@csrf_exempt
def xxe_parse(request):
text='hi'
p=comments.objects.filter(id=1).update(comment=text)
return render(request, 'Lab/XXE/xxe_lab.html')

"""
self.run_and_assert(tmpdir, input_code, expected)


class TestSQLQueryParameterizationFormattedString(BaseCodemodTest):
codemod = SQLQueryParameterization
Expand Down
Loading