Skip to content

Commit 123d048

Browse files
committed
Fix DevSkim warnings: Replace localhost with testserver in test
- Replace all 5 instances of 'localhost' with 'testserver' in mock tests - These tests use mocked connections and never actually connect - Addresses GitHub Advanced Security DevSkim notices on PR #562 (lines 209, 221, 231, 240, 251)
1 parent cc599b8 commit 123d048

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

tests/test_006_exceptions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def test_connect_runtime_error_mapped_to_correct_dbapi_exception():
206206
side_effect=RuntimeError("SQLSTATE:28000:Login failed for user 'baduser'."),
207207
):
208208
with pytest.raises(OperationalError) as exc_info:
209-
connect("Server=localhost;Database=mydb;UID=baduser;PWD=wrongpassword;")
209+
connect("Server=testserver;Database=mydb;UID=baduser;PWD=wrongpassword;")
210210
assert "Login failed for user" in exc_info.value.ddbc_error
211211
assert not isinstance(exc_info.value, RuntimeError)
212212

@@ -218,7 +218,7 @@ def test_connect_runtime_error_mapped_to_correct_dbapi_exception():
218218
),
219219
):
220220
with pytest.raises(OperationalError) as exc_info:
221-
connect("Server=localhost;Database=mydb;UID=u;PWD=p;")
221+
connect("Server=testserver;Database=mydb;UID=u;PWD=p;")
222222
assert "no default driver" in exc_info.value.ddbc_error
223223
assert not isinstance(exc_info.value, RuntimeError)
224224

@@ -228,7 +228,7 @@ def test_connect_runtime_error_mapped_to_correct_dbapi_exception():
228228
side_effect=RuntimeError("Connection handle not allocated"),
229229
):
230230
with pytest.raises(OperationalError) as exc_info:
231-
connect("Server=localhost;Database=mydb;UID=u;PWD=p;")
231+
connect("Server=testserver;Database=mydb;UID=u;PWD=p;")
232232
assert "Connection handle not allocated" in exc_info.value.ddbc_error
233233
assert not isinstance(exc_info.value, RuntimeError)
234234

@@ -238,7 +238,7 @@ def test_connect_runtime_error_mapped_to_correct_dbapi_exception():
238238
side_effect=RuntimeError("SQLSTATE:99999:Unknown error with unmapped code"),
239239
):
240240
with pytest.raises(DatabaseError) as exc_info:
241-
connect("Server=localhost;Database=mydb;UID=u;PWD=p;")
241+
connect("Server=testserver;Database=mydb;UID=u;PWD=p;")
242242
assert "Unknown error with unmapped code" in exc_info.value.ddbc_error
243243
assert "SQLSTATE code: 99999" in exc_info.value.driver_error
244244
assert not isinstance(exc_info.value, RuntimeError)
@@ -249,7 +249,7 @@ def test_connect_runtime_error_mapped_to_correct_dbapi_exception():
249249
side_effect=RuntimeError("SQLSTATE::Invalid handle!"),
250250
):
251251
with pytest.raises(OperationalError) as exc_info:
252-
connect("Server=localhost;Database=mydb;UID=u;PWD=p;")
252+
connect("Server=testserver;Database=mydb;UID=u;PWD=p;")
253253
assert "Invalid handle!" in exc_info.value.ddbc_error
254254
assert not isinstance(exc_info.value, RuntimeError)
255255

@@ -258,7 +258,7 @@ def test_connect_runtime_error_mapped_to_correct_dbapi_exception():
258258
mock_conn.commit.side_effect = RuntimeError("SQLSTATE:08S01:Communication link failure")
259259
mock_conn.get_autocommit.return_value = False
260260
with patch("mssql_python.connection.ddbc_bindings.Connection", return_value=mock_conn):
261-
conn = connect("Server=localhost;Database=mydb;UID=u;PWD=p;")
261+
conn = connect("Server=testserver;Database=mydb;UID=u;PWD=p;")
262262
with pytest.raises(OperationalError) as exc_info:
263263
conn.commit()
264264
assert "Communication link failure" in exc_info.value.ddbc_error
@@ -269,7 +269,7 @@ def test_connect_runtime_error_mapped_to_correct_dbapi_exception():
269269
mock_conn2.rollback.side_effect = RuntimeError("SQLSTATE:08S01:Communication link failure")
270270
mock_conn2.get_autocommit.return_value = False
271271
with patch("mssql_python.connection.ddbc_bindings.Connection", return_value=mock_conn2):
272-
conn2 = connect("Server=localhost;Database=mydb;UID=u;PWD=p;")
272+
conn2 = connect("Server=testserver;Database=mydb;UID=u;PWD=p;")
273273
with pytest.raises(OperationalError) as exc_info:
274274
conn2.rollback()
275275
assert "Communication link failure" in exc_info.value.ddbc_error

0 commit comments

Comments
 (0)