Skip to content

Commit c8ee3db

Browse files
committed
chore: reduce DevSkim false positives and fix Azure SQL bulkcopy test
- Exclude tests/, **/test_*.py, and benchmarks/ from DevSkim scanning (localhost in test connection strings is not debug code) - Suppress DS176209 (TODO comments) — informational, not a security concern - DS137138 (localhost) left enabled — path exclusions handle test files, keeps coverage for accidental localhost in production code - Fix test_bulkcopy_without_database_parameter: remove USE statement which is not supported on Azure SQL Database, use fully qualified table names with the default database instead
1 parent acbe020 commit c8ee3db

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

.github/workflows/devskim.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727

2828
- name: Run DevSkim scanner
2929
uses: microsoft/DevSkim-Action@v1
30+
with:
31+
ignore_globs: "tests/**,**/test_*.py,benchmarks/**"
32+
# DS176209: TODO comments — not a security concern
33+
ignore_rules_list: "DS176209"
3034

3135
- name: Upload DevSkim scan results to GitHub Security tab
3236
uses: github/codeql-action/upload-sarif@v3

tests/test_019_bulkcopy.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ def test_bulkcopy_without_database_parameter(conn_str):
9999
parser = _ConnectionStringParser(validate_keywords=False)
100100
params = parser._parse(conn_str)
101101

102-
# Save the original database name to use it explicitly in our operations
103-
original_database = params.get("database")
104-
105102
# Remove DATABASE parameter if present (case-insensitive, handles all synonyms)
106103
params.pop("database", None)
107104

@@ -119,11 +116,7 @@ def test_bulkcopy_without_database_parameter(conn_str):
119116
current_db = cursor.fetchone()[0]
120117
assert current_db is not None, "Should be connected to a database"
121118

122-
# If original database was specified, switch to it to ensure we have permissions
123-
if original_database:
124-
cursor.execute(f"USE [{original_database}]")
125-
126-
# Create test table in the current database
119+
# Create test table in the current (default) database
127120
table_name = "mssql_python_bulkcopy_no_db_test"
128121
cursor.execute(f"IF OBJECT_ID('{table_name}', 'U') IS NOT NULL DROP TABLE {table_name}")
129122
cursor.execute(f"CREATE TABLE {table_name} (id INT, name VARCHAR(50), value FLOAT)")
@@ -137,11 +130,9 @@ def test_bulkcopy_without_database_parameter(conn_str):
137130
]
138131

139132
# Perform bulkcopy - this should NOT raise ValueError about missing DATABASE
140-
# Note: bulkcopy creates its own connection, so we need to use fully qualified table name
141-
# if we had a database in the original connection string
142-
bulkcopy_table_name = (
143-
f"[{original_database}].[dbo].{table_name}" if original_database else table_name
144-
)
133+
# Use fully qualified name with the actual current database (not the
134+
# original one we stripped — that may differ from where we landed).
135+
bulkcopy_table_name = f"[{current_db}].[dbo].{table_name}"
145136
result = cursor.bulkcopy(bulkcopy_table_name, data, timeout=60)
146137

147138
# Verify result
@@ -189,13 +180,15 @@ def test_bulkcopy_with_server_synonyms(conn_str):
189180

190181
# Create table
191182
cursor.execute(f"DROP TABLE IF EXISTS {table_name}")
192-
cursor.execute(f"""
183+
cursor.execute(
184+
f"""
193185
CREATE TABLE {table_name} (
194186
id INT,
195187
name NVARCHAR(50),
196188
value FLOAT
197189
)
198-
""")
190+
"""
191+
)
199192
conn.commit()
200193

201194
# Test data
@@ -236,13 +229,15 @@ def test_bulkcopy_with_server_synonyms(conn_str):
236229

237230
# Create table
238231
cursor.execute(f"DROP TABLE IF EXISTS {table_name}")
239-
cursor.execute(f"""
232+
cursor.execute(
233+
f"""
240234
CREATE TABLE {table_name} (
241235
id INT,
242236
name NVARCHAR(50),
243237
value FLOAT
244238
)
245-
""")
239+
"""
240+
)
246241
conn.commit()
247242

248243
# Test data

0 commit comments

Comments
 (0)