Ejemplo n.º 1
0
 def test_package_update_public_public_fqn_violation(self):
     id1 = api.package_upload(self._stub_package(), self.tenant_id).id
     id2 = api.package_upload(self._stub_package(), self.tenant_id_2).id
     patch = self.get_change('replace', ['is_public'], True)
     api.package_update(id1, [patch], self.context)
     self.assertRaises(exc.HTTPConflict, api.package_update,
                       id2, [patch], self.context_2)
Ejemplo n.º 2
0
 def test_package_update_public_public_fqn_violation(self):
     id1 = api.package_upload(self._stub_package(), self.tenant_id).id
     id2 = api.package_upload(self._stub_package(), self.tenant_id_2).id
     patch = self.get_change('replace', ['is_public'], True)
     api.package_update(id1, [patch], self.context)
     self.assertRaises(exc.HTTPConflict, api.package_update, id2, [patch],
                       self.context_2)
Ejemplo n.º 3
0
 def test_package_update_public_public_class_name_violation(self):
     id1 = api.package_upload(self._stub_package(class_definitions=("foo", "bar")), self.tenant_id).id
     id2 = api.package_upload(
         self._stub_package(class_definitions=("foo", "bar"), fully_qualified_name="com.example.package2"),
         self.tenant_id_2,
     ).id
     patch = self.get_change("replace", ["is_public"], True)
     api.package_update(id1, [patch], self.context)
     self.assertRaises(exc.HTTPConflict, api.package_update, id2, [patch], self.context_2)
Ejemplo n.º 4
0
 def test_package_update_public_public_class_name_violation(self):
     id1 = api.package_upload(self._stub_package(
         class_definitions=('foo', 'bar')), self.tenant_id).id
     id2 = api.package_upload(self._stub_package(
         class_definitions=('foo', 'bar'),
         fully_qualified_name='com.example.package2'), self.tenant_id_2).id
     patch = self.get_change('replace', ['is_public'], True)
     api.package_update(id1, [patch], self.context)
     self.assertRaises(exc.HTTPConflict, api.package_update,
                       id2, [patch], self.context_2)
Ejemplo n.º 5
0
 def test_authorize_package_delete_error(self):
     values = self._stub_package()
     package = api.package_upload(values, self.tenant_id)
     self.assertRaises(exc.HTTPForbidden, api._authorize_package, package,
                       self.context_2)
     self.assertRaises(exc.HTTPForbidden,
                       api.package_delete, package.id, self.context_2)
     id = package.id
     patch = self.get_change('replace', ['is_public'], False)
     api.package_update(id, [patch], self.context)
     self.assertRaises(exc.HTTPForbidden, api._authorize_package, package,
                       self.context_2, allow_public=True)
Ejemplo n.º 6
0
    def update(self, req, body, package_id):
        """List of allowed changes:
            { "op": "add", "path": "/tags", "value": [ "foo", "bar" ] }
            { "op": "add", "path": "/categories", "value": [ "foo", "bar" ] }
            { "op": "remove", "path": "/tags" }
            { "op": "remove", "path": "/categories" }
            { "op": "replace", "path": "/tags", "value": ["foo", "bar"] }
            { "op": "replace", "path": "/is_public", "value": true }
            { "op": "replace", "path": "/description",
                                "value":"New description" }
            { "op": "replace", "path": "/name", "value": "New name" }
        """
        policy.check("modify_package", req.context, {'package_id': package_id})

        pkg_to_update = db_api.package_get(package_id, req.context)
        if pkg_to_update.is_public:
            policy.check("manage_public_package", req.context)

        _check_content_type(req, 'application/murano-packages-json-patch')
        if not isinstance(body, list):
            msg = _('Request body must be a JSON array of operation objects.')
            LOG.error(msg)
            raise exc.HTTPBadRequest(explanation=msg)
        for change in body:
            if 'is_public' in change['path']:
                if change['value'] is True and not pkg_to_update.is_public:
                    policy.check('publicize_package', req.context)
            if 'name' in change['path']:
                if len(change['value']) > 80:
                    msg = _('Package name should be 80 characters maximum')
                    LOG.error(msg)
                    raise exc.HTTPBadRequest(explanation=msg)
        package = db_api.package_update(package_id, body, req.context)
        return package.to_dict()
