示例#1
0
 def test_missing_file(self):
     server = DefaultServer()
     request = Mock()
     request.META = {}
     os.remove(self.filer_file.file.path)
     self.assertRaises(Http404, server.serve,
                       *(request, self.filer_file.file))
示例#2
0
 def test_normal(self):
     request = Mock()
     request.META = {}
     response = self.server.serve(request, self.filer_file.file)
     headers = dict(response.items())
     self.assertTrue(response.has_header('X-Accel-Redirect'))
     self.assertTrue(headers['X-Accel-Redirect'].startswith(self.server.nginx_location))
     # make sure the file object was never opened (otherwise the whole delegating to nginx would kinda
     # be useless)
     self.assertTrue(self.filer_file.file.closed)
 def test_normal(self):
     request = Mock()
     request.META = {}
     response = self.server.serve(request, self.filer_file.file)
     headers = dict(response.items())
     self.assertTrue(response.has_header('X-Sendfile'))
     self.assertEqual(headers['X-Sendfile'], self.filer_file.file.path)
     # make sure the file object was never opened (otherwise the whole delegating to nginx would kinda
     # be useless)
     self.assertTrue(self.filer_file.file.closed)
示例#4
0
 def test_normal(self):
     request = Mock()
     request.META = {}
     response = self.server.serve(request, self.filer_file.file)
     headers = dict(response.items())
     self.assertTrue(response.has_header('X-Sendfile'))
     self.assertEqual(headers['X-Sendfile'], self.filer_file.file.path)
     # make sure the file object was never opened (otherwise the whole delegating to nginx would kinda
     # be useless)
     self.assertTrue(self.filer_file.file.closed)
 def test_normal(self):
     request = Mock()
     request.META = {}
     response = self.server.serve(request, self.filer_file.file)
     headers = dict(response.items())
     self.assertTrue(response.has_header('X-Accel-Redirect'))
     self.assertTrue(headers['X-Accel-Redirect'].startswith(self.server.nginx_location))
     # make sure the file object was never opened (otherwise the whole delegating to nginx would kinda
     # be useless)
     self.assertTrue(self.filer_file.file.closed)
示例#6
0
 def test_missing_file(self):
     """
     this backend should not even notice if the file is missing.
     """
     request = Mock()
     request.META = {}
     os.remove(self.filer_file.file.path)
     response = self.server.serve(request, self.filer_file.file)
     headers = dict(response.items())
     self.assertTrue(response.has_header('X-Accel-Redirect'))
     self.assertTrue(headers['X-Accel-Redirect'].startswith(self.server.nginx_location))
     self.assertTrue(self.filer_file.file.closed)
 def test_missing_file(self):
     """
     this backend should not even notice if the file is missing.
     """
     request = Mock()
     request.META = {}
     os.remove(self.filer_file.file.path)
     response = self.server.serve(request, self.filer_file.file)
     headers = dict(response.items())
     self.assertTrue(response.has_header('X-Accel-Redirect'))
     self.assertTrue(headers['X-Accel-Redirect'].startswith(self.server.nginx_location))
     self.assertTrue(self.filer_file.file.closed)
示例#8
0
    def test_save_as(self):
        server = DefaultServer()
        request = Mock()
        request.META = {}
        response = server.serve(request, self.filer_file.file, save_as=True)
        self.assertEqual(response['Content-Disposition'], 'attachment; filename=testimage.jpg')

        response = server.serve(request, self.filer_file.file, save_as=False)
        self.assertFalse(response.has_header('Content-Disposition'))

        response = server.serve(request, self.filer_file.file, save_as='whatever.png')
        self.assertEqual(response['Content-Disposition'], 'attachment; filename=whatever.png')
示例#9
0
    def test_save_as(self):
        server = DefaultServer()
        request = Mock()
        request.META = {}
        response = server.serve(request, self.filer_file.file, save_as=True)
        self.assertEqual(response["Content-Disposition"], "attachment; filename=testimage.jpg")

        response = server.serve(request, self.filer_file.file, save_as=False)
        self.assertFalse(response.has_header("Content-Disposition"))

        response = server.serve(request, self.filer_file.file, save_as="whatever.png")
        self.assertEqual(response["Content-Disposition"], "attachment; filename=whatever.png")
