-
-
Notifications
You must be signed in to change notification settings - Fork 70
[change] Improve endpoints to download firmware images #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
18775b0
761bdd2
2824f49
30c8aef
5deae9a
3543a8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import swapper | ||
from django.contrib.auth import get_permission_codename | ||
from django.contrib.auth.models import Permission | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from openwisp_users.tests.utils import TestMultitenantAdminMixin | ||
|
||
from ..swapper import load_model | ||
from .base import TestUpgraderMixin | ||
|
||
OrganizationUser = swapper.load_model('openwisp_users', 'OrganizationUser') | ||
FirmwareImage = load_model('FirmwareImage') | ||
Group = swapper.load_model('openwisp_users', 'Group') | ||
|
||
|
||
class TestPrivateStorage(TestUpgraderMixin, TestMultitenantAdminMixin, TestCase): | ||
|
@@ -23,7 +29,7 @@ def _download_firmware_assert_status(self, status_code): | |
self.assertEqual(response.status_code, status_code) | ||
|
||
def test_unauthenticated_user(self): | ||
self._download_firmware_assert_status(403) | ||
self._download_firmware_assert_status(401) | ||
|
||
def test_authenticated_user(self): | ||
user = self._get_user() | ||
|
@@ -74,3 +80,47 @@ def test_superuser(self): | |
user = self._get_admin() | ||
self.client.force_login(user) | ||
self._download_firmware_assert_status(200) | ||
|
||
def test_view_permission_check(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this test is correct? I believe the code comments are outdated. A user being Organization Admin and a user having Administrator group are two different things. Is this clear? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes clear now |
||
staff_user = self._get_operator() | ||
self.client.force_login(staff_user) | ||
org = self.image.build.category.organization | ||
|
||
with self.subTest('Test initial access without permissions'): | ||
self._download_firmware_assert_status(403) | ||
|
||
# Add view permission first | ||
content_type = ContentType.objects.get_for_model(FirmwareImage) | ||
perm_codename = get_permission_codename('view', FirmwareImage._meta) | ||
view_perm = Permission.objects.get( | ||
content_type=content_type, codename=perm_codename | ||
) | ||
staff_user.user_permissions.add(view_perm) | ||
|
||
with self.subTest('Test access with view permission and org admin status'): | ||
self._create_org_user(user=staff_user, organization=org, is_admin=True) | ||
self._download_firmware_assert_status(200) | ||
|
||
# Remove org manager status | ||
org_user = staff_user.openwisp_users_organization.get( | ||
organization_users__organization=org | ||
) | ||
org_user.is_admin = False | ||
org_user.save() | ||
|
||
# Remove staff status | ||
staff_user.is_staff = False | ||
staff_user.save() | ||
|
||
# Restore org manager status | ||
org_user.is_admin = True | ||
org_user.save() | ||
|
||
with self.subTest('Test access without staff status'): | ||
self._download_firmware_assert_status(403) | ||
|
||
# Remove view permission | ||
staff_user.user_permissions.remove(view_perm) | ||
|
||
with self.subTest('Test access without view permission'): | ||
self._download_firmware_assert_status(403) |
Uh oh!
There was an error while loading. Please reload this page.