Ejemplo n.º 7
0
    def update(self, req, body, package_id):
        """List of allowed changes:
            { "op": "add", "path": "/tags", "value": [ "foo", "bar" ] }
            { "op": "add", "path": "/categories", "value": [ "foo", "bar" ] }
            { "op": "remove", "path": "/tags" }
            { "op": "remove", "path": "/categories" }
            { "op": "replace", "path": "/tags", "value": ["foo", "bar"] }
            { "op": "replace", "path": "/is_public", "value": true }
            { "op": "replace", "path": "/description",
                                "value":"New description" }
            { "op": "replace", "path": "/name", "value": "New name" }
        """
        policy.check("modify_package", req.context, {'package_id': package_id})

        pkg_to_update = db_api.package_get(package_id, req.context)
        if pkg_to_update.is_public:
            policy.check("manage_public_package", req.context)

        _check_content_type(req, 'application/murano-packages-json-patch')
        if not isinstance(body, list):
            msg = _('Request body must be a JSON array of operation objects.')
            LOG.error(msg)
            raise exc.HTTPBadRequest(explanation=msg)
        for change in body:
            if 'is_public' in change['path']:
                if change['value'] is True and not pkg_to_update.is_public:
                    policy.check('publicize_package', req.context)
                break
        package = db_api.package_update(package_id, body, req.context)
        return package.to_dict()
Ejemplo n.º 8
0
    def update(self, req, body, package_id):
        """List of allowed changes:
            { "op": "add", "path": "/tags", "value": [ "foo", "bar" ] }
            { "op": "add", "path": "/categories", "value": [ "foo", "bar" ] }
            { "op": "remove", "path": "/tags" }
            { "op": "remove", "path": "/categories" }
            { "op": "replace", "path": "/tags", "value": ["foo", "bar"] }
            { "op": "replace", "path": "/is_public", "value": true }
            { "op": "replace", "path": "/description",
                                "value":"New description" }
            { "op": "replace", "path": "/name", "value": "New name" }
        """
        policy.check("update_package", req.context, {'package_id': package_id})

        _check_content_type(req, 'application/murano-packages-json-patch')
        if not isinstance(body, list):
            msg = _('Request body must be a JSON array of operation objects.')
            LOG.error(msg)
            raise exc.HTTPBadRequest(explanation=msg)
        package = db_api.package_update(package_id, body, req.context)

        return package.to_dict()
Ejemplo n.º 9
0
    def update(self, req, body, package_id):
        """List of allowed changes:
            { "op": "add", "path": "/tags", "value": [ "foo", "bar" ] }
            { "op": "add", "path": "/categories", "value": [ "foo", "bar" ] }
            { "op": "remove", "path": "/tags" }
            { "op": "remove", "path": "/categories" }
            { "op": "replace", "path": "/tags", "value": ["foo", "bar"] }
            { "op": "replace", "path": "/is_public", "value": true }
            { "op": "replace", "path": "/description",
                                "value":"New description" }
            { "op": "replace", "path": "/name", "value": "New name" }
        """
        policy.check("update_package", req.context, {'package_id': package_id})

        _check_content_type(req, 'application/murano-packages-json-patch')
        if not isinstance(body, list):
            msg = _('Request body must be a JSON array of operation objects.')
            LOG.error(msg)
            raise exc.HTTPBadRequest(explanation=msg)
        package = db_api.package_update(package_id, body, req.context)

        return package.to_dict()
Ejemplo n.º 10
0
 def test_package_make_public(self):
     id = api.package_upload(self._stub_package(), self.tenant_id).id
     patch = self.get_change('replace', ['is_public'], True)
     api.package_update(id, [patch], self.context)
     package = api.package_get(id, self.context)
     self.assertTrue(package.is_public)
Ejemplo n.º 11
0
 def test_package_make_public(self):
     id = api.package_upload(self._stub_package(), self.tenant_id).id
     patch = self.get_change('replace', ['is_public'], True)
     api.package_update(id, [patch], self.context)
     package = api.package_get(id, self.context)
     self.assertTrue(package.is_public)
Ejemplo n.º 12
0
 def test_package_make_public(self):
     id = api.package_upload(self._stub_package(), self.tenant_id).id
     patch = self.get_change("replace", ["is_public"], True)
     api.package_update(id, [patch], self.context)
     package = api.package_get(id, self.context)
     self.assertEqual(True, package.is_public)