Skip to content

Commit defb0cb

Browse files
committed
[req-changes] Added test for shared Credentials
Added migrations to add "view" permissions
1 parent 53330f0 commit defb0cb

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
@@ -492,6 +492,22 @@ def test_delete_credential_detail(self):
492492
response = self.client.delete(path)
493493
self.assertEqual(response.status_code, 204)
494494

495+
def test_operator_access_shared_credentials(self):
496+
self._create_credentials(organization=None)
497+
self._test_org_user_access_shared_object(
498+
listview_name="connection_api:credential_list",
499+
detailview_name="connection_api:credential_detail",
500+
create_payload={
501+
"connector": "openwisp_controller.connection.connectors.ssh.Ssh",
502+
"name": "Test credentials",
503+
"organization": "",
504+
"auto_add": False,
505+
"params": {"username": "root", "password": "Pa$$w0Rd", "port": 22},
506+
},
507+
update_payload={"name": "updated-test"},
508+
expected_count=1,
509+
)
510+
495511
def test_get_deviceconnection_list(self):
496512
d1 = self._create_device()
497513
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)