Exemple #1
0
    def test_container_acl_remove_write(self):
        formData = {
            'container_name': 'containerName',
            'method': 'ContainerAclRemove',
            'header_name': 'test',
            'acl_type': 'write',
            'acl_value': 'test'
        }
        self.mox.StubOutWithMock(api, 'swift_set_container_info')
        api.swift_set_container_info(IsA(http.HttpRequest),
                                     self.container.name,
                                     {'X-Container-Write': ''})

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('dash_containers_acl',
                    args=[self.request.user.tenant_id, self.container.name]),
            formData)
        self.assertRedirectsNoFollow(
            res,
            reverse('dash_containers_acl',
                    args=[self.request.user.tenant_id, self.container.name]))
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Exemple #2
0
    def handle(self, request, data):
        header = data['header_name']
        container_name = data['container_name']

        if not header.lower().startswith('x-container-meta'):
            messages.error(request, "Container metadata must begin with x-container-meta-")
        else:
            hdrs = {}
            hdrs[header] = ''
            api.swift_set_container_info(request, container_name, hdrs)

        return shortcuts.redirect(request.build_absolute_uri())
Exemple #3
0
    def handle(self, request, data):
        header = data['header_name']
        container_name = data['container_name']

        if not header.lower().startswith('x-container-meta'):
            messages.error(request, "Container metadata must begin with x-container-meta-")
        else:
            hdrs = {}
            hdrs[header] = ''
            try:
                api.swift_set_container_info(request, container_name, hdrs)
            except ResponseError, e:
                messages.error(request, 'Unable to remove metadata from container : %s' % str(e))
Exemple #4
0
 def test_container_meta_remove(self):
     formData = {'container_name' : 'containerName',
                 'method' : 'ContainerMetaRemove',
                 'header_name' : 'x-container-meta-test' }
     self.mox.StubOutWithMock(api, 'swift_set_container_info')
     api.swift_set_container_info(
                 IsA(http.HttpRequest), self.container.name, {'x-container-meta-test' : ''})
     self.mox.ReplayAll()
     res = self.client.post(reverse('dash_containers_meta',
                                    args=[self.request.user.tenant_id, self.container.name]),
                                    formData) 
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
Exemple #5
0
    def handle(self, request, data):
        header = data['header_name']
        container_name = data['container_name']

        if not header.lower().startswith('x-container-meta'):
            messages.error(
                request,
                "Container metadata must begin with x-container-meta-")
        else:
            hdrs = {}
            hdrs[header] = ''
            api.swift_set_container_info(request, container_name, hdrs)

        return shortcuts.redirect(request.build_absolute_uri())
Exemple #6
0
    def handle(self, request, data):
        header = data['header_name']
        container_name = data['container_name']

        if not header.lower().startswith('x-container-meta'):
            messages.error(
                request,
                "Container metadata must begin with x-container-meta-")
        else:
            hdrs = {}
            hdrs[header] = ''
            try:
                api.swift_set_container_info(request, container_name, hdrs)
            except ResponseError, e:
                messages.error(
                    request,
                    'Unable to remove metadata from container : %s' % str(e))
