Skip to content

Commit 0fd4150

Browse files
sfc-gh-pbulawasfc-gh-pczajka
authored andcommitted
SNOW-1922893: Remove Windows permissions check (#2173)
1 parent 2f4c4fb commit 0fd4150

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/snowflake/connector/config_manager.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ def read_config(
330330
continue
331331

332332
if (
333-
sliceoptions.check_permissions # Skip checking if this file couldn't hold sensitive information
333+
not IS_WINDOWS # Skip checking on Windows
334+
and sliceoptions.check_permissions # Skip checking if this file couldn't hold sensitive information
334335
# Same check as openssh does for permissions
335336
# https://github.com/openssh/openssh-portable/blob/2709809fd616a0991dc18e3a58dea10fb383c3f0/readconf.c#LL2264C1-L2264C1
336337
and filep.stat().st_mode & READABLE_BY_OTHERS != 0
@@ -341,12 +342,7 @@ def read_config(
341342
and filep.stat().st_uid != os.getuid()
342343
)
343344
):
344-
# for non-Windows, suggest change to 0600 permissions.
345-
chmod_message = (
346-
f'.\n * To change owner, run `chown $USER "{str(filep)}"`.\n * To restrict permissions, run `chmod 0600 "{str(filep)}"`.\n'
347-
if not IS_WINDOWS
348-
else ""
349-
)
345+
chmod_message = f'.\n * To change owner, run `chown $USER "{str(filep)}"`.\n * To restrict permissions, run `chmod 0600 "{str(filep)}"`.\n'
350346

351347
warn(f"Bad owner or permissions on {str(filep)}{chmod_message}")
352348
LOGGER.debug(f"reading configuration file from {str(filep)}")

test/unit/test_configmanager.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ def test_warn_config_file_owner(tmp_path, monkeypatch):
575575
)
576576

577577

578+
@pytest.mark.skipif(IS_WINDOWS, reason="chmod doesn't work on Windows")
578579
def test_warn_config_file_permissions(tmp_path):
579580
c_file = tmp_path / "config.toml"
580581
c1 = ConfigManager(file_path=c_file, name="root_parser")
@@ -590,17 +591,30 @@ def test_warn_config_file_permissions(tmp_path):
590591
with warnings.catch_warnings(record=True) as c:
591592
assert c1["b"] is True
592593
assert len(c) == 1
593-
chmod_message = (
594-
f'.\n * To change owner, run `chown $USER "{str(c_file)}"`.\n * To restrict permissions, run `chmod 0600 "{str(c_file)}"`.\n'
595-
if not IS_WINDOWS
596-
else ""
597-
)
594+
chmod_message = f'.\n * To change owner, run `chown $USER "{str(c_file)}"`.\n * To restrict permissions, run `chmod 0600 "{str(c_file)}"`.\n'
598595
assert (
599596
str(c[0].message)
600597
== f"Bad owner or permissions on {str(c_file)}" + chmod_message
601598
)
602599

603600

601+
@pytest.mark.skipif(not IS_WINDOWS, reason="Windows specific test")
602+
def test_warn_config_file_permissions_windows(tmp_path):
603+
c_file = tmp_path / "config.toml"
604+
c1 = ConfigManager(file_path=c_file, name="root_parser")
605+
c1.add_option(name="b", parse_str=lambda e: e.lower() == "true")
606+
c_file.write_text(
607+
dedent(
608+
"""\
609+
b = true
610+
"""
611+
)
612+
)
613+
with warnings.catch_warnings(record=True) as c:
614+
assert c1["b"] is True
615+
assert len(c) == 0
616+
617+
604618
@pytest.mark.skipif(IS_WINDOWS, reason="chmod doesn't work on Windows")
605619
def test_log_debug_config_file_parent_dir_permissions(tmp_path, caplog):
606620
tmp_dir = tmp_path / "tmp_dir"

0 commit comments

Comments
 (0)