qontract-reconcile 0.10.1rc1201__py3-none-any.whl → 0.10.2.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qontract_reconcile-0.10.2.dev1.dist-info/METADATA +500 -0
- {qontract_reconcile-0.10.1rc1201.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/RECORD +14 -132
- {qontract_reconcile-0.10.1rc1201.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/WHEEL +1 -2
- {qontract_reconcile-0.10.1rc1201.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/entry_points.txt +1 -0
- reconcile/aws_account_manager/README.md +5 -0
- reconcile/change_owners/README.md +34 -0
- reconcile/external_resources/manager.py +12 -1
- reconcile/external_resources/model.py +11 -0
- reconcile/glitchtip/README.md +150 -0
- reconcile/gql_definitions/introspection.json +51176 -0
- reconcile/run_integration.py +293 -0
- reconcile/utils/binary.py +2 -2
- reconcile/utils/mr/README.md +198 -0
- reconcile/utils/oc_map.py +2 -2
- tools/qontract_cli.py +0 -0
- qontract_reconcile-0.10.1rc1201.dist-info/METADATA +0 -64
- qontract_reconcile-0.10.1rc1201.dist-info/top_level.txt +0 -3
- reconcile/test/__init__.py +0 -0
- reconcile/test/conftest.py +0 -157
- reconcile/test/fixtures.py +0 -24
- reconcile/test/saas_auto_promotions_manager/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/conftest.py +0 -170
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/conftest.py +0 -115
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/data_keys.py +0 -19
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_desired_state.py +0 -66
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_merge_request_manager.py +0 -86
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_mr_parser.py +0 -352
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_reconciler.py +0 -494
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/conftest.py +0 -25
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_multiple_namespaces.py +0 -37
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_namespace.py +0 -81
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_target.py +0 -61
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_json_path_selector.py +0 -74
- reconcile/test/saas_auto_promotions_manager/test_integration_test.py +0 -52
- reconcile/test/saas_auto_promotions_manager/utils/__init__.py +0 -0
- reconcile/test/test_acs_notifiers.py +0 -393
- reconcile/test/test_acs_policies.py +0 -497
- reconcile/test/test_acs_rbac.py +0 -865
- reconcile/test/test_aggregated_list.py +0 -237
- reconcile/test/test_amtool.py +0 -37
- reconcile/test/test_aws_ami_cleanup.py +0 -230
- reconcile/test/test_aws_ami_share.py +0 -68
- reconcile/test/test_aws_cloudwatch_log_retention.py +0 -434
- reconcile/test/test_aws_iam_keys.py +0 -70
- reconcile/test/test_aws_iam_password_reset.py +0 -35
- reconcile/test/test_aws_support_cases_sos.py +0 -23
- reconcile/test/test_checkpoint.py +0 -178
- reconcile/test/test_cli.py +0 -41
- reconcile/test/test_closedbox_endpoint_monitoring.py +0 -207
- reconcile/test/test_dashdotdb_dora.py +0 -245
- reconcile/test/test_database_access_manager.py +0 -660
- reconcile/test/test_deadmanssnitch.py +0 -290
- reconcile/test/test_gabi_authorized_users.py +0 -72
- reconcile/test/test_gcr_mirror.py +0 -14
- reconcile/test/test_github_org.py +0 -156
- reconcile/test/test_github_repo_invites.py +0 -119
- reconcile/test/test_gitlab_housekeeping.py +0 -333
- reconcile/test/test_gitlab_labeler.py +0 -126
- reconcile/test/test_gitlab_members.py +0 -219
- reconcile/test/test_gitlab_permissions.py +0 -164
- reconcile/test/test_instrumented_wrappers.py +0 -18
- reconcile/test/test_integrations_manager.py +0 -1252
- reconcile/test/test_jenkins_worker_fleets.py +0 -57
- reconcile/test/test_jira_permissions_validator.py +0 -519
- reconcile/test/test_jump_host.py +0 -114
- reconcile/test/test_ldap_users.py +0 -125
- reconcile/test/test_make.py +0 -28
- reconcile/test/test_ocm_additional_routers.py +0 -133
- reconcile/test/test_ocm_clusters.py +0 -798
- reconcile/test/test_ocm_clusters_manifest_updates.py +0 -87
- reconcile/test/test_ocm_machine_pools.py +0 -1103
- reconcile/test/test_ocm_update_recommended_version.py +0 -145
- reconcile/test/test_ocm_upgrade_scheduler_org_updater.py +0 -125
- reconcile/test/test_openshift_base.py +0 -1269
- reconcile/test/test_openshift_cluster_bots.py +0 -240
- reconcile/test/test_openshift_namespace_labels.py +0 -344
- reconcile/test/test_openshift_namespaces.py +0 -256
- reconcile/test/test_openshift_resource.py +0 -443
- reconcile/test/test_openshift_resources_base.py +0 -478
- reconcile/test/test_openshift_saas_deploy.py +0 -188
- reconcile/test/test_openshift_saas_deploy_change_tester.py +0 -308
- reconcile/test/test_openshift_saas_deploy_trigger_cleaner.py +0 -65
- reconcile/test/test_openshift_serviceaccount_tokens.py +0 -282
- reconcile/test/test_openshift_tekton_resources.py +0 -265
- reconcile/test/test_openshift_upgrade_watcher.py +0 -223
- reconcile/test/test_prometheus_rules_tester.py +0 -151
- reconcile/test/test_quay_membership.py +0 -86
- reconcile/test/test_quay_mirror.py +0 -172
- reconcile/test/test_quay_mirror_org.py +0 -82
- reconcile/test/test_quay_repos.py +0 -59
- reconcile/test/test_queries.py +0 -53
- reconcile/test/test_repo_owners.py +0 -47
- reconcile/test/test_requests_sender.py +0 -139
- reconcile/test/test_saasherder.py +0 -1611
- reconcile/test/test_saasherder_allowed_secret_paths.py +0 -125
- reconcile/test/test_secret_reader.py +0 -153
- reconcile/test/test_slack_base.py +0 -183
- reconcile/test/test_slack_usergroups.py +0 -785
- reconcile/test/test_sql_query.py +0 -316
- reconcile/test/test_status_board.py +0 -258
- reconcile/test/test_terraform_aws_route53.py +0 -29
- reconcile/test/test_terraform_cloudflare_dns.py +0 -117
- reconcile/test/test_terraform_cloudflare_resources.py +0 -408
- reconcile/test/test_terraform_cloudflare_users.py +0 -747
- reconcile/test/test_terraform_repo.py +0 -440
- reconcile/test/test_terraform_resources.py +0 -519
- reconcile/test/test_terraform_tgw_attachments.py +0 -1295
- reconcile/test/test_terraform_users.py +0 -152
- reconcile/test/test_terraform_vpc_peerings.py +0 -576
- reconcile/test/test_terraform_vpc_peerings_build_desired_state.py +0 -1434
- reconcile/test/test_three_way_diff_strategy.py +0 -131
- reconcile/test/test_utils_jinja2.py +0 -130
- reconcile/test/test_vault_replication.py +0 -534
- reconcile/test/test_vault_utils.py +0 -47
- reconcile/test/test_version_bump.py +0 -18
- reconcile/test/test_vpc_peerings_validator.py +0 -194
- reconcile/test/test_wrong_region.py +0 -78
- release/__init__.py +0 -0
- release/test_version.py +0 -50
- release/version.py +0 -104
- tools/cli_commands/test/__init__.py +0 -0
- tools/cli_commands/test/conftest.py +0 -332
- tools/cli_commands/test/test_aws_cost_report.py +0 -258
- tools/cli_commands/test/test_cost_management_api.py +0 -326
- tools/cli_commands/test/test_gpg_encrypt.py +0 -235
- tools/cli_commands/test/test_openshift_cost_optimization_report.py +0 -255
- tools/cli_commands/test/test_openshift_cost_report.py +0 -295
- tools/cli_commands/test/test_util.py +0 -70
- tools/test/__init__.py +0 -0
- tools/test/conftest.py +0 -77
- tools/test/test_app_interface_metrics_exporter.py +0 -48
- tools/test/test_erv2.py +0 -80
- tools/test/test_get_container_images.py +0 -230
- tools/test/test_qontract_cli.py +0 -197
- tools/test/test_saas_promotion_state.py +0 -187
- tools/test/test_sd_app_sre_alert_report.py +0 -74
- tools/test/test_sre_checkpoints.py +0 -79
@@ -1,534 +0,0 @@
|
|
1
|
-
from typing import cast
|
2
|
-
|
3
|
-
import pytest
|
4
|
-
|
5
|
-
import reconcile.vault_replication as integ
|
6
|
-
from reconcile.gql_definitions.fragments.vault_secret import VaultSecret
|
7
|
-
from reconcile.gql_definitions.jenkins_configs.jenkins_configs import (
|
8
|
-
AppV1,
|
9
|
-
JenkinsConfigsQueryData,
|
10
|
-
JenkinsConfigV1_JenkinsConfigV1,
|
11
|
-
JenkinsInstanceV1,
|
12
|
-
ResourceV1,
|
13
|
-
)
|
14
|
-
from reconcile.gql_definitions.vault_instances.vault_instances import (
|
15
|
-
VaultReplicationConfigV1_VaultInstanceAuthV1,
|
16
|
-
VaultReplicationConfigV1_VaultInstanceAuthV1_VaultInstanceAuthApproleV1,
|
17
|
-
)
|
18
|
-
from reconcile.gql_definitions.vault_policies import vault_policies
|
19
|
-
from reconcile.test.fixtures import Fixtures
|
20
|
-
from reconcile.utils.vault import (
|
21
|
-
SecretAccessForbidden,
|
22
|
-
SecretNotFound,
|
23
|
-
SecretVersionNotFound,
|
24
|
-
VaultClient,
|
25
|
-
_VaultClient,
|
26
|
-
)
|
27
|
-
|
28
|
-
fxt = Fixtures("vault_replication")
|
29
|
-
|
30
|
-
|
31
|
-
@pytest.fixture
|
32
|
-
def jenkins_config_query_data() -> JenkinsConfigsQueryData:
|
33
|
-
return JenkinsConfigsQueryData(
|
34
|
-
jenkins_configs=[
|
35
|
-
JenkinsConfigV1_JenkinsConfigV1(
|
36
|
-
path="path/to/config",
|
37
|
-
name="jenkins-secrets-config",
|
38
|
-
app=AppV1(
|
39
|
-
name="my-app",
|
40
|
-
),
|
41
|
-
instance=JenkinsInstanceV1(
|
42
|
-
name="jenkins-instance",
|
43
|
-
serverUrl="https://test.net",
|
44
|
-
token=VaultSecret(
|
45
|
-
path="secret_path",
|
46
|
-
field="secret_field",
|
47
|
-
version=None,
|
48
|
-
format=None,
|
49
|
-
),
|
50
|
-
deleteMethod=None,
|
51
|
-
),
|
52
|
-
type="secrets",
|
53
|
-
config=None,
|
54
|
-
config_path=ResourceV1(
|
55
|
-
content="name: 'test_data_name'\n secret-path: 'this/is/a/path'"
|
56
|
-
),
|
57
|
-
),
|
58
|
-
]
|
59
|
-
)
|
60
|
-
|
61
|
-
|
62
|
-
@pytest.fixture
|
63
|
-
def vault_instance_data_invalid_auth() -> VaultReplicationConfigV1_VaultInstanceAuthV1:
|
64
|
-
return VaultReplicationConfigV1_VaultInstanceAuthV1(
|
65
|
-
provider="test",
|
66
|
-
secretEngine="kv_v1",
|
67
|
-
)
|
68
|
-
|
69
|
-
|
70
|
-
@pytest.fixture(autouse=True)
|
71
|
-
def reset_singletons():
|
72
|
-
VaultClient._instance = None
|
73
|
-
|
74
|
-
|
75
|
-
@pytest.fixture
|
76
|
-
def policy_query_data() -> vault_policies.VaultPoliciesQueryData:
|
77
|
-
return vault_policies.VaultPoliciesQueryData(
|
78
|
-
policy=[
|
79
|
-
vault_policies.VaultPolicyV1(
|
80
|
-
name="test-policy",
|
81
|
-
instance=vault_policies.VaultInstanceV1(name="vault-instance"),
|
82
|
-
rules='path "this/is/a/path/*" {\n capabilities = ["create", "read", "update"]\n}\n',
|
83
|
-
)
|
84
|
-
]
|
85
|
-
)
|
86
|
-
|
87
|
-
|
88
|
-
def test_policy_contais_path():
|
89
|
-
policy_paths = ["path1", "path2"]
|
90
|
-
path = "path1"
|
91
|
-
assert integ._policy_contains_path(path, policy_paths) is True
|
92
|
-
|
93
|
-
|
94
|
-
def test_policy_contais_path_false():
|
95
|
-
policy_paths = ["path2", "path3"]
|
96
|
-
path = "path1"
|
97
|
-
assert integ._policy_contains_path(path, policy_paths) is False
|
98
|
-
|
99
|
-
|
100
|
-
def test_check_invalid_paths_ko():
|
101
|
-
path_list = ["path1", "path3"]
|
102
|
-
policy_paths = ["path1", "path2"]
|
103
|
-
with pytest.raises(integ.VaultInvalidPaths):
|
104
|
-
integ.check_invalid_paths(path_list, policy_paths)
|
105
|
-
|
106
|
-
|
107
|
-
def test_check_invalid_paths_ok():
|
108
|
-
path_list = ["path1", "path2"]
|
109
|
-
policy_paths = ["path1", "path2"]
|
110
|
-
integ.check_invalid_paths(path_list, policy_paths)
|
111
|
-
|
112
|
-
|
113
|
-
def test_list_invalid_paths():
|
114
|
-
path_list = ["path1", "path3"]
|
115
|
-
policy_paths = ["path1", "path2"]
|
116
|
-
assert integ.list_invalid_paths(path_list, policy_paths) == ["path3"]
|
117
|
-
|
118
|
-
|
119
|
-
@pytest.fixture
|
120
|
-
def vault_client_test() -> _VaultClient:
|
121
|
-
return cast(_VaultClient, None)
|
122
|
-
|
123
|
-
|
124
|
-
def test_get_jenkins_secret_list_w_content(
|
125
|
-
jenkins_config_query_data: JenkinsConfigsQueryData,
|
126
|
-
vault_client_test: _VaultClient,
|
127
|
-
):
|
128
|
-
assert integ.get_jenkins_secret_list(
|
129
|
-
vault_client_test, "jenkins-instance", jenkins_config_query_data
|
130
|
-
) == [
|
131
|
-
"this/is/a/path",
|
132
|
-
]
|
133
|
-
|
134
|
-
|
135
|
-
@pytest.fixture
|
136
|
-
def vault_instance_data() -> (
|
137
|
-
VaultReplicationConfigV1_VaultInstanceAuthV1_VaultInstanceAuthApproleV1
|
138
|
-
):
|
139
|
-
return VaultReplicationConfigV1_VaultInstanceAuthV1_VaultInstanceAuthApproleV1(
|
140
|
-
provider="approle",
|
141
|
-
secretEngine="kv_v1",
|
142
|
-
roleID=VaultSecret(
|
143
|
-
path="secret/path/role_id",
|
144
|
-
field="role_id",
|
145
|
-
version=None,
|
146
|
-
format=None,
|
147
|
-
),
|
148
|
-
secretID=VaultSecret(
|
149
|
-
path="secret/path/secret_id",
|
150
|
-
field="secret_id",
|
151
|
-
version=None,
|
152
|
-
format=None,
|
153
|
-
),
|
154
|
-
)
|
155
|
-
|
156
|
-
|
157
|
-
def test_get_vault_credentials_invalid_auth_method(
|
158
|
-
vault_instance_data_invalid_auth: VaultReplicationConfigV1_VaultInstanceAuthV1,
|
159
|
-
mocker,
|
160
|
-
):
|
161
|
-
mock_vault_client = mocker.patch(
|
162
|
-
"reconcile.utils.vault._VaultClient", autospec=True
|
163
|
-
)
|
164
|
-
mock_vault_client.return_value.read.side_effect = ["a", "b"]
|
165
|
-
|
166
|
-
with pytest.raises(integ.VaultInvalidAuthMethod):
|
167
|
-
integ.get_vault_credentials(
|
168
|
-
vault_instance_data_invalid_auth, "http://vault.com"
|
169
|
-
)
|
170
|
-
|
171
|
-
|
172
|
-
def test_get_vault_credentials_app_role(
|
173
|
-
vault_instance_data: VaultReplicationConfigV1_VaultInstanceAuthV1_VaultInstanceAuthApproleV1,
|
174
|
-
mocker,
|
175
|
-
):
|
176
|
-
mock_vault_client = mocker.patch(
|
177
|
-
"reconcile.utils.vault._VaultClient", autospec=True
|
178
|
-
)
|
179
|
-
mock_vault_client.return_value.read.side_effect = ["a", "b"]
|
180
|
-
|
181
|
-
assert integ.get_vault_credentials(
|
182
|
-
vault_instance_data, "https://vault-instance.com"
|
183
|
-
) == {
|
184
|
-
"role_id": "a",
|
185
|
-
"secret_id": "b",
|
186
|
-
"server": "https://vault-instance.com",
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
def test_get_policy_paths(policy_query_data: vault_policies.VaultPoliciesQueryData):
|
191
|
-
assert integ.get_policy_paths(
|
192
|
-
"test-policy", "vault-instance", policy_query_data
|
193
|
-
) == ["this/is/a/path/*"]
|
194
|
-
|
195
|
-
|
196
|
-
@pytest.mark.parametrize(
|
197
|
-
"path, vault_list, return_value",
|
198
|
-
[
|
199
|
-
(
|
200
|
-
"app-sre/test/path/{template}-1",
|
201
|
-
[
|
202
|
-
"app-sre/test/path/test-1",
|
203
|
-
"app-sre/test/path/test-2",
|
204
|
-
"app-sre/example/path/test-1",
|
205
|
-
],
|
206
|
-
["app-sre/test/path/test-1"],
|
207
|
-
),
|
208
|
-
(
|
209
|
-
"app-sre/test/path/{template}",
|
210
|
-
[
|
211
|
-
"app-sre/test/path/test-1",
|
212
|
-
"app-sre/test/path/test-2",
|
213
|
-
"app-sre/example/path/test-1",
|
214
|
-
],
|
215
|
-
["app-sre/test/path/test-1", "app-sre/test/path/test-2"],
|
216
|
-
),
|
217
|
-
(
|
218
|
-
"app-sre/{template}/path/{template}",
|
219
|
-
[
|
220
|
-
"app-sre/test/path/test-1",
|
221
|
-
"app-sre/test/path/test-2",
|
222
|
-
"app-sre/example/path/test-1",
|
223
|
-
"app-sre/example/path2/test-1",
|
224
|
-
],
|
225
|
-
[
|
226
|
-
"app-sre/test/path/test-1",
|
227
|
-
"app-sre/test/path/test-2",
|
228
|
-
"app-sre/example/path/test-1",
|
229
|
-
],
|
230
|
-
),
|
231
|
-
(
|
232
|
-
"app-sre/{template}/path/{template}-1",
|
233
|
-
["app-sre/test/path/test-1", "app-sre/test/path/test-2"],
|
234
|
-
["app-sre/test/path/test-1"],
|
235
|
-
),
|
236
|
-
(
|
237
|
-
"app-sre/{template}/path/test-1",
|
238
|
-
["app-sre/test/path/test-1", "app-sre/test/path/test-2"],
|
239
|
-
["app-sre/test/path/test-1"],
|
240
|
-
),
|
241
|
-
(
|
242
|
-
"app-sre/test/pa{th}/test-1",
|
243
|
-
["app-sre/test/path/test-1", "app-sre/test/path/test-2"],
|
244
|
-
["app-sre/test/path/test-1"],
|
245
|
-
),
|
246
|
-
],
|
247
|
-
)
|
248
|
-
def test_get_secrets_from_templated_path(path, vault_list, return_value):
|
249
|
-
assert integ.get_secrets_from_templated_path(path, vault_list) == return_value
|
250
|
-
|
251
|
-
|
252
|
-
def test_get_jenkins_secret_list_templating(mocker):
|
253
|
-
mock_vault_client = mocker.patch(
|
254
|
-
"reconcile.utils.vault._VaultClient", autospec=True
|
255
|
-
)
|
256
|
-
mock_vault_client.list_all.side_effect = [
|
257
|
-
["path/test-1/secret", "path/test-2/secret"]
|
258
|
-
]
|
259
|
-
|
260
|
-
test = fxt.get_anymarkup("jenkins_configs/jenkins_config_insta_path.yaml")
|
261
|
-
assert integ.get_jenkins_secret_list(
|
262
|
-
mock_vault_client, "jenkins-instance", JenkinsConfigsQueryData(**test)
|
263
|
-
) == ["path/test-1/secret", "path/test-2/secret"]
|
264
|
-
|
265
|
-
|
266
|
-
def test_get_policy_paths_real_data():
|
267
|
-
test = fxt.get_anymarkup("vault_policies/vault_policies_query_data.yaml")
|
268
|
-
assert integ.get_policy_paths(
|
269
|
-
"vault-test-policy",
|
270
|
-
"vault-instance",
|
271
|
-
vault_policies.VaultPoliciesQueryData(**test),
|
272
|
-
) == ["path/test-1/*", "path/test-2/*"]
|
273
|
-
|
274
|
-
|
275
|
-
@pytest.mark.parametrize(
|
276
|
-
"dry_run, secret_version, path", [[False, 1, "path"], [True, 1, "path"]]
|
277
|
-
)
|
278
|
-
def test_write_dummy_version(dry_run, secret_version, path, mocker):
|
279
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
280
|
-
|
281
|
-
integ.write_dummy_versions(
|
282
|
-
dry_run=dry_run,
|
283
|
-
dest_vault=vault_client,
|
284
|
-
secret_version=secret_version,
|
285
|
-
path=path,
|
286
|
-
)
|
287
|
-
if not dry_run:
|
288
|
-
vault_client.write.assert_called_once_with(
|
289
|
-
{"path": path, "data": {"dummy": "data"}}, False, True
|
290
|
-
)
|
291
|
-
else:
|
292
|
-
vault_client.write.assert_not_called()
|
293
|
-
|
294
|
-
|
295
|
-
@pytest.mark.parametrize(
|
296
|
-
"dry_run, current_dest_version, current_source_version, path",
|
297
|
-
[[False, 1, 2, "path"], [True, 1, 2, "path"]],
|
298
|
-
)
|
299
|
-
def test_deep_copy_versions(
|
300
|
-
dry_run, current_dest_version, current_source_version, path, mocker
|
301
|
-
):
|
302
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
303
|
-
|
304
|
-
vault_client.read_all_with_version.return_value = [{"test": "data"}, 2]
|
305
|
-
|
306
|
-
integ.deep_copy_versions(
|
307
|
-
dry_run=dry_run,
|
308
|
-
source_vault=vault_client,
|
309
|
-
dest_vault=vault_client,
|
310
|
-
current_dest_version=current_dest_version,
|
311
|
-
current_source_version=current_source_version,
|
312
|
-
path=path,
|
313
|
-
)
|
314
|
-
|
315
|
-
secret_dict = {"path": path, "version": 2}
|
316
|
-
if dry_run:
|
317
|
-
vault_client.read_all_with_version.assert_called_once_with(secret_dict)
|
318
|
-
vault_client.write.assert_not_called()
|
319
|
-
else:
|
320
|
-
write_dict = {"path": path, "data": {"test": "data"}}
|
321
|
-
vault_client.read_all_with_version.assert_called_once_with(secret_dict)
|
322
|
-
vault_client.write.assert_called_once_with(write_dict, False, True)
|
323
|
-
|
324
|
-
|
325
|
-
@pytest.mark.parametrize(
|
326
|
-
"dry_run, current_dest_version, current_source_version, path",
|
327
|
-
[[False, 1, 2, "path"], [True, 1, 2, "path"]],
|
328
|
-
)
|
329
|
-
def test_deep_copy_versions_exception(
|
330
|
-
dry_run, current_dest_version, current_source_version, path, mocker
|
331
|
-
):
|
332
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
333
|
-
write_dummy_versions = mocker.patch(
|
334
|
-
"reconcile.vault_replication.write_dummy_versions", autospec=True
|
335
|
-
)
|
336
|
-
|
337
|
-
vault_client.read_all_with_version.side_effect = SecretVersionNotFound()
|
338
|
-
|
339
|
-
integ.deep_copy_versions(
|
340
|
-
dry_run=dry_run,
|
341
|
-
source_vault=vault_client,
|
342
|
-
dest_vault=vault_client,
|
343
|
-
current_dest_version=current_dest_version,
|
344
|
-
current_source_version=current_source_version,
|
345
|
-
path=path,
|
346
|
-
)
|
347
|
-
|
348
|
-
secret_dict = {"path": path, "version": 2}
|
349
|
-
if dry_run:
|
350
|
-
vault_client.read_all_with_version.assert_called_once_with(secret_dict)
|
351
|
-
write_dummy_versions.assert_called()
|
352
|
-
vault_client.write.assert_not_called()
|
353
|
-
else:
|
354
|
-
vault_client.read_all_with_version.assert_called_once_with(secret_dict)
|
355
|
-
write_dummy_versions.assert_called()
|
356
|
-
|
357
|
-
|
358
|
-
def test_copy_vault_secret_forbidden_access(mocker):
|
359
|
-
dry_run = True
|
360
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
361
|
-
vault_client.read_all_with_version.side_effect = SecretAccessForbidden()
|
362
|
-
|
363
|
-
with pytest.raises(SecretAccessForbidden):
|
364
|
-
integ.copy_vault_secret(
|
365
|
-
dry_run=dry_run,
|
366
|
-
source_vault=vault_client,
|
367
|
-
dest_vault=vault_client,
|
368
|
-
path="path",
|
369
|
-
)
|
370
|
-
|
371
|
-
|
372
|
-
def test_copy_vault_secret_not_found_v2(mocker):
|
373
|
-
dry_run = True
|
374
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
375
|
-
|
376
|
-
vault_client.read_all_with_version.side_effect = [["secret", 2], SecretNotFound()]
|
377
|
-
deep_copy_versions = mocker.patch(
|
378
|
-
"reconcile.vault_replication.deep_copy_versions", autospec=True
|
379
|
-
)
|
380
|
-
|
381
|
-
integ.copy_vault_secret(
|
382
|
-
dry_run=dry_run, source_vault=vault_client, dest_vault=vault_client, path="path"
|
383
|
-
)
|
384
|
-
vault_client.read_all_with_version.assert_called()
|
385
|
-
deep_copy_versions.assert_called()
|
386
|
-
|
387
|
-
|
388
|
-
@pytest.mark.parametrize("dry_run, path", [[False, "path"], [True, "path"]])
|
389
|
-
def test_copy_vault_secret_not_found_v1(dry_run, path, mocker):
|
390
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
391
|
-
|
392
|
-
vault_client.read_all_with_version.side_effect = [
|
393
|
-
["secret", None],
|
394
|
-
SecretNotFound(),
|
395
|
-
["secret", None],
|
396
|
-
]
|
397
|
-
deep_copy_versions = mocker.patch(
|
398
|
-
"reconcile.vault_replication.deep_copy_versions", autospec=True
|
399
|
-
)
|
400
|
-
|
401
|
-
integ.copy_vault_secret(
|
402
|
-
dry_run=dry_run, source_vault=vault_client, dest_vault=vault_client, path="path"
|
403
|
-
)
|
404
|
-
if not dry_run:
|
405
|
-
vault_client.read_all_with_version.assert_called()
|
406
|
-
vault_client.write.assert_called_once_with(
|
407
|
-
{"path": path, "data": "secret"}, False, True
|
408
|
-
)
|
409
|
-
deep_copy_versions.assert_not_called()
|
410
|
-
else:
|
411
|
-
vault_client.read_all_with_version.assert_called()
|
412
|
-
vault_client.write.assert_not_called()
|
413
|
-
deep_copy_versions.assert_not_called()
|
414
|
-
|
415
|
-
|
416
|
-
def test_copy_vault_secret_found_v2(mocker):
|
417
|
-
dry_run = True
|
418
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
419
|
-
|
420
|
-
vault_client.read_all_with_version.side_effect = [["secret", 2], ["secret", 1]]
|
421
|
-
deep_copy_versions = mocker.patch(
|
422
|
-
"reconcile.vault_replication.deep_copy_versions", autospec=True
|
423
|
-
)
|
424
|
-
|
425
|
-
integ.copy_vault_secret(
|
426
|
-
dry_run=dry_run, source_vault=vault_client, dest_vault=vault_client, path="path"
|
427
|
-
)
|
428
|
-
vault_client.read_all_with_version.assert_called()
|
429
|
-
deep_copy_versions.assert_called_once_with(
|
430
|
-
dry_run, vault_client, vault_client, 1, 2, "path"
|
431
|
-
)
|
432
|
-
|
433
|
-
|
434
|
-
def test_copy_vault_secret_found_same_version_v2(mocker):
|
435
|
-
dry_run = True
|
436
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
437
|
-
|
438
|
-
vault_client.read_all_with_version.side_effect = [["secret", 2], ["secret", 2]]
|
439
|
-
deep_copy_versions = mocker.patch(
|
440
|
-
"reconcile.vault_replication.deep_copy_versions", autospec=True
|
441
|
-
)
|
442
|
-
|
443
|
-
integ.copy_vault_secret(
|
444
|
-
dry_run=dry_run, source_vault=vault_client, dest_vault=vault_client, path="path"
|
445
|
-
)
|
446
|
-
vault_client.read_all_with_version.assert_called()
|
447
|
-
deep_copy_versions.assert_not_called()
|
448
|
-
|
449
|
-
|
450
|
-
@pytest.mark.parametrize(
|
451
|
-
"dry_run, path, return_values",
|
452
|
-
[
|
453
|
-
[False, "path", [["secret2", None], ["secret", None], ["secret", None]]],
|
454
|
-
[True, "path", [["secret2", None], ["secret", None], ["secret", None]]],
|
455
|
-
],
|
456
|
-
)
|
457
|
-
def test_copy_vault_secret_found_v1(dry_run, path, return_values, mocker):
|
458
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
459
|
-
|
460
|
-
vault_client.read_all_with_version.side_effect = return_values
|
461
|
-
deep_copy_versions = mocker.patch(
|
462
|
-
"reconcile.vault_replication.deep_copy_versions", autospec=True
|
463
|
-
)
|
464
|
-
|
465
|
-
integ.copy_vault_secret(
|
466
|
-
dry_run=dry_run, source_vault=vault_client, dest_vault=vault_client, path="path"
|
467
|
-
)
|
468
|
-
if not dry_run:
|
469
|
-
vault_client.read_all_with_version.assert_called()
|
470
|
-
vault_client.write.assert_called_once_with(
|
471
|
-
{"path": path, "data": "secret"}, False, True
|
472
|
-
)
|
473
|
-
deep_copy_versions.assert_not_called()
|
474
|
-
else:
|
475
|
-
vault_client.read_all_with_version.assert_called()
|
476
|
-
vault_client.write.assert_not_called()
|
477
|
-
|
478
|
-
|
479
|
-
@pytest.mark.parametrize(
|
480
|
-
"dry_run, path, return_values",
|
481
|
-
[
|
482
|
-
[False, "path", [["secret", None], ["secret", None], ["secret", None]]],
|
483
|
-
[True, "path", [["secret", None], ["secret", None], ["secret", None]]],
|
484
|
-
],
|
485
|
-
)
|
486
|
-
def test_copy_vault_secret_found_v1_same_value(dry_run, path, return_values, mocker):
|
487
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
488
|
-
|
489
|
-
vault_client.read_all_with_version.side_effect = return_values
|
490
|
-
|
491
|
-
integ.copy_vault_secret(
|
492
|
-
dry_run=dry_run, source_vault=vault_client, dest_vault=vault_client, path="path"
|
493
|
-
)
|
494
|
-
if not dry_run:
|
495
|
-
vault_client.read_all_with_version.assert_called()
|
496
|
-
vault_client.write.assert_not_called()
|
497
|
-
else:
|
498
|
-
vault_client.read_all_with_version.assert_called()
|
499
|
-
vault_client.write.assert_not_called()
|
500
|
-
|
501
|
-
|
502
|
-
def test_get_policy_secret_list(mocker):
|
503
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
504
|
-
vault_client.list_all.side_effect = [
|
505
|
-
["policy/path/1/secret1", "policy/path/1/secret2"],
|
506
|
-
["policy/path/2/secret1", "policy/path/2/secret2"],
|
507
|
-
]
|
508
|
-
|
509
|
-
assert set(
|
510
|
-
integ.get_policy_secret_list(
|
511
|
-
vault_client,
|
512
|
-
["policy/path/1/*", "policy/path/2/*", "policy/p-a_th/3/secret1_1-1"],
|
513
|
-
)
|
514
|
-
) == {
|
515
|
-
"policy/path/1/secret1",
|
516
|
-
"policy/path/1/secret2",
|
517
|
-
"policy/path/2/secret1",
|
518
|
-
"policy/path/2/secret2",
|
519
|
-
"policy/p-a_th/3/secret1_1-1",
|
520
|
-
}
|
521
|
-
|
522
|
-
|
523
|
-
@pytest.mark.parametrize(
|
524
|
-
"paths",
|
525
|
-
[
|
526
|
-
["policy/path*"],
|
527
|
-
["policy/p*th"],
|
528
|
-
["policy/+/p*th"],
|
529
|
-
],
|
530
|
-
)
|
531
|
-
def test_get_policy_secret_list_failure(paths, mocker):
|
532
|
-
vault_client = mocker.patch("reconcile.utils.vault._VaultClient", autospec=True)
|
533
|
-
with pytest.raises(integ.VaultInvalidPaths):
|
534
|
-
integ.get_policy_secret_list(vault_client, paths)
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import importlib
|
2
|
-
import os
|
3
|
-
import time
|
4
|
-
from unittest.mock import (
|
5
|
-
MagicMock,
|
6
|
-
patch,
|
7
|
-
)
|
8
|
-
|
9
|
-
import pytest
|
10
|
-
|
11
|
-
from reconcile.utils import vault
|
12
|
-
|
13
|
-
|
14
|
-
class SleepCalled(Exception):
|
15
|
-
pass
|
16
|
-
|
17
|
-
|
18
|
-
class testVaultClient(vault._VaultClient): # pylint: disable=W0223
|
19
|
-
def __init__(self): # pylint: disable=W0231
|
20
|
-
pass
|
21
|
-
|
22
|
-
|
23
|
-
class TestVaultUtils:
|
24
|
-
@staticmethod
|
25
|
-
def test_vault_auto_refresh_env():
|
26
|
-
os.environ["VAULT_AUTO_REFRESH_INTERVAL"] = "1"
|
27
|
-
importlib.reload(vault)
|
28
|
-
assert vault.VAULT_AUTO_REFRESH_INTERVAL == 1
|
29
|
-
|
30
|
-
@staticmethod
|
31
|
-
def test_vault_auto_refresh_no_env():
|
32
|
-
del os.environ["VAULT_AUTO_REFRESH_INTERVAL"]
|
33
|
-
assert os.getenv("VAULT_AUTO_REFRESH_INTERVAL") is None
|
34
|
-
importlib.reload(vault)
|
35
|
-
assert vault.VAULT_AUTO_REFRESH_INTERVAL == 600
|
36
|
-
|
37
|
-
@staticmethod
|
38
|
-
@patch.object(time, "sleep")
|
39
|
-
def test_sleep_is_called(sleep):
|
40
|
-
sleep.side_effect = SleepCalled
|
41
|
-
|
42
|
-
testVaultClient._refresh_client_auth = MagicMock()
|
43
|
-
|
44
|
-
client = testVaultClient()
|
45
|
-
|
46
|
-
with pytest.raises(SleepCalled):
|
47
|
-
client._auto_refresh_client_auth()
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
|
3
|
-
import packaging.version as pep440
|
4
|
-
import pkg_resources
|
5
|
-
import pytest
|
6
|
-
import requests
|
7
|
-
|
8
|
-
|
9
|
-
@pytest.mark.skipif(
|
10
|
-
os.getuid() != 0,
|
11
|
-
reason="This test is only for CI environments",
|
12
|
-
)
|
13
|
-
def test_version_bump():
|
14
|
-
current_version = pkg_resources.get_distribution("qontract-reconcile").version
|
15
|
-
pypi_version = requests.get(
|
16
|
-
"https://pypi.org/pypi/qontract-reconcile/json", timeout=60
|
17
|
-
).json()["info"]["version"]
|
18
|
-
assert pep440.Version(current_version) > pep440.Version(pypi_version)
|