Skip to content

Commit

Permalink
fix mssql test
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmedal committed Feb 12, 2025
1 parent b7cf6ef commit 992f42a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 1 addition & 10 deletions ibis-server/app/model/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,7 @@ def get_mssql_connection(cls, info: MSSqlConnectionInfo) -> BaseBackend:
port=info.port.get_secret_value(),
database=info.database.get_secret_value(),
user=info.user.get_secret_value(),
password=(
info.password
and cls._escape_special_characters_for_odbc(
info.password.get_secret_value()
)
),
password=info.password.get_secret_value(),
driver=info.driver,
TDS_Version=info.tds_version,
**info.kwargs if info.kwargs else dict(),
Expand Down Expand Up @@ -197,10 +192,6 @@ def get_trino_connection(info: TrinoConnectionInfo) -> BaseBackend:
password=(info.password and info.password.get_secret_value()),
)

@staticmethod
def _escape_special_characters_for_odbc(value: str) -> str:
return "{" + value.replace("}", "}}") + "}"

@staticmethod
def _create_ssl_context(info: ConnectionInfo) -> Optional[ssl.SSLContext]:
ssl_mode = (
Expand Down
12 changes: 11 additions & 1 deletion ibis-server/tests/routers/v2/connector/test_mssql.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import urllib

import orjson
import pandas as pd
Expand Down Expand Up @@ -427,6 +428,15 @@ async def test_password_with_special_characters(client):
assert response.status_code == 200
assert "Microsoft SQL Server 2019" in response.text

connection_url = _to_connection_url(mssql)
response = await client.post(
url=f"{base_url}/metadata/version",
json={"connectionInfo": {"connectionUrl": connection_url}},
)

assert response.status_code == 200
assert "Microsoft SQL Server 2019" in response.text


def _to_connection_info(mssql: SqlServerContainer):
return {
Expand All @@ -441,4 +451,4 @@ def _to_connection_info(mssql: SqlServerContainer):

def _to_connection_url(mssql: SqlServerContainer):
info = _to_connection_info(mssql)
return f"mssql://{info['user']}:{info['password']}@{info['host']}:{info['port']}/{info['database']}?driver=ODBC+Driver+18+for+SQL+Server&TrustServerCertificate=YES"
return f"mssql://{info['user']}:{urllib.parse.quote_plus(info['password'])}@{info['host']}:{info['port']}/{info['database']}?driver=ODBC+Driver+18+for+SQL+Server&TrustServerCertificate=YES"

0 comments on commit 992f42a

Please sign in to comment.