diff options
| author | Colin Wilk <colin@wilk.cx> | 2026-06-28 23:24:21 +0200 |
|---|---|---|
| committer | Colin Wilk <colin@wilk.cx> | 2026-06-28 23:24:21 +0200 |
| commit | a0432093db76d7bb462f113d4bbeca0a8f376e95 (patch) | |
| tree | 1a7bd3659d22f07ed3d3dfc035d88913b85d37ed /molecule/default/tests/test_decryption_keys.py | |
| parent | 1143a273413e8c3df0b4c0f553eab30acb0804f8 (diff) | |
| download | ansible-role-borgbackup-a0432093db76d7bb462f113d4bbeca0a8f376e95.tar.gz ansible-role-borgbackup-a0432093db76d7bb462f113d4bbeca0a8f376e95.zip | |
Format python files with ruff
Diffstat (limited to 'molecule/default/tests/test_decryption_keys.py')
| -rw-r--r-- | molecule/default/tests/test_decryption_keys.py | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/molecule/default/tests/test_decryption_keys.py b/molecule/default/tests/test_decryption_keys.py index bd5ff6a..be851f7 100644 --- a/molecule/default/tests/test_decryption_keys.py +++ b/molecule/default/tests/test_decryption_keys.py @@ -1,4 +1,5 @@ """Tests for decryption keys file structure""" + import os import stat import pytest @@ -6,26 +7,26 @@ import pytest def _get_keys_path(): """Get decryption_keys.yml path from molecule environment""" - scenario_dir = os.environ.get('MOLECULE_SCENARIO_DIRECTORY') + scenario_dir = os.environ.get("MOLECULE_SCENARIO_DIRECTORY") if scenario_dir: - return os.path.join(scenario_dir, 'decryption_keys.yml') + return os.path.join(scenario_dir, "decryption_keys.yml") test_dir = os.path.dirname(os.path.abspath(__file__)) - return os.path.join(test_dir, '..', 'decryption_keys.yml') + return os.path.join(test_dir, "..", "decryption_keys.yml") def test_decryption_keys_file_exists(): """Test that decryption_keys.yml exists""" keys_path = _get_keys_path() if not os.path.exists(keys_path): - pytest.skip('decryption_keys.yml not yet generated') + pytest.skip("decryption_keys.yml not yet generated") def test_decryption_keys_file_permissions(): """Test that decryption_keys.yml has secure permissions""" keys_path = _get_keys_path() if not os.path.exists(keys_path): - pytest.skip('decryption_keys.yml not yet generated') + pytest.skip("decryption_keys.yml not yet generated") file_stat = os.stat(keys_path) file_mode = stat.S_IMODE(file_stat.st_mode) @@ -38,12 +39,12 @@ def test_decryption_keys_structure_single_repo(): """Test single-repo hosts have correct key format""" keys_path = _get_keys_path() if not os.path.exists(keys_path): - pytest.skip('decryption_keys.yml not yet generated') + pytest.skip("decryption_keys.yml not yet generated") - with open(keys_path, 'r') as f: + with open(keys_path, "r") as f: content = f.read() - assert 'borg-client_borg-client:' in content, ( + assert "borg-client_borg-client:" in content, ( "Single repo host should have key named 'hostname_repo_name'" ) @@ -52,15 +53,15 @@ def test_decryption_keys_structure_multi_repo(): """Test multi-instance hosts have correct key format""" keys_path = _get_keys_path() if not os.path.exists(keys_path): - pytest.skip('decryption_keys.yml not yet generated') + pytest.skip("decryption_keys.yml not yet generated") - with open(keys_path, 'r') as f: + with open(keys_path, "r") as f: content = f.read() - assert 'borg-client-multi_configs:' in content, ( + assert "borg-client-multi_configs:" in content, ( "Multi-instance host should have key for 'configs' repo" ) - assert 'borg-client-multi_home-data:' in content, ( + assert "borg-client-multi_home-data:" in content, ( "Multi-instance host should have key for 'home-data' repo" ) @@ -69,13 +70,13 @@ def test_decryption_keys_multi_instance_separate_entries(): """Test multi-instance hosts have separate keys for each repo""" keys_path = _get_keys_path() if not os.path.exists(keys_path): - pytest.skip('decryption_keys.yml not yet generated') + pytest.skip("decryption_keys.yml not yet generated") - with open(keys_path, 'r') as f: + with open(keys_path, "r") as f: content = f.read() - configs_count = content.count('borg-client-multi_configs:') - home_data_count = content.count('borg-client-multi_home-data:') + configs_count = content.count("borg-client-multi_configs:") + home_data_count = content.count("borg-client-multi_home-data:") assert configs_count == 1, ( f"configs key should appear exactly once, found {configs_count}" @@ -89,13 +90,13 @@ def test_decryption_keys_contain_paper_key_format(): """Test that decryption keys use borg paper key format""" keys_path = _get_keys_path() if not os.path.exists(keys_path): - pytest.skip('decryption_keys.yml not yet generated') + pytest.skip("decryption_keys.yml not yet generated") - with open(keys_path, 'r') as f: + with open(keys_path, "r") as f: content = f.read() - assert 'BORG PAPER KEY' in content, ( - 'Decryption keys should contain borg paper key format' + assert "BORG PAPER KEY" in content, ( + "Decryption keys should contain borg paper key format" ) @@ -103,15 +104,15 @@ def test_decryption_keys_all_hosts_present(): """Test that all expected hosts have keys""" keys_path = _get_keys_path() if not os.path.exists(keys_path): - pytest.skip('decryption_keys.yml not yet generated') + pytest.skip("decryption_keys.yml not yet generated") - with open(keys_path, 'r') as f: + with open(keys_path, "r") as f: content = f.read() expected_keys = [ - 'borg-client_borg-client:', - 'borg-client-multi_configs:', - 'borg-client-multi_home-data:', + "borg-client_borg-client:", + "borg-client-multi_configs:", + "borg-client-multi_home-data:", ] for key in expected_keys: @@ -122,11 +123,11 @@ def test_no_keys_for_disabled_export(): """Test that no decryption keys are exported when disabled""" keys_path = _get_keys_path() if not os.path.exists(keys_path): - pytest.skip('decryption_keys.yml not yet generated') + pytest.skip("decryption_keys.yml not yet generated") - with open(keys_path, 'r') as f: + with open(keys_path, "r") as f: content = f.read() - assert 'borg-client-2_borg-client-2:' not in content, ( - 'Keys should not be exported for borg-client-2 (export disabled)' + assert "borg-client-2_borg-client-2:" not in content, ( + "Keys should not be exported for borg-client-2 (export disabled)" ) |