Exemple #7
0
 def test_container_meta_remove(self):
     formData = {
         'container_name': 'containerName',
         'method': 'ContainerMetaRemove',
         'header_name': 'x-container-meta-test'
     }
     self.mox.StubOutWithMock(api, 'swift_set_container_info')
     api.swift_set_container_info(IsA(http.HttpRequest),
                                  self.container.name,
                                  {'x-container-meta-test': ''})
     self.mox.ReplayAll()
     res = self.client.post(
         reverse('dash_containers_meta',
                 args=[self.request.user.tenant_id, self.container.name]),
         formData)
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
Exemple #8
0
 def test_contianer_acl_put_read_duplicate(self):
     formData = {'container_name' : 'containerName',
                 'method' : 'ContainerAcl',
                 'acl_type' : "1",
                 'acl_add' : 'test',
                 'read_acl' : 'test'}
     self.mox.StubOutWithMock(api, 'swift_set_container_info')
     api.swift_set_container_info(
                 IsA(http.HttpRequest), self.container.name, {'X-Container-Read' : 'test'})
     self.mox.ReplayAll()
     res = self.client.post(reverse('dash_containers_acl',
                                    args=[self.request.user.tenant_id, self.container.name]),
                                    formData) 
     self.assertRedirectsNoFollow(res, reverse('dash_containers_acl',
                                               args=[self.request.user.tenant_id, self.container.name]))
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
Exemple #9
0
    def test_container_meta_put_maxlen(self):

        postvalue = 'v' * 4099 # length limit over
        formData = {'container_name' : 'containerName',
                    'method' : 'ContainerMeta',
                    'header_name' : 'x-container-meta-test',
                    'header_value' : postvalue }
        self.mox.StubOutWithMock(api, 'swift_set_container_info')
        api.swift_set_container_info(
                    IsA(http.HttpRequest), self.container.name, {'x-container-meta-test':postvalue})
        self.mox.ReplayAll()
        res = self.client.post(reverse('dash_containers_meta',
                                       args=[self.request.user.tenant_id, self.container.name]),
                                       formData) 
        self.assertRedirectsNoFollow(res, reverse('dash_containers_meta',
                                                  args=[self.request.user.tenant_id, self.container.name]))
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Exemple #10
0
    def test_container_acl_remove_read_ref(self):
        formData = {'container_name' : 'containerName',
                    'method' : 'ContainerAclRemove',
                    'header_name' : '*',
                    'acl_type' : 'read',
                    'acl_value' : 'test, .r:*'}
        self.mox.StubOutWithMock(api, 'swift_set_container_info')
        api.swift_set_container_info(
                    IsA(http.HttpRequest), self.container.name, {'X-Container-Read':'test'})
       
        self.mox.ReplayAll()
 
        res = self.client.post(reverse('dash_containers_acl',
                                       args=[self.request.user.tenant_id, self.container.name]),
                                       formData, follow=False) 
        self.assertRedirectsNoFollow(res, reverse('dash_containers_acl',
                                                  args=[self.request.user.tenant_id, self.container.name]))
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Exemple #11
0
    def test_container_public_put(self):
      
        ret_container = self.container 
        ret_container.headers = [('x-container-meta-web-index','test'),
                                 ('x-container-meta-web-listing-css', 'css'),
                                 ('x-container-meta-web-error', 'err'),
                                 ('x-container-meta-web-listing', 'fuga') ]
        formData = {'container_name':'containerName',
                    'method':'MakePublicContainer',
                    'index_object_name' : self.object.name,
                    'css_object_name' : self.object.name,
                    'html_listing' : True,
                    'public_html' : True,
                    'use_css_in_listing' : True,
                    'error' : 'errorsuffix'
                   }

        self.mox.StubOutWithMock(api, 'swift_get_container')
        api.swift_get_container(
                                IsA(http.HttpRequest), self.container.name
                                ).AndReturn(ret_container)
        
        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(
                              IsA(http.HttpRequest), self.container.name
                              ).AndReturn([self.object])

        self.mox.StubOutWithMock(api, 'swift_set_container_info')

        api.swift_set_container_info(
                                     IsA(http.HttpRequest), self.container.name,
                                     IgnoreArg())
        
        self.mox.ReplayAll()
            
        res = self.client.post(reverse('dash_containers_public', args=['tenant', self.container.name]),
                                       formData)
        #self.assertRedirectsNoFollow(res, reverse('dash_containers_public',
        #                                          args=[self.request.user.tenant_id, self.container.name]))
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Exemple #12
0
    def test_container_public_put(self):

        ret_container = self.container
        ret_container.headers = [('x-container-meta-web-index', 'test'),
                                 ('x-container-meta-web-listing-css', 'css'),
                                 ('x-container-meta-web-error', 'err'),
                                 ('x-container-meta-web-listing', 'fuga')]
        formData = {
            'container_name': 'containerName',
            'method': 'MakePublicContainer',
            'index_object_name': self.object.name,
            'css_object_name': self.object.name,
            'html_listing': True,
            'public_html': True,
            'use_css_in_listing': True,
            'error': 'errorsuffix'
        }

        self.mox.StubOutWithMock(api, 'swift_get_container')
        api.swift_get_container(IsA(http.HttpRequest),
                                self.container.name).AndReturn(ret_container)

        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(IsA(http.HttpRequest),
                              self.container.name).AndReturn([self.object])

        self.mox.StubOutWithMock(api, 'swift_set_container_info')

        api.swift_set_container_info(IsA(http.HttpRequest),
                                     self.container.name, IgnoreArg())

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('dash_containers_public',
                    args=['tenant', self.container.name]), formData)
        #self.assertRedirectsNoFollow(res, reverse('dash_containers_public',
        #                                          args=[self.request.user.tenant_id, self.container.name]))
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Exemple #13
0
 def test_contianer_acl_put_read_ref(self):
     formData = {
         'container_name': 'containerName',
         'method': 'ContainerAcl',
         'acl_add': '.r:*',
         'acl_type': "1",
         'read_acl': ''
     }
     self.mox.StubOutWithMock(api, 'swift_set_container_info')
     api.swift_set_container_info(IsA(http.HttpRequest),
                                  self.container.name,
                                  {'X-Container-Read': '.r:*'})
     self.mox.ReplayAll()
     res = self.client.post(
         reverse('dash_containers_acl',
                 args=[self.request.user.tenant_id, self.container.name]),
         formData)
     self.assertRedirectsNoFollow(
         res,
         reverse('dash_containers_acl',
                 args=[self.request.user.tenant_id, self.container.name]))
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
Exemple #14
0
    def handle(self, request, data):
        hdrs = {}
        index_object_name = data['index_object_name']
        css_object_name = data['css_object_name']
        public_html = data['public_html']
        error = data['error']
        html_listing = data['html_listing']
        use_css_in_listing = data['use_css_in_listing']
        container_name = data['container_name']
        for name in ['Index', 'Listing', 'Listing-Css', 'Error']:
            hdrs['X-Container-Meta-Web-' + name] = ''
        if public_html:
            hdrs['X-Container-Meta-Web-Index'] = index_object_name
        if html_listing:
            hdrs['X-Container-Meta-Web-Listing'] = 'true'
        if use_css_in_listing:
            hdrs['X-Container-Meta-Web-Listing-Css'] = css_object_name
        if error:
            hdrs['X-Container-Meta-Web-Error'] = error

        api.swift_set_container_info(request, container_name, hdrs)

        return shortcuts.redirect("dash_containers", request.user.tenant_id)
