@@ -193,6 +193,17 @@ def test_keep_alive_heartbeat_frequency_min(conn_cnx):
193193 assert cnx .client_session_keep_alive_heartbeat_frequency == 900
194194
195195
196+ @pytest .mark .skipolddriver
197+ def test_platform_detection_timeout (conn_cnx ):
198+ """Tests platform detection timeout.
199+
200+ Creates a connection with platform_detection_timeout parameter.
201+ """
202+
203+ with conn_cnx (platform_detection_timeout_seconds = 2.5 ) as cnx :
204+ assert cnx .platform_detection_timeout_seconds == 2.5
205+
206+
196207def test_bad_db (conn_cnx ):
197208 """Attempts to use a bad DB."""
198209 with conn_cnx (database = "baddb" ) as cnx :
@@ -1399,3 +1410,80 @@ def test_file_utils_sanity_check():
13991410 conn = create_connection ("default" )
14001411 assert hasattr (conn ._file_operation_parser , "parse_file_operation" )
14011412 assert hasattr (conn ._stream_downloader , "download_as_stream" )
1413+
1414+
1415+ @pytest .mark .skipolddriver
1416+ @pytest .mark .skipif (IS_WINDOWS , reason = "chmod doesn't work on Windows" )
1417+ def test_unsafe_skip_file_permissions_check_skips_config_permissions_check (
1418+ db_parameters , tmp_path
1419+ ):
1420+ """Test that unsafe_skip_file_permissions_check flag bypasses permission checks on config files."""
1421+ # Write config file and set unsafe permissions (readable by others)
1422+ tmp_config_file = tmp_path / "config.toml"
1423+ tmp_config_file .write_text ("[log]\n " "save_logs = false\n " 'level = "INFO"\n ' )
1424+ tmp_config_file .chmod (stat .S_IRUSR | stat .S_IWUSR | stat .S_IROTH )
1425+
1426+ def _run_select_1 (unsafe_skip_file_permissions_check : bool ):
1427+ warnings .simplefilter ("always" )
1428+ # Connect directly with db_parameters, using custom config file path
1429+ # We need to modify CONFIG_MANAGER to point to our test file
1430+ from snowflake .connector .config_manager import CONFIG_MANAGER
1431+
1432+ original_file_path = CONFIG_MANAGER .file_path
1433+ try :
1434+ CONFIG_MANAGER .file_path = tmp_config_file
1435+ CONFIG_MANAGER .conf_file_cache = None # Force re-read
1436+ with snowflake .connector .connect (
1437+ ** db_parameters ,
1438+ unsafe_skip_file_permissions_check = unsafe_skip_file_permissions_check ,
1439+ ) as conn :
1440+ with conn .cursor () as cur :
1441+ result = cur .execute ("select 1;" ).fetchall ()
1442+ assert result == [(1 ,)]
1443+ finally :
1444+ CONFIG_MANAGER .file_path = original_file_path
1445+ CONFIG_MANAGER .conf_file_cache = None
1446+
1447+ # Without the flag - should trigger permission warnings
1448+ with warnings .catch_warnings (record = True ) as warning_list :
1449+ _run_select_1 (unsafe_skip_file_permissions_check = False )
1450+ permission_warnings = [
1451+ w for w in warning_list if "Bad owner or permissions" in str (w .message )
1452+ ]
1453+ assert (
1454+ len (permission_warnings ) > 0
1455+ ), "Expected permission warning when unsafe_skip_file_permissions_check=False"
1456+
1457+ # With the flag - should bypass permission checks and not show warnings
1458+ with warnings .catch_warnings (record = True ) as warning_list :
1459+ _run_select_1 (unsafe_skip_file_permissions_check = True )
1460+ permission_warnings = [
1461+ w for w in warning_list if "Bad owner or permissions" in str (w .message )
1462+ ]
1463+ assert (
1464+ len (permission_warnings ) == 0
1465+ ), "Expected no permission warning when unsafe_skip_file_permissions_check=True"
1466+
1467+
1468+ # The property snowflake_version is newly introduced and therefore should not be tested on old drivers.
1469+ @pytest .mark .skipolddriver
1470+ def test_snowflake_version ():
1471+ import re
1472+
1473+ conn = create_connection ("default" )
1474+ # Assert that conn has a snowflake_version attribute
1475+ assert hasattr (
1476+ conn , "snowflake_version"
1477+ ), "conn should have a snowflake_version attribute"
1478+
1479+ # Assert that conn.snowflake_version is a string.
1480+ assert isinstance (
1481+ conn .snowflake_version , str
1482+ ), f"snowflake_version should be a string, but got { type (conn .snowflake_version )} "
1483+
1484+ # Assert that conn.snowflake_version is in the format of "x.y.z", where
1485+ # x, y and z are numbers.
1486+ version_pattern = r"^\d+\.\d+\.\d+$"
1487+ assert re .match (
1488+ version_pattern , conn .snowflake_version
1489+ ), f"snowflake_version should match pattern 'x.y.z', but got '{ conn .snowflake_version } '"
0 commit comments