@authenticate
def test_no_credentials_exception(self):
resp = self._get('/api/rgw/proxy/status')
- self.assertStatus(401)
- self.assertIn('message', resp)
+ self.assertStatus(500)
+ self.assertIn('detail', resp)
class RgwProxyTest(DashboardTestCase):
self.assertStatus(200)
self._delete('/api/rgw/proxy/user', params={'uid': 'teuth-test-user'})
- self.assertStatus(404)
+ self.assertStatus(500)
resp = self._resp.json()
- self.assertIn('Code', resp)
- self.assertIn('HostId', resp)
- self.assertIn('RequestId', resp)
- self.assertEqual(resp['Code'], 'NoSuchUser')
+ self.assertIn('detail', resp)
+ self.assertIn('failed request with status code 404', resp['detail'])
+ self.assertIn('"Code":"NoSuchUser"', resp['detail'])
+ self.assertIn('"HostId"', resp['detail'])
+ self.assertIn('"RequestId"', resp['detail'])
@authenticate
def test_rgw_proxy(self):
from .. import logger
from ..services.ceph_service import CephService
from ..services.rgw_client import RgwClient
-from ..rest_client import RequestException
-from ..exceptions import NoCredentialsException
@ApiController('rgw')
try:
rgw_client = RgwClient.admin_instance()
- except NoCredentialsException as e:
- cherrypy.response.headers['Content-Type'] = 'application/json'
- cherrypy.response.status = 401
- return json.dumps({'message': str(e)}).encode('utf-8')
-
- method = cherrypy.request.method
- data = None
+ method = cherrypy.request.method
+ data = None
- if cherrypy.request.body.length:
- data = cherrypy.request.body.read()
+ if cherrypy.request.body.length:
+ data = cherrypy.request.body.read()
- try:
return rgw_client.proxy(method, path, params, data)
- except RequestException as e:
- cherrypy.response.status = e.status_code
- return e.content
+ except Exception as e: # pylint: disable=broad-except
+ # Always use status code 500 and NOT the status that may delivered
+ # by the exception. That's because we do not want to forward e.g.
+ # 401 or 404 that may trigger unwanted actions in the UI.
+ cherrypy.response.headers['Content-Type'] = 'application/json'
+ cherrypy.response.status = 500
+ return json.dumps({'detail': str(e)}).encode('utf-8')