Exemple #15
0
    def handle(self, request, data):
        hdrs = {}
        index_object_name = data['index_object_name']
        css_object_name = data['css_object_name']
        public_html = data['public_html']
        error = data['error']
        html_listing = data['html_listing']
        use_css_in_listing = data['use_css_in_listing']
        container_name = data['container_name']
        for name in ['Index', 'Listing', 'Listing-Css', 'Error']:
           hdrs['X-Container-Meta-Web-' + name] = ''
        if public_html:
           hdrs['X-Container-Meta-Web-Index'] = index_object_name
        if html_listing:
           hdrs['X-Container-Meta-Web-Listing'] = 'true'
        if use_css_in_listing:
           hdrs['X-Container-Meta-Web-Listing-Css'] = css_object_name
        if error:
           hdrs['X-Container-Meta-Web-Error'] = error

        api.swift_set_container_info(request, container_name, hdrs)

        return shortcuts.redirect("dash_containers", request.user.tenant_id)
Exemple #16
0
    def test_container_meta_put_maxlen(self):

        postvalue = 'v' * 4099  # length limit over
        formData = {
            'container_name': 'containerName',
            'method': 'ContainerMeta',
            'header_name': 'x-container-meta-test',
            'header_value': postvalue
        }
        self.mox.StubOutWithMock(api, 'swift_set_container_info')
        api.swift_set_container_info(IsA(http.HttpRequest),
                                     self.container.name,
                                     {'x-container-meta-test': postvalue})
        self.mox.ReplayAll()
        res = self.client.post(
            reverse('dash_containers_meta',
                    args=[self.request.user.tenant_id, self.container.name]),
            formData)
        self.assertRedirectsNoFollow(
            res,
            reverse('dash_containers_meta',
                    args=[self.request.user.tenant_id, self.container.name]))
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Exemple #17
0
class ContainerMeta(forms.SelfHandlingForm):
    ''' Form that handles Swift Container Meta Data '''
    container_name = forms.CharField(widget=forms.HiddenInput())
    header_name = forms.CharField(
        max_length="128",
        label='Name',
        required=True,
        validators=[validators.MaxLengthValidator(128)])
    header_value = forms.CharField(
        max_length="256",
        label="Value",
        required=True,
        validators=[validators.MaxLengthValidator(256)])

    def __init__(self, *args, **kwargs):
        super(ContainerMeta, self).__init__(*args, **kwargs)

    def handle(self, request, data):
        header = data['header_name']
        value = data['header_value']
        container_name = data['container_name']

        try:
            header.encode('ascii')
            value.encode('ascii')
        except UnicodeEncodeError, e:
            messages.error(
                request,
                "Container metadata contains non-ASCII character %s" % str(e))
            return shortcuts.redirect(request.build_absolute_uri())

        if not header.lower().startswith('x-container-meta'):
            messages.error(
                request,
                "Container metadata must begin with x-container-meta-")
            return shortcuts.redirect(request.build_absolute_uri())

        hdrs = {}
        hdrs[header] = value

        try:
            api.swift_set_container_info(request, container_name, hdrs)
        except Exception, e:
            messages.error(
                request,
                'Unable to setting Container Meta Information is failed: %s' %
                str(e))
