diff --git a/openbrokerapi/api.py b/openbrokerapi/api.py index d20c121..db74a71 100644 --- a/openbrokerapi/api.py +++ b/openbrokerapi/api.py @@ -124,6 +124,13 @@ def error_handler_bad_request(e): description=constants.DEFAULT_BAD_REQUEST_ERROR_MESSAGE )), HTTPStatus.BAD_REQUEST + @openbroker.errorhandler(errors.ErrUnauthorized) + def error_handler_unauthorized(e): + logger.exception(e) + return to_json_response(ErrorResponse( + description=str(e) + )), HTTPStatus.UNAUTHORIZED + @openbroker.route("/v2/catalog", methods=['GET']) def catalog(): """ diff --git a/openbrokerapi/errors.py b/openbrokerapi/errors.py index e429ca3..9b8c9a0 100644 --- a/openbrokerapi/errors.py +++ b/openbrokerapi/errors.py @@ -68,3 +68,10 @@ class ErrBadRequest(ServiceException): """ def __init__(self, msg='Malformed or missing data'): super().__init__(msg) + +class ErrUnauthorized(ServiceException): + """ + Raise if authorization is missing or is not valid + """ + def __init__(self, msg='Unauthorized'): + super().__init__(msg) \ No newline at end of file diff --git a/tests/test_bad_request.py b/tests/test_bad_request.py index ead83f1..f1a1749 100644 --- a/tests/test_bad_request.py +++ b/tests/test_bad_request.py @@ -107,14 +107,27 @@ def test_unbind_is_called_with_the_right_values(self): self.assert400(response) - def test_deprovisioning_is_called_with_the_right_values(self): - self.broker.deprovision.side_effect = errors.ErrBadRequest('BadRequest') + def test_provisioning_unathorized(self): + self.broker.provision.side_effect = errors.ErrUnauthorized('Unauthorized') - response = self.client.delete( - "/v2/service_instances/here_instance_id?service_id=service-guid-here&plan_id=plan-guid-here&accepts_incomplete=true", + response = self.client.put( + "/v2/service_instances/here-instance-id?accepts_incomplete=true", + data=json.dumps({ + "service_id": "service-guid-here", + "plan_id": "plan-guid-here", + "organization_guid": "org-guid-here", + "space_guid": "space-guid-here", + "parameters": { + "parameter1": 1 + }, + "context": { + "organization_guid": "org-guid-here", + "space_guid": "space-guid-here", + } + }), headers={ 'X-Broker-Api-Version': '2.13', + 'Content-Type': 'application/json', 'Authorization': self.auth_header }) - - self.assert400(response) \ No newline at end of file + self.assert401(response) \ No newline at end of file