Example #1
0
    def test_folder_removed_when_attachments_added(self):
        " EmptyDir's shouldn't exist if there are attachments inside the 'dir' "
        addon = Package(author=self.author, type='a')
        addon.save()
        revision = PackageRevision.objects.filter(package__name=addon.name)[0]

        folder = EmptyDir(name=self.path, author=self.author, root_dir='d')
        folder.save()
        revision.folder_add(folder)
        self.assertEqual(1, revision.folders.count())

        att = Attachment(
            filename='/'.join([self.path, 'helpers']),
            author=self.author,
            ext='js'
        )
        att.save()
        revision.attachment_add(att)
        self.assertEqual(0, revision.folders.count())

        att = Attachment(
            filename='model',
            author=self.author,
            ext='html'
        )
        att.save()
        revision.attachment_add(att)
        self.assertEqual(0, revision.folders.count())
Example #2
0
    def test_folder_removed_when_modules_added(self):
        " EmptyDir's shouldn't exist if there are modules inside the 'dir' "
        addon = Package(author=self.author, type='a')
        addon.save()
        revision = PackageRevision.objects.filter(package__name=addon.name)[0]

        folder = EmptyDir(name=self.path, author=self.author, root_dir='l')
        folder.save()
        revision.folder_add(folder)
        self.assertEqual(1, revision.folders.count())

        mod = Module(
            filename='/'.join([self.path, 'helpers']),
            author=self.author,
            code='//test code'
        )
        mod.save()
        revision.module_add(mod)
        self.assertEqual(0, revision.folders.count())

        mod = Module(
            filename='model',
            author=self.author,
            code='//test code'
        )
        mod.save()
        revision.module_add(mod)
        self.assertEqual(0, revision.folders.count())
Example #3
0
def package_add_folder(r, id_number, type_id, revision_number):
    " adds an EmptyDir to a revision "
    revision = get_package_revision(id_number, type_id, revision_number)
    if r.user.pk != revision.author.pk:
        log_msg = ("[security] Attempt to add a folder to package (%s) by "
                   "non-owner (%s)" % (id_number, r.user))
        log.warning(log_msg)
        return HttpResponseForbidden('You are not the author of this Package')

    foldername, root = r.POST.get('name', ''), r.POST.get('root_dir')

    dir = EmptyDir(name=foldername, author=r.user, root_dir=root)
    try:
        dir.save()
        revision.folder_add(dir)
    except FilenameExistException, err:
        dir.delete()
        return HttpResponseForbidden(escape(str(err)))
Example #4
0
def add_folder(request, revision_id):
    " adds an EmptyDir to a revision "
    revision = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if request.user.pk != revision.author.pk:
        log_msg = ("[security] Attempt to add a folder to revision (%s) by "
                   "non-owner (%s)" % (revision_id, request.user))
        log.warning(log_msg)
        return HttpResponseForbidden('You are not the author of this Package')

    foldername, root = (
            request.POST.get('name', ''),
            request.POST.get('root_dir'))

    dir = EmptyDir(name=foldername, author=request.user, root_dir=root)
    try:
        dir.save()
        revision.folder_add(dir)
    except FilenameExistException, err:
        dir.delete()
        return HttpResponseForbidden(escape(str(err)))
Example #5
0
    def test_folder_removed_when_modules_added(self):
        " EmptyDir's shouldn't exist if there are modules inside the 'dir' "
        addon = Package(author=self.author, type='a')
        addon.save()
        revision = PackageRevision.objects.filter(package__name=addon.name)[0]

        folder = EmptyDir(name=self.path, author=self.author, root_dir='l')
        folder.save()
        revision.folder_add(folder)
        self.assertEqual(1, revision.folders.count())

        mod = Module(filename='/'.join([self.path, 'helpers']),
                     author=self.author,
                     code='//test code')
        mod.save()
        revision.module_add(mod)
        self.assertEqual(0, revision.folders.count())

        mod = Module(filename='model', author=self.author, code='//test code')
        mod.save()
        revision.module_add(mod)
        self.assertEqual(0, revision.folders.count())
Example #6
0
def add_folder(request, revision_id):
    " adds an EmptyDir to a revision "
    revision = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if request.user.pk != revision.author.pk:
        log_msg = ("[security] Attempt to add a folder to revision (%s) by "
                   "non-owner (%s)" % (revision_id, request.user))
        log.warning(log_msg)
        return HttpResponseForbidden('You are not the author of this Package')

    foldername, root = (request.POST.get('name',
                                         ''), request.POST.get('root_dir'))

    dir = EmptyDir(name=foldername, author=request.user, root_dir=root)
    try:
        dir.save()
        revision.folder_add(dir)
    except FilenameExistException, err:
        dir.delete()
        return HttpResponseForbidden(escape(str(err)))