Skip to content

Commit 6295642

Browse files
authored
feat: Not allow local resource management by default (#1359)
<!-- Mandatory: Provide a clear, concise description of the changes and their purpose --> AAP-48659 asks to remove ALLOW_LOCAL_RESOURCE_MANAGEMENT in EDA. This flag is no longer used across AAP. <!-- If applicable, provide a link to the issue that is being addressed --> https://issues.redhat.com/browse/AAP-48659 <!-- What is being changed? --> This PR converts ALLOW_LOCAL_RESOURCE_MANAGEMENT to an internal flag. The default value is False meaning EDA is not allowed to create/modify shared resources. PDE does not need to manipulate the flag. The flag is not completely removed for development purpose. It can be turn on to run EDA standalone. <!-- Why is this change needed? --> <!-- How does this change address the issue? --> <!-- Does this change introduce any new dependencies, blockers or breaking changes? --> <!-- How it can be tested? -->
1 parent b072220 commit 6295642

File tree

12 files changed

+81
-18
lines changed

12 files changed

+81
-18
lines changed

src/aap_eda/settings/defaults.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,12 @@
220220
ANSIBLE_BASE_JWT_VALIDATE_CERT: bool = False
221221
ANSIBLE_BASE_JWT_KEY: str = "https://localhost"
222222

223+
# Default Not allow local resource management.
224+
# Ignore what is set in DAB.
225+
# Can be changed via ENV
226+
ALLOW_LOCAL_RESOURCE_MANAGEMENT: bool = False
227+
223228
# These settings have defaults in DAB
224-
# ALLOW_LOCAL_RESOURCE_MANAGEMENT
225229
# RESOURCE_SERVICE_PATH
226230
# RESOURCE_SERVER_SYNC_ENABLED
227231
# ENABLE_SERVICE_BACKED_SSO

src/aap_eda/settings/development_defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
ANSIBLE_BASE_MANAGED_ROLE_REGISTRY = {}
2121
ANSIBLE_BASE_JWT_KEY = "https://localhost"
2222
ANSIBLE_BASE_JWT_VALIDATE_CERT = False
23-
ALLOW_LOCAL_RESOURCE_MANAGEMENT: True
23+
ALLOW_LOCAL_RESOURCE_MANAGEMENT = True
2424

2525
RESOURCE_SERVER = {
2626
"URL": None,

tests/integration/api/test_organization.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def test_list_organizations_filter_by_ansible_id(
100100

101101
@pytest.mark.django_db
102102
def test_create_organization(
103+
use_local_resource_setting,
103104
base_client: APIClient,
104105
super_user: models.User,
105106
):
@@ -152,6 +153,7 @@ def test_retrieve_organization_not_exist(admin_client: APIClient):
152153

153154
@pytest.mark.django_db
154155
def test_partial_update_organization_success(
156+
use_local_resource_setting,
155157
new_organization: models.Organization,
156158
superuser_client: APIClient,
157159
):
@@ -180,6 +182,7 @@ def test_partial_update_organization_forbidden(
180182

181183
@pytest.mark.django_db
182184
def test_partial_update_default_organization_exception(
185+
use_local_resource_setting,
183186
default_organization: models.Organization,
184187
superuser_client: APIClient,
185188
):
@@ -197,7 +200,9 @@ def test_partial_update_default_organization_exception(
197200

198201
@pytest.mark.django_db
199202
def test_delete_organization_success(
200-
new_organization: models.Organization, superuser_client: APIClient
203+
use_local_resource_setting,
204+
new_organization: models.Organization,
205+
superuser_client: APIClient,
201206
):
202207
response = superuser_client.delete(
203208
f"{api_url_v1}/organizations/{new_organization.id}/"
@@ -212,7 +217,9 @@ def test_delete_organization_success(
212217

213218
@pytest.mark.django_db
214219
def test_delete_organization_conflict(
215-
default_organization: models.Organization, admin_client: APIClient
220+
use_local_resource_setting,
221+
default_organization: models.Organization,
222+
admin_client: APIClient,
216223
):
217224
response = admin_client.delete(
218225
f"{api_url_v1}/organizations/{default_organization.id}/"
@@ -233,7 +240,9 @@ def test_delete_organization_forbidden(
233240

234241

235242
@pytest.mark.django_db
236-
def test_delete_organization_not_exist(admin_client: APIClient):
243+
def test_delete_organization_not_exist(
244+
use_local_resource_setting, admin_client: APIClient
245+
):
237246
response = admin_client.delete(f"{api_url_v1}/organizations/100/")
238247
assert response.status_code == status.HTTP_404_NOT_FOUND
239248

tests/integration/api/test_root.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
def test_v1_root(admin_client, request, expected_slugs, use_shared_resource):
9595
if use_shared_resource:
9696
request.getfixturevalue("use_shared_resource_setting")
97+
else:
98+
request.getfixturevalue("use_local_resource_setting")
9799
response = admin_client.get(f"{api_url_v1}/")
98100
assert response.status_code == 200
99101
assert len(response.data) == len(expected_slugs)

tests/integration/api/test_team.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def test_list_teams_filter_by_ansible_id(
8888

8989
@pytest.mark.django_db
9090
def test_create_team(
91+
use_local_resource_setting,
9192
default_organization: models.Organization,
9293
admin_client: APIClient,
9394
):
@@ -123,7 +124,6 @@ def test_create_team_forbidden(
123124

124125
@pytest.mark.django_db
125126
def test_create_team_unique_name_constraint(
126-
use_shared_resource_setting,
127127
default_organization: models.Organization,
128128
default_team: models.Team,
129129
admin_client: APIClient,
@@ -155,6 +155,7 @@ def test_retrieve_team_not_exist(admin_client: APIClient):
155155

156156
@pytest.mark.django_db
157157
def test_partial_update_team(
158+
use_local_resource_setting,
158159
default_team: models.Team,
159160
admin_client: APIClient,
160161
):
@@ -183,7 +184,9 @@ def test_partial_update_team_forbidden(
183184

184185
@pytest.mark.django_db
185186
def test_delete_team_success(
186-
default_team: models.Team, admin_client: APIClient
187+
use_local_resource_setting,
188+
default_team: models.Team,
189+
admin_client: APIClient,
187190
):
188191
response = admin_client.delete(f"{api_url_v1}/teams/{default_team.id}/")
189192
assert response.status_code == status.HTTP_204_NO_CONTENT
@@ -202,7 +205,9 @@ def test_delete_team_forbidden(
202205

203206

204207
@pytest.mark.django_db
205-
def test_delete_team_not_exist(admin_client: APIClient):
208+
def test_delete_team_not_exist(
209+
use_local_resource_setting, admin_client: APIClient
210+
):
206211
response = admin_client.delete(f"{api_url_v1}/teams/100/")
207212
assert response.status_code == status.HTTP_404_NOT_FOUND
208213

tests/integration/api/test_user.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ def test_retrieve_current_user_unauthenticated(base_client: APIClient):
103103

104104

105105
@pytest.mark.django_db
106-
def test_update_current_user(admin_client: APIClient, admin_user: models.User):
106+
def test_update_current_user(
107+
use_local_resource_setting,
108+
admin_client: APIClient,
109+
admin_user: models.User,
110+
):
107111
response = admin_client.patch(
108112
f"{api_url_v1}/users/me/",
109113
data={
@@ -135,7 +139,9 @@ def test_update_current_user_forbidden(
135139

136140
@pytest.mark.django_db
137141
def test_update_current_user_password(
138-
admin_client: APIClient, admin_user: models.User
142+
use_local_resource_setting,
143+
admin_client: APIClient,
144+
admin_user: models.User,
139145
):
140146
response = admin_client.patch(
141147
f"{api_url_v1}/users/me/",
@@ -151,6 +157,7 @@ def test_update_current_user_password(
151157

152158
@pytest.mark.django_db
153159
def test_update_current_user_username_fail(
160+
use_local_resource_setting,
154161
admin_client: APIClient,
155162
admin_user: models.User,
156163
admin_info: dict,
@@ -171,7 +178,7 @@ def test_update_current_user_username_fail(
171178

172179

173180
@pytest.mark.django_db
174-
def test_create_user(admin_client: APIClient):
181+
def test_create_user(use_local_resource_setting, admin_client: APIClient):
175182
create_user_data = {
176183
"username": "test.user",
177184
"first_name": "Test",
@@ -205,7 +212,6 @@ def test_create_user_forbidden(
205212

206213
@pytest.mark.django_db
207214
def test_update_is_superuser_field(
208-
use_shared_resource_setting,
209215
superuser_client: APIClient,
210216
new_user: models.User,
211217
):
@@ -223,7 +229,6 @@ def test_update_is_superuser_field(
223229

224230
@pytest.mark.django_db
225231
def test_update_superuser_field_as_non_superuser(
226-
use_shared_resource_setting,
227232
admin_client: APIClient,
228233
new_user: models.User,
229234
):
@@ -240,6 +245,7 @@ def test_update_superuser_field_as_non_superuser(
240245

241246
@pytest.mark.django_db
242247
def test_create_superuser(
248+
use_local_resource_setting,
243249
superuser_client: APIClient,
244250
user_api_client: APIClient,
245251
org_admin_rd,
@@ -277,7 +283,9 @@ def test_create_superuser(
277283

278284

279285
@pytest.mark.django_db
280-
def test_modify_superuser_as_superuser(superuser_client: APIClient):
286+
def test_modify_superuser_as_superuser(
287+
use_local_resource_setting, superuser_client: APIClient
288+
):
281289
other_user = models.User.objects.create(username="other-user")
282290
assert other_user.is_superuser is False # sanity
283291
url = reverse("user-detail", kwargs={"pk": other_user.pk})
@@ -288,6 +296,7 @@ def test_modify_superuser_as_superuser(superuser_client: APIClient):
288296

289297
@pytest.mark.django_db
290298
def test_modify_superuser_as_org_admin(
299+
use_local_resource_setting,
291300
user_api_client: APIClient,
292301
org_admin_rd,
293302
org_member_rd,
@@ -322,7 +331,7 @@ def test_modify_superuser_as_org_admin(
322331

323332
@pytest.mark.django_db
324333
def test_organization_admin_can_create_user(
325-
default_user, user_api_client, org_admin_rd
334+
use_local_resource_setting, default_user, user_api_client, org_admin_rd
326335
):
327336
create_user_data = {
328337
"username": "test.user",
@@ -431,6 +440,7 @@ def test_list_users_filter_superuser(
431440

432441
@pytest.mark.django_db
433442
def test_partial_update_user(
443+
use_local_resource_setting,
434444
admin_client: APIClient,
435445
admin_user: models.User,
436446
):
@@ -472,6 +482,7 @@ def test_partial_update_user_forbidden(
472482

473483
@pytest.mark.django_db
474484
def test_delete_user(
485+
use_local_resource_setting,
475486
superuser_client: APIClient,
476487
default_user: models.User,
477488
):
@@ -578,6 +589,7 @@ def test_list_users_filter_by_ansible_id(
578589

579590
@pytest.mark.django_db
580591
def test_resources_remain_after_user_delete(
592+
use_local_resource_setting,
581593
base_client: APIClient,
582594
admin_user: models.User,
583595
default_user: models.User,

tests/integration/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,12 @@ def use_shared_resource_setting():
816816
yield
817817

818818

819+
@pytest.fixture
820+
def use_local_resource_setting():
821+
with override_settings(ALLOW_LOCAL_RESOURCE_MANAGEMENT=True):
822+
yield
823+
824+
819825
# fixture for a running redis server
820826
@pytest.fixture
821827
def default_credential_type() -> models.CredentialType:

tests/integration/dab_rbac/test_crud_permissions.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def get_detail_url(obj, skip_if_not_found=False):
4141
@pytest.mark.django_db
4242
@pytest.mark.parametrize("model", permission_registry.all_registered_models)
4343
def test_add_permissions(
44+
use_local_resource_setting,
4445
request,
4546
model,
4647
cls_factory,
@@ -163,7 +164,13 @@ def test_view_permissions(
163164
@pytest.mark.django_db
164165
@pytest.mark.parametrize("model", permission_registry.all_registered_models)
165166
def test_change_permissions(
166-
model, cls_factory, default_user, user_client, give_obj_perm, request
167+
use_local_resource_setting,
168+
model,
169+
cls_factory,
170+
default_user,
171+
user_client,
172+
give_obj_perm,
173+
request,
167174
):
168175
model_name = cls_factory.get_model_name(model)
169176
obj = cls_factory.get_fixture_object(request, model_name)
@@ -205,7 +212,13 @@ def test_change_permissions(
205212
@pytest.mark.django_db
206213
@pytest.mark.parametrize("model", permission_registry.all_registered_models)
207214
def test_delete_permissions(
208-
model, cls_factory, default_user, user_client, give_obj_perm, request
215+
use_local_resource_setting,
216+
model,
217+
cls_factory,
218+
default_user,
219+
user_client,
220+
give_obj_perm,
221+
request,
209222
):
210223
model_name = cls_factory.get_model_name(model)
211224
obj = cls_factory.get_fixture_object(request, model_name)

tests/integration/dab_rbac/test_organization.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ def test_create_with_default_org(cls_factory, model, admin_client, request):
7373
@pytest.mark.django_db
7474
@pytest.mark.parametrize("model", ORG_MODELS)
7575
def test_create_with_custom_org(
76-
cls_factory, model, superuser_client, request, new_organization
76+
use_local_resource_setting,
77+
cls_factory,
78+
model,
79+
superuser_client,
80+
request,
81+
new_organization,
7782
):
7883
model_name = cls_factory.get_model_name(model)
7984
model_obj = cls_factory.get_fixture_object(request, model_name)

tests/integration/dab_rbac/test_related_permissions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@pytest.mark.django_db
2121
@pytest.mark.parametrize("model", permission_registry.all_registered_models)
2222
def test_related_organization_edit_access_control(
23+
use_local_resource_setting,
2324
cls_factory,
2425
default_user,
2526
user_client,

0 commit comments

Comments
 (0)