Skip to content

Commit

Permalink
Preparation for 1.16.0 release (#175)
Browse files Browse the repository at this point in the history
* Fix tests for 1.16.0 release preparation

* Add types-pyOpenSSL dependency
  • Loading branch information
denisenkom authored Oct 29, 2024
1 parent 18e6427 commit a273130
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/pytds/tds_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

if typing.TYPE_CHECKING:
from pytds.tds_session import _TdsSession
import OpenSSL


def IS_TDS7_PLUS(x: _TdsSession):
Expand Down Expand Up @@ -955,7 +956,7 @@ def __init__(self) -> None:
self.validate_host = True
self.enc_login_only = False
self.enc_flag = 0
self.tls_ctx = None
self.tls_ctx: None | OpenSSL.SSL.Context = None
self.client_tz: datetime.tzinfo = pytds.tz.local
self.option_flag2 = 0
self.connect_timeout = 0.0
Expand Down
5 changes: 4 additions & 1 deletion src/pytds/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ def establish_channel(tds_sock: _TdsSession) -> None:
w = tds_sock._writer
r = tds_sock._reader
login = tds_sock.conn._login
tls_ctx = login.tls_ctx
if not tls_ctx:
raise Exception("login.tls_ctx is not set unexpectedly")

bhost = login.server_name.encode("ascii")

conn = OpenSSL.SSL.Connection(login.tls_ctx)
conn = OpenSSL.SSL.Connection(tls_ctx)
conn.set_tlsext_host_name(bhost)
# change connection to client mode
conn.set_connect_state()
Expand Down
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ codecov
# TypeError: deprecated() got an unexpected keyword argument 'name'
# Example failing build: https://ci.appveyor.com/project/denisenkom/pytds/builds/46539355/job/aq6d65ej1oi0i59p
pyOpenSSL<22.1.0
types-pyOpenSSL
pyDes
ntlm-auth
pyspnego
Expand Down
8 changes: 3 additions & 5 deletions tests/sspi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ def test_sec_context(self):

token_buf = create_string_buffer(10000)
bufs = [(pytds.sspi.SECBUFFER_TOKEN, token_buf)]
server = settings.HOST
if "\\" in server:
server, _ = server.split("\\")
host, _, _ = socket.gethostbyname_ex(server)
target_name = "MSSQLSvc/{0}:1433".format(host)
# getting current host's name
host, _, _ = socket.gethostbyname_ex("")
target_name = f"MSSQLSvc/{host}:1433"
ctx, status, bufs = cred.create_context(
flags=pytds.sspi.ISC_REQ_CONFIDENTIALITY
| pytds.sspi.ISC_REQ_REPLAY_DETECT
Expand Down

0 comments on commit a273130

Please sign in to comment.