Skip to content

Commit

Permalink
Set test config file mode to 600 to prevent warnings (#1398)
Browse files Browse the repository at this point in the history
Prevents the warnings about file permissions in tests:
```
  /home/runner/.local/share/hatch/env/virtual/snowflake-cli-labs/M-xJJ0Mq/integration/lib/python3.10/site-packages/snowflake/connector/config_manager.py:351: UserWarning: Bad owner or permissions on /home/runner/work/snowflake-cli/snowflake-cli/tests_integration/config/plugin_tests/override_plugin_config.toml.
   * To change owner, run `chown $USER "/home/runner/work/snowflake-cli/snowflake-cli/tests_integration/config/plugin_tests/override_plugin_config.toml"`.
   * To restrict permissions, run `chmod 0600 "/home/runner/work/snowflake-cli/snowflake-cli/tests_integration/config/plugin_tests/override_plugin_config.toml"`.
  
    warn(f"Bad owner or permissions on {str(filep)}{chmod_message}")
```

Since Git doesn't store file permissions (only the executable bit), the files get checked out as `644` so we need to remove group and public read access.
  • Loading branch information
sfc-gh-fcampbell committed Aug 1, 2024
1 parent ebee456 commit 948d5c7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/testing_utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_snowcli_config():
test_config = TEST_DIR / "test.toml"
with _named_temporary_file(suffix=".toml") as p:
p.write_text(test_config.read_text())
p.chmod(0o777)
p.chmod(0o600) # Make config file private
yield p


Expand Down
21 changes: 21 additions & 0 deletions tests_integration/config/world_readable.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2024 Snowflake Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Same as connection_configs.toml but its mode bits
# don't get set to 644 during tests (to test the warning mechanism)

[connections.default]
[connections.integration]
schema = "public"
role = "INTEGRATION_TESTS"
4 changes: 4 additions & 0 deletions tests_integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

TEST_DIR = Path(__file__).parent
DEFAULT_TEST_CONFIG = "connection_configs.toml"
WORLD_READABLE_CONFIG = "world_readable.toml"


@dataclass
Expand All @@ -70,6 +71,9 @@ def test_snowcli_config_provider():
with tempfile.TemporaryDirectory() as td:
temp_dst = Path(td) / "config"
shutil.copytree(TEST_DIR / "config", temp_dst)
for config_file in temp_dst.glob("**/*.toml"):
if config_file.name != WORLD_READABLE_CONFIG:
config_file.chmod(0o600) # Make config file private
yield TestConfigProvider(temp_dst)


Expand Down
4 changes: 4 additions & 0 deletions tests_integration/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
import pytest
from snowflake.connector.compat import IS_WINDOWS

from tests_integration.conftest import WORLD_READABLE_CONFIG


@pytest.mark.integration
def test_config_file_permissions_warning(runner, recwarn):
runner.use_config(WORLD_READABLE_CONFIG)

result = runner.invoke_with_config(["connection", "list"])
assert result.exit_code == 0, result.output

Expand Down

0 comments on commit 948d5c7

Please sign in to comment.