|
23 | 23 |
|
24 | 24 | import os |
25 | 25 |
|
| 26 | +from configparser import ConfigParser |
26 | 27 | from mock import patch |
27 | 28 | import pytest |
28 | 29 |
|
29 | 30 | from databricks_cli.configure.provider import DatabricksConfig, DEFAULT_SECTION, \ |
30 | 31 | update_and_persist_config, get_config_for_profile, get_config, \ |
31 | 32 | set_config_provider, ProfileConfigProvider, _get_path, DatabricksConfigProvider,\ |
32 | | - SparkTaskContextConfigProvider |
| 33 | + SparkTaskContextConfigProvider, _overwrite_config |
33 | 34 | from databricks_cli.utils import InvalidConfigurationError |
34 | 35 |
|
35 | 36 |
|
| 37 | + |
| 38 | + |
36 | 39 | TEST_HOST = 'https://test.cloud.databricks.com' |
37 | 40 | |
38 | 41 | TEST_PASSWORD = 'banana' # NOQA |
@@ -246,3 +249,25 @@ def test_mlflow_config_constructor(): |
246 | 249 | assert conf.password == TEST_PASSWORD |
247 | 250 | assert conf.token == TEST_TOKEN |
248 | 251 | assert conf.insecure is False |
| 252 | + |
| 253 | +def test_overwrite_config_creates_file_with_correct_permission(): |
| 254 | + config_path = _get_path() |
| 255 | + |
| 256 | + assert not os.path.exists(config_path) |
| 257 | + _overwrite_config(ConfigParser()) |
| 258 | + assert os.path.exists(config_path) |
| 259 | + |
| 260 | + # assert mode 600 ie owner only can read write |
| 261 | + assert os.stat(config_path).st_mode == 0o100600 |
| 262 | + |
| 263 | + |
| 264 | +def test_overwrite_config_overwrites_permissions_to_600(): |
| 265 | + config_path = _get_path() |
| 266 | + file_descriptor = os.open(config_path, os.O_CREAT | os.O_RDWR) |
| 267 | + os.close(file_descriptor) |
| 268 | + |
| 269 | + assert not os.stat(config_path).st_mode == 0o100600 |
| 270 | + |
| 271 | + _overwrite_config(ConfigParser()) |
| 272 | + |
| 273 | + assert os.stat(config_path).st_mode == 0o100600 |
0 commit comments