示例#10
0
 def test_missing_file(self):
     """
     this backend should not even notice if the file is missing.
     """
     request = Mock()
     request.META = {}
     os.remove(self.filer_file.file.path)
     response = self.server.serve(request, self.filer_file.file)
     headers = dict(response.items())
     self.assertTrue(response.has_header('X-Sendfile'))
     self.assertEqual(headers['X-Sendfile'], self.filer_file.file.path)
     # make sure the file object was never opened (otherwise the whole delegating to nginx would kinda
     # be useless)
     self.assertTrue(self.filer_file.file.closed)
 def test_missing_file(self):
     """
     this backend should not even notice if the file is missing.
     """
     request = Mock()
     request.META = {}
     os.remove(self.filer_file.file.path)
     response = self.server.serve(request, self.filer_file.file)
     headers = dict(response.items())
     self.assertTrue(response.has_header('X-Sendfile'))
     self.assertEqual(headers['X-Sendfile'], self.filer_file.file.path)
     # make sure the file object was never opened (otherwise the whole delegating to nginx would kinda
     # be useless)
     self.assertTrue(self.filer_file.file.closed)
示例#12
0
    def test_unlogged_user_has_rights_when_permissions_disabled(self):
        self.create_fixtures()
        request = Mock()
        setattr(request, 'user', self.unauth_user)

        result = self.folder.has_read_permission(request)
        self.assertEqual(result, True)
示例#13
0
    def test_overlapped_groups_deny1(self):
        # Tests overlapped groups with explicit deny

        request1 = Mock()
        setattr(request1, 'user', self.test_user1)

        old_setting = filer_settings.FILER_ENABLE_PERMISSIONS
        try:
            filer_settings.FILER_ENABLE_PERMISSIONS = True

            self.assertEqual(self.folder.has_read_permission(request1), False)
            self.assertEqual(self.folder_perm.has_read_permission(request1),
                             False)

            self.assertEqual(FolderPermission.objects.count(), 0)

            FolderPermission.objects.create(
                folder=self.folder,
                type=FolderPermission.CHILDREN,
                group=self.group1,
                can_edit=FolderPermission.DENY,
                can_read=FolderPermission.ALLOW,
                can_add_children=FolderPermission.DENY)
            FolderPermission.objects.create(
                folder=self.folder,
                type=FolderPermission.CHILDREN,
                group=self.group2,
                can_edit=FolderPermission.ALLOW,
                can_read=FolderPermission.ALLOW,
                can_add_children=FolderPermission.ALLOW)

            self.assertEqual(FolderPermission.objects.count(), 2)

            # We have to invalidate cache
            delattr(self.folder, 'permission_cache')

            self.assertEqual(
                self.test_user1.groups.filter(pk=self.group1.pk).exists(),
                True)
            self.assertEqual(
                self.test_user1.groups.filter(pk=self.group2.pk).exists(),
                False)

            self.assertEqual(self.folder.has_read_permission(request1), True)
            self.assertEqual(self.folder.has_edit_permission(request1), False)

            self.assertEqual(self.test_user1.groups.count(), 1)

            self.test_user1.groups.add(self.group2)

            self.assertEqual(self.test_user1.groups.count(), 2)

            # We have to invalidate cache
            delattr(self.folder, 'permission_cache')

            self.assertEqual(self.folder.has_read_permission(request1), True)
            self.assertEqual(self.folder.has_edit_permission(request1), False)

        finally:
            filer_settings.FILER_ENABLE_PERMISSIONS = old_setting
示例#14
0
    def test_superuser_has_rights(self):
        self.create_fixtures()
        request = Mock()
        setattr(request, 'user', self.superuser)

        result = self.folder.has_read_permission(request)
        self.assertEqual(result, True)
示例#15
0
    def test_owner_user_has_rights(self):
        # Set owner as the owner of the folder.
        self.folder.owner = self.owner
        request = Mock()
        setattr(request, 'user', self.owner)

        result = self.folder.has_read_permission(request)
        self.assertEqual(result, True)
示例#16
0
    def test_combined_groups(self):
        request1 = Mock()
        setattr(request1, 'user', self.test_user1)
        request2 = Mock()
        setattr(request2, 'user', self.test_user2)

        old_setting = filer_settings.FILER_ENABLE_PERMISSIONS
        try:
            filer_settings.FILER_ENABLE_PERMISSIONS = True

            self.assertEqual(self.folder.has_read_permission(request1), False)
            self.assertEqual(self.folder.has_read_permission(request2), False)
            self.assertEqual(self.folder_perm.has_read_permission(request1), False)
            self.assertEqual(self.folder_perm.has_read_permission(request2), False)

            self.assertEqual(FolderPermission.objects.count(), 0)

            FolderPermission.objects.create(folder=self.folder, type=FolderPermission.CHILDREN, group=self.group1, can_edit=FolderPermission.DENY, can_read=FolderPermission.ALLOW, can_add_children=FolderPermission.DENY)
            FolderPermission.objects.create(folder=self.folder_perm, type=FolderPermission.CHILDREN, group=self.group2, can_edit=FolderPermission.DENY, can_read=FolderPermission.ALLOW, can_add_children=FolderPermission.DENY)

            self.assertEqual(FolderPermission.objects.count(), 2)

            # We have to invalidate cache
            delattr(self.folder, 'permission_cache')
            delattr(self.folder_perm, 'permission_cache')

            self.assertEqual(self.folder.has_read_permission(request1), True)
            self.assertEqual(self.folder.has_read_permission(request2), False)
            self.assertEqual(self.folder_perm.has_read_permission(request1), False)
            self.assertEqual(self.folder_perm.has_read_permission(request2), True)

            self.test_user1.groups.add(self.group2)
            self.test_user2.groups.add(self.group1)

            # We have to invalidate cache
            delattr(self.folder, 'permission_cache')
            delattr(self.folder_perm, 'permission_cache')

            self.assertEqual(self.folder.has_read_permission(request1), True)
            self.assertEqual(self.folder.has_read_permission(request2), True)
            self.assertEqual(self.folder_perm.has_read_permission(request1), True)
            self.assertEqual(self.folder_perm.has_read_permission(request2), True)

        finally:
            filer_settings.FILER_ENABLE_PERMISSIONS = old_setting
