Skip to content

Commit 4bfd259

Browse files
committed
Add SQL_COPT_SS_ACCESS_TOKEN constant, replace hardcoded 1256
1 parent f0f34fd commit 4bfd259

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

mssql_python/auth.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Tuple, Dict, Optional, List
1010

1111
from mssql_python.logging import logger
12-
from mssql_python.constants import AuthType
12+
from mssql_python.constants import AuthType, ConstantsDDBC
1313

1414

1515
class AADAuth:
@@ -293,7 +293,11 @@ def process_connection_string(
293293
"process_connection_string: Token authentication configured successfully - auth_type=%s",
294294
auth_type,
295295
)
296-
return ";".join(modified_parameters) + ";", {1256: token_struct}, auth_type
296+
return (
297+
";".join(modified_parameters) + ";",
298+
{ConstantsDDBC.SQL_COPT_SS_ACCESS_TOKEN.value: token_struct},
299+
auth_type,
300+
)
297301
else:
298302
logger.warning(
299303
"process_connection_string: Token acquisition failed, proceeding without token"

mssql_python/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ class ConstantsDDBC(Enum):
158158
SQL_ATTR_SERVER_NAME = 13
159159
SQL_ATTR_RESET_CONNECTION = 116
160160

161+
# SQL Server-specific connection option constants
162+
SQL_COPT_SS_ACCESS_TOKEN = 1256
163+
161164
# Transaction Isolation Level Constants
162165
SQL_TXN_READ_UNCOMMITTED = 1
163166
SQL_TXN_READ_COMMITTED = 2

tests/test_008_auth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
process_connection_string,
1717
extract_auth_type,
1818
)
19-
from mssql_python.constants import AuthType
19+
from mssql_python.constants import AuthType, ConstantsDDBC
2020
import secrets
2121

2222
SAMPLE_TOKEN = secrets.token_hex(44)
@@ -338,8 +338,8 @@ def test_process_connection_string_with_default_auth(self):
338338
assert "Server=test" in result_str
339339
assert "Database=testdb" in result_str
340340
assert attrs is not None
341-
assert 1256 in attrs
342-
assert isinstance(attrs[1256], bytes)
341+
assert ConstantsDDBC.SQL_COPT_SS_ACCESS_TOKEN.value in attrs
342+
assert isinstance(attrs[ConstantsDDBC.SQL_COPT_SS_ACCESS_TOKEN.value], bytes)
343343
assert auth_type == "default"
344344

345345
def test_process_connection_string_no_auth(self):
@@ -361,8 +361,8 @@ def test_process_connection_string_interactive_non_windows(self, monkeypatch):
361361
assert "Server=test" in result_str
362362
assert "Database=testdb" in result_str
363363
assert attrs is not None
364-
assert 1256 in attrs
365-
assert isinstance(attrs[1256], bytes)
364+
assert ConstantsDDBC.SQL_COPT_SS_ACCESS_TOKEN.value in attrs
365+
assert isinstance(attrs[ConstantsDDBC.SQL_COPT_SS_ACCESS_TOKEN.value], bytes)
366366
assert auth_type == "interactive"
367367

368368

0 commit comments

Comments
 (0)