diff --git a/tests/testing_utils/fixtures.py b/tests/testing_utils/fixtures.py index 446b6f54b..148326f11 100644 --- a/tests/testing_utils/fixtures.py +++ b/tests/testing_utils/fixtures.py @@ -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 diff --git a/tests_integration/config/world_readable.toml b/tests_integration/config/world_readable.toml new file mode 100644 index 000000000..8ffa81e9e --- /dev/null +++ b/tests_integration/config/world_readable.toml @@ -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" diff --git a/tests_integration/conftest.py b/tests_integration/conftest.py index 6e0f116be..7c360eaef 100644 --- a/tests_integration/conftest.py +++ b/tests_integration/conftest.py @@ -47,6 +47,7 @@ TEST_DIR = Path(__file__).parent DEFAULT_TEST_CONFIG = "connection_configs.toml" +WORLD_READABLE_CONFIG = "world_readable.toml" @dataclass @@ -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) diff --git a/tests_integration/test_config.py b/tests_integration/test_config.py index f15ce3897..0973cf8c5 100644 --- a/tests_integration/test_config.py +++ b/tests_integration/test_config.py @@ -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