示例#17
0
    def test_unlogged_user_has_no_rights(self):
        old_setting = filer_settings.FILER_ENABLE_PERMISSIONS
        filer_settings.FILER_ENABLE_PERMISSIONS = True
        self.create_fixtures()
        request = Mock()
        setattr(request, 'user', self.unauth_user)

        result = self.folder.has_read_permission(request)
        filer_settings.FILER_ENABLE_PERMISSIONS = old_setting
        self.assertEqual(result, False)
示例#18
0
    def test_overlapped_groups2(self):
        # Tests overlapped groups without explicit deny
        # Similar test to test_overlapped_groups1, only order of groups is different

        request2 = Mock()
        setattr(request2, 'user', self.test_user2)

        old_setting = filer_settings.FILER_ENABLE_PERMISSIONS
        try:
            filer_settings.FILER_ENABLE_PERMISSIONS = True

            self.assertEqual(self.folder.has_read_permission(request2), False)
            self.assertEqual(self.folder_perm.has_read_permission(request2), False)

            self.assertEqual(FolderPermission.objects.count(), 0)

            FolderPermission.objects.create(folder=self.folder_perm, type=FolderPermission.CHILDREN, group=self.group2, can_edit=None, can_read=FolderPermission.ALLOW, can_add_children=None)
            FolderPermission.objects.create(folder=self.folder_perm, type=FolderPermission.CHILDREN, group=self.group1, can_edit=FolderPermission.ALLOW, can_read=FolderPermission.ALLOW, can_add_children=FolderPermission.ALLOW)

            self.assertEqual(FolderPermission.objects.count(), 2)

            # We have to invalidate cache
            delattr(self.folder_perm, 'permission_cache')

            self.assertEqual(self.test_user2.groups.filter(pk=self.group2.pk).exists(), True)
            self.assertEqual(self.test_user2.groups.filter(pk=self.group1.pk).exists(), False)

            self.assertEqual(self.folder_perm.has_read_permission(request2), True)
            self.assertEqual(self.folder_perm.has_edit_permission(request2), False)

            self.assertEqual(self.test_user2.groups.count(), 1)

            self.test_user2.groups.add(self.group1)

            self.assertEqual(self.test_user2.groups.count(), 2)

            # We have to invalidate cache
            delattr(self.folder_perm, 'permission_cache')

            self.assertEqual(self.folder_perm.has_read_permission(request2), True)
            self.assertEqual(self.folder_perm.has_edit_permission(request2), True)

        finally:
            filer_settings.FILER_ENABLE_PERMISSIONS = old_setting
示例#19
0
 def test_normal(self):
     server = DefaultServer()
     request = Mock()
     request.META = {}
     response = server.serve(request, self.filer_file.file)
     self.assertTrue(response.has_header('Last-Modified'))
示例#20
0
 def test_not_modified(self):
     server = DefaultServer()
     request = Mock()
     request.META = {'HTTP_IF_MODIFIED_SINCE': http_date(time.time())}
     response = server.serve(request, self.filer_file.file)
     self.assertTrue(isinstance(response, HttpResponseNotModified))
 def test_missing_file(self):
     server = DefaultServer()
     request = Mock()
     request.META = {}
     os.remove(self.filer_file.file.path)
     self.assertRaises(Http404, server.serve, *(request, self.filer_file.file))
 def test_not_modified(self):
     server = DefaultServer()
     request = Mock()
     request.META = {'HTTP_IF_MODIFIED_SINCE': http_date(time.time())}
     response = server.serve(request, self.filer_file.file)
     self.assertTrue(isinstance(response, HttpResponseNotModified))
 def test_normal(self):
     server = DefaultServer()
     request = Mock()
     request.META = {}
     response = server.serve(request, self.filer_file.file)
     self.assertTrue(response.has_header('Last-Modified'))