test(access): Ensure items returned from query are from user organization and/or globally set organization

ref: #459 closes #448
This commit is contained in:
2025-01-04 18:04:02 +09:30
parent dd72843ffb
commit 1087dde2d5
48 changed files with 981 additions and 32 deletions

View File

@ -12,6 +12,8 @@ from api.tests.abstract.test_metadata_functional import MetadataAttributesFuncti
from itim.models.clusters import Cluster
from settings.models.app_settings import AppSettings
class ViewSetBase:
@ -46,6 +48,33 @@ class ViewSetBase:
self.different_organization = different_organization
self.global_organization = Organization.objects.create(
name = 'test_global_organization'
)
self.global_org_item = self.model.objects.create(
organization = self.global_organization,
name = 'global_item'
)
app_settings = AppSettings.objects.get(
owner_organization = None
)
app_settings.global_organization = self.global_organization
app_settings.save()
view_permissions = Permission.objects.get(
codename = 'view_' + self.model._meta.model_name,
content_type = ContentType.objects.get(

View File

@ -12,6 +12,8 @@ from api.tests.abstract.test_metadata_functional import MetadataAttributesFuncti
from itim.models.clusters import ClusterType
from settings.models.app_settings import AppSettings
class ViewSetBase:
@ -46,6 +48,31 @@ class ViewSetBase:
self.different_organization = different_organization
self.global_organization = Organization.objects.create(
name = 'test_global_organization'
)
self.global_org_item = self.model.objects.create(
organization = self.global_organization,
name = 'global_item'
)
app_settings = AppSettings.objects.get(
owner_organization = None
)
app_settings.global_organization = self.global_organization
app_settings.save()
view_permissions = Permission.objects.get(
codename = 'view_' + self.model._meta.model_name,
content_type = ContentType.objects.get(

View File

@ -12,6 +12,8 @@ from api.tests.abstract.test_metadata_functional import MetadataAttributesFuncti
from itim.models.services import Port
from settings.models.app_settings import AppSettings
class ViewSetBase:
@ -46,6 +48,34 @@ class ViewSetBase:
self.different_organization = different_organization
self.global_organization = Organization.objects.create(
name = 'test_global_organization'
)
self.global_org_item = self.model.objects.create(
organization = self.global_organization,
number = 8181,
protocol = Port.Protocol.TCP
)
app_settings = AppSettings.objects.get(
owner_organization = None
)
app_settings.global_organization = self.global_organization
app_settings.save()
view_permissions = Permission.objects.get(
codename = 'view_' + self.model._meta.model_name,
content_type = ContentType.objects.get(

View File

@ -60,3 +60,15 @@ class ServiceNotePermissionsAPI(
self.url_view_kwargs = {'service_id': self.note_item.id, 'pk': self.item.pk }
self.add_data = {'note': 'a note added', 'organization': self.organization.id}
def test_returned_data_from_user_and_global_organizations_only(self):
"""Check items returned
This test case is a over-ride of a test case with the same name.
This model is not a tenancy model making this test not-applicable.
Items returned from the query Must be from the users organization and
global ONLY!
"""
pass

View File

@ -14,6 +14,8 @@ from itam.models.device import Device
from itim.models.services import Service, Port
from settings.models.app_settings import AppSettings
class ViewSetBase:
@ -48,6 +50,40 @@ class ViewSetBase:
self.different_organization = different_organization
device = Device.objects.create(
organization=organization,
name = 'device'
)
self.global_organization = Organization.objects.create(
name = 'test_global_organization'
)
self.global_org_item = self.model.objects.create(
organization = self.global_organization,
name = 'global_item',
device = device,
config_key_variable = 'value'
)
app_settings = AppSettings.objects.get(
owner_organization = None
)
app_settings.global_organization = self.global_organization
app_settings.save()
view_permissions = Permission.objects.get(
codename = 'view_' + self.model._meta.model_name,
content_type = ContentType.objects.get(
@ -124,11 +160,6 @@ class ViewSetBase:
user = self.view_user
)
device = Device.objects.create(
organization=organization,
name = 'device'
)
port = Port.objects.create(
organization=organization,
number = 80,

View File

@ -156,7 +156,18 @@ class ViewSetBase:
class ServicePermissionsAPI(ViewSetBase, APIPermissionView, TestCase):
pass
def test_returned_data_from_user_and_global_organizations_only(self):
"""Check items returned
This test case is a over-ride of a test case with the same name.
This model is not a tenancy model making this test not-applicable.
Items returned from the query Must be from the users organization and
global ONLY!
"""
pass

View File

@ -158,7 +158,18 @@ class ViewSetBase:
class ServicePermissionsAPI(ViewSetBase, APIPermissionView, TestCase):
pass
def test_returned_data_from_user_and_global_organizations_only(self):
"""Check items returned
This test case is a over-ride of a test case with the same name.
This model is not a tenancy model making this test not-applicable.
Items returned from the query Must be from the users organization and
global ONLY!
"""
pass