Skip to content

Commit 73bc66f

Browse files
committed
[req-changes] Added test for shared Credentials
Added migrations to add "view" permissions
1 parent 7c850ab commit 73bc66f

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django.db import migrations
2+
3+
from . import assign_permissions_to_groups
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("config", "0059_zerotier_templates_ow_zt_to_global"),
9+
]
10+
11+
operations = [
12+
migrations.RunPython(
13+
assign_permissions_to_groups, reverse_code=migrations.RunPython.noop
14+
)
15+
]

openwisp_controller/connection/tests/test_admin.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,30 @@ def test_admin_menu_groups(self):
132132
url = reverse(f"admin:{self.app_label}_{model}_changelist")
133133
self.assertContains(response, f' class="mg-link" href="{url}"')
134134

135+
def test_org_admin_create_shared_credentials(self):
136+
self._test_org_admin_create_shareable_object(
137+
path=reverse(f"admin:{self.app_label}_credentials_add"),
138+
model=Credentials,
139+
payload={
140+
"name": "Shared Credentials",
141+
"organization": "",
142+
"connector": "openwisp_controller.connection.connectors.ssh.Ssh",
143+
"params": {
144+
"username": "root",
145+
"password": "password",
146+
"port": 22,
147+
},
148+
},
149+
)
150+
151+
def test_org_admin_view_shared_credentials(self):
152+
credentials = self._create_credentials(organization=None)
153+
self._test_org_admin_view_shareable_object(
154+
path=reverse(
155+
f"admin:{self.app_label}_credentials_change", args=[credentials.pk]
156+
),
157+
)
158+
135159

136160
class TestCommandInlines(TestAdminMixin, CreateConnectionsMixin, TestCase):
137161
config_app_label = "config"

openwisp_controller/connection/tests/test_api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,22 @@ def test_delete_credential_detail(self):
474474
response = self.client.delete(path)
475475
self.assertEqual(response.status_code, 204)
476476

477+
def test_operator_access_shared_credentials(self):
478+
self._create_credentials(organization=None)
479+
self._test_org_user_access_shared_object(
480+
listview_name="connection_api:credential_list",
481+
detailview_name="connection_api:credential_detail",
482+
create_payload={
483+
"connector": "openwisp_controller.connection.connectors.ssh.Ssh",
484+
"name": "Test credentials",
485+
"organization": "",
486+
"auto_add": False,
487+
"params": {"username": "root", "password": "Pa$$w0Rd", "port": 22},
488+
},
489+
update_payload={"name": "updated-test"},
490+
expected_count=1,
491+
)
492+
477493
def test_get_deviceconnection_list(self):
478494
d1 = self._create_device()
479495
path = reverse("connection_api:deviceconnection_list", args=(d1.pk,))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.db import migrations
2+
3+
from . import assign_permissions_to_groups
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("geo", "0003_alter_devicelocation_floorplan_location"),
9+
]
10+
operations = [
11+
migrations.RunPython(
12+
assign_permissions_to_groups, reverse_code=migrations.RunPython.noop
13+
)
14+
]

0 commit comments

Comments
 (0)