Exemple #18
0
class ContainerAclRemove(forms.SelfHandlingForm):
    container_name = forms.CharField(widget=forms.HiddenInput())
    header_name = forms.CharField(widget=forms.HiddenInput())
    acl_type = forms.CharField(widget=forms.HiddenInput())
    acl_value = forms.CharField(widget=forms.HiddenInput())

    def __init__(self, *args, **kwargs):
        super(ContainerAclRemove, self).__init__(*args, **kwargs)

    def handle(self, request, data):
        header = data['header_name']
        container_name = data['container_name']
        acl_type = data['acl_type']
        acl_value = data['acl_value']

        if acl_type == "read":
            type = 'X-Container-Read'
        elif acl_type == "write":
            type = 'X-Container-Write'
        else:
            pass
        # clean and parse acl
        try:
            acl = clean_acl(type, acl_value)
            refs, groups = parse_acl(acl)
        except ValueError, e:
            messages.error(request, 'ACL value is invalid %s' % str(e))
            return

        if header in groups:
            groups.remove(header)
        if header in refs:
            refs.remove(header)

        # re-calcurate referer string
        refs = map(lambda x: '.r:%s' % x, refs)

        # set header
        hdrs = {}
        hdrs[type] = ','.join(groups + refs)

        api.swift_set_container_info(request, container_name, hdrs)

        return shortcuts.redirect(request.build_absolute_uri())
Exemple #19
0
                val.append(False)
        LOG.debug('val %s' % val)
        if not True in val:
            messages.error(
                request, 'Adding ReadAcl or WriteACL for other account is not \
             allowed unless Your Acl is allowed. Please add your Acl \
             first (ex %s ' % request.user.tenant_name)
            return None

        # set header
        hdrs = {}
        hdrs[type] = ','.join(group_result + ref_result)

        LOG.debug("sending ACL %s" % hdrs)
        try:
            api.swift_set_container_info(request, container_name, hdrs)
        except Exception, e:
            messages.error(request,
                           'Unable to set container acl : %s' % str(e))

        return None


class MakePublicContainer(forms.SelfHandlingForm):
    index_object_name = forms.ChoiceField(label="Object used for index.html")
    css_object_name = forms.ChoiceField(
        label="Object used as a css file for listing Container")
    error = forms.CharField(max_length="255",
                            label="file suffix to be used when error occurs",
                            required=False)
    public_html = forms.BooleanField(label="Published as HTML", required=False)
