Skip to content

Commit be4c0b3

Browse files
sfc-gh-pczajkasfc-gh-turbaszek
authored andcommitted
Adjust binging security test to server behavioral change (#2588)
1 parent 12ba779 commit be4c0b3

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

test/csp_helpers.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,3 @@ def __enter__(self):
446446
def __exit__(self, *args, **kwargs):
447447
self.os_environment_patch.__exit__(*args)
448448
super().__exit__(*args, **kwargs)
449-
450-
451-
def is_running_against_gcp():
452-
return os.getenv("cloud_provider").lower() == "gcp"

test/integ/test_cursor_binding.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python
22
from __future__ import annotations
33

4-
from test.csp_helpers import is_running_against_gcp
5-
64
import pytest
75

86
from snowflake.connector.errors import ProgrammingError
@@ -44,22 +42,38 @@ def test_binding_security(conn_cnx, db_parameters):
4442

4543
# SQL injection safe test
4644
# Good Example
47-
if not is_running_against_gcp():
48-
with pytest.raises(ProgrammingError):
49-
cnx.cursor().execute(
45+
# server behavior change: this no longer raises an error, but returns an empty result set
46+
try:
47+
res = (
48+
cnx.cursor()
49+
.execute(
5050
"SELECT * FROM {name} WHERE aa=%s".format(
5151
name=db_parameters["name"]
5252
),
5353
("1 or aa>0",),
5454
)
55-
56-
with pytest.raises(ProgrammingError):
57-
cnx.cursor().execute(
55+
.fetchall()
56+
)
57+
assert res == []
58+
except ProgrammingError:
59+
# old server behavior: OK
60+
pass
61+
62+
try:
63+
res = (
64+
cnx.cursor()
65+
.execute(
5866
"SELECT * FROM {name} WHERE aa=%(aa)s".format(
5967
name=db_parameters["name"]
6068
),
6169
{"aa": "1 or aa>0"},
6270
)
71+
.fetchall()
72+
)
73+
assert res == []
74+
except ProgrammingError:
75+
# old server behavior: OK
76+
pass
6377

6478
# Bad Example in application. DON'T DO THIS
6579
c = cnx.cursor()

0 commit comments

Comments
 (0)