Exemple #20
0
class ContainerAcl(forms.SelfHandlingForm):
    ''' Form that handles Swift Container Acl '''
    container_name = forms.CharField(widget=forms.HiddenInput())
    acl_type = forms.ChoiceField(label="ACL Type",
                                 choices=((1, 'ReadAcl'), (0, 'WriteAcl')),
                                 initial=1,
                                 widget=forms.RadioSelect)
    read_acl = forms.CharField(widget=forms.HiddenInput(), required=False)
    write_acl = forms.CharField(widget=forms.HiddenInput(), required=False)
    acl_add = forms.CharField(max_length="255", label="ACL", required=True)

    def __init__(self, *args, **kwargs):
        super(ContainerAcl, self).__init__(*args, **kwargs)

    def handle(self, request, data):

        container_name = data['container_name']
        acl_type = data['acl_type']

        if acl_type == "1":
            type = 'X-Container-Read'
            acl_value = data.get('read_acl', '')
        elif acl_type == "0":
            type = 'X-Container-Write'
            acl_value = data.get('write_acl', '')

        # clean and parse acl
        try:
            acl = clean_acl(type, data['acl_add'])
            acl_orig = clean_acl(type, acl_value)
            ref_add, group_add = parse_acl(acl)
            ref_orig, group_orig = parse_acl(acl_orig)
        except ValueError, e:
            messages.error(request, 'ACL value is invalid %s' % str(e))
            print str(e)
            return

        # duplicate check
        ref_add = list(set(ref_add))
        ref_orig = list(set(ref_orig))
        group_add = list(set(group_add))
        group_orig = list(set(group_orig))

        acl_result = []
        acl_ref_result = []

        for item in group_add:
            if not item in group_orig:
                acl_result.append(item)
        for item in ref_add:
            if not item in ref_orig:
                acl_ref_result.append(item)

        group_result = group_orig + acl_result
        ref_result = acl_ref_result + ref_orig
        # re-calcurate referer string
        refs_result = map(lambda x: '.r:%s' % x, ref_result)

        # set header
        hdrs = {}
        hdrs[type] = ','.join(group_result + ref_result)

        api.swift_set_container_info(request, container_name, hdrs)

        return shortcuts.redirect(request.build_absolute_uri())
Exemple #21
0
class ContainerAclRemove(forms.SelfHandlingForm):
    container_name = forms.CharField(widget=forms.HiddenInput())
    header_name = forms.CharField(widget=forms.HiddenInput())
    acl_type = forms.CharField(widget=forms.HiddenInput())
    acl_value = forms.CharField(widget=forms.HiddenInput())

    def __init__(self, *args, **kwargs):
        super(ContainerAclRemove, self).__init__(*args, **kwargs)

    def handle(self, request, data):
        header = data['header_name']
        container_name = data['container_name']
        acl_type = data['acl_type']
        acl_value = data['acl_value']

        if acl_type == "read":
            type = 'X-Container-Read'
        elif acl_type == "write":
            type = 'X-Container-Write'
        else:
            pass
        # clean and parse acl
        try:
            acl = clean_acl(type, acl_value)
            refs, groups = parse_acl(acl)
        except ValueError, e:
            messages.error(request, 'ACL value is invalid %s' % str(e))
            return None

        if header in groups:
            groups.remove(header)
        if header in refs:
            refs.remove(header)

        # re-calcurate referer string
        refs = map(lambda x: '.r:%s' % x.encode('utf-8'), refs)
        LOG.debug('ref  %s' % refs)

        tenant_name = request.user.tenant_name
        tenant_user_name = '%s:%s' % (request.user.tenant_name,
                                      request.user.username)
        LOG.debug('acl_type %s' % acl_type)
        # check ACL
        val = []
        for each_acl in groups:
            if each_acl == tenant_name or each_acl == tenant_user_name:
                val.append(True)
            else:
                val.append(False)
        if not True in val and len(val) > 0:
            messages.error(
                request,
                'Removing Your ACL from this Container is not allowed unless other ACLs are deleted'
            )
            return

        #messages.error(request, refs)
        # set header
        hdrs = {}
        hdrs[type] = ','.join(groups + refs)

        LOG.debug('delete acl %s' % hdrs)
        try:
            api.swift_set_container_info(request, container_name, hdrs)
        except Exception, e:
            # TODO error message
            messages.error(
                request,
                'Removing Container Meta Information is failed: %s' % str(e))
Exemple #22
0
            else:
                val.append(False)
        LOG.debug('val %s' % val)
        if not True in val:
             messages.error(request, 'Adding ReadAcl or WriteACL for other account is not \
             allowed unless Your Acl is allowed. Please add your Acl \
             first (ex %s ' % request.user.tenant_name)
             return None

        # set header
        hdrs = {}
        hdrs[type] = ','.join(group_result + ref_result)

        LOG.debug("sending ACL %s" % hdrs)
        try:
            api.swift_set_container_info(request, container_name, hdrs)
        except Exception, e:
            messages.error(request, 'Unable to set container acl : %s' % str(e))


        return None       


class MakePublicContainer(forms.SelfHandlingForm):
    index_object_name = forms.ChoiceField(label="Object used for index.html")
    css_object_name = forms.ChoiceField(label="Object used as a css file for listing Container")
    error = forms.CharField(max_length="255", label="file suffix to be used when error occurs", required=False )
    public_html = forms.BooleanField(label="Published as HTML", required=False)
    use_css_in_listing = forms.BooleanField(label="Use CSS file for listing Container", required=False)
    html_listing = forms.BooleanField(label="Enable Container listing", required=False )
    container_name = forms.CharField(widget=forms.HiddenInput())
Exemple #23
0
class MakePublicContainer(forms.SelfHandlingForm):
    index_object_name = forms.ChoiceField(label="Object used for index.html")
    css_object_name = forms.ChoiceField(
        label="Object used as a css file for listing Container")
    error = forms.CharField(max_length="255",
                            label="file suffix to be used when error occurs",
                            required=False)
    public_html = forms.BooleanField(label="Published as HTML", required=False)
    use_css_in_listing = forms.BooleanField(
        label="Use CSS file for listing Container", required=False)
    html_listing = forms.BooleanField(label="Enable Container listing",
                                      required=False)
    container_name = forms.CharField(widget=forms.HiddenInput())

    def __init__(self, *args, **kwargs):
        objects = kwargs.pop('objects')
        headers = kwargs.pop('headers')
        super(MakePublicContainer, self).__init__(*args, **kwargs)
        self.fields['index_object_name'].choices = objects
        self.fields['css_object_name'].choices = objects

        for name, value in headers:
            name = name.lower()
            if name == 'x-container-meta-web-index':
                self.fields['public_html'].initial = True
                self.fields['index_object_name'].initial = (value, value)
            if name == 'x-container-meta-web-listings':
                self.fields['html_listing'].initial = value == 'true'
            if name == 'x-container-meta-web-listings-css':
                self.fields['use_css_in_listing'].initial = True
                self.fields['css_object_name'].initial = (value, value)
            if name == 'x-container-meta-web-error':
                self.fields['error'].value = value

    def handle(self, request, data):
        hdrs = {}
        index_object_name = data['index_object_name']
        css_object_name = data['css_object_name']
        public_html = data['public_html']
        error = data['error']
        try:
            error = error.encode('ascii')
        except Exception, e:
            messages.error(
                request,
                'Container Public contains non-ASCII character %s' % str(e))
            return
        html_listing = data['html_listing']
        use_css_in_listing = data['use_css_in_listing']
        container_name = data['container_name']
        for name in ['Index', 'Listings', 'Listings-Css', 'Error']:
            hdrs['X-Container-Meta-Web-' + name] = ''
        if public_html:
            hdrs['X-Container-Meta-Web-Index'] = index_object_name
        if html_listing:
            hdrs['X-Container-Meta-Web-Listings'] = 'true'
        if use_css_in_listing:
            hdrs['X-Container-Meta-Web-Listings-Css'] = css_object_name
        if error:
            hdrs['X-Container-Meta-Web-Error'] = error

        try:
            api.swift_set_container_info(request, container_name, hdrs)
        except Exception, e:
            messages.error(
                request,
                'Unable to set container metadata for public : %s' % str(e))
            return