Change response status code when start_date and end_date are invalid

The create lease API and the update lease API return a 403 response
status code when start_date and end_date have an invalid time order.
A 403 response status code means the API request is Not Authorized,
which can confuse the client.

This patch changes blazar-api to return a 400 response status code when
the two dates have an invalid time order.

Change-Id: I5603212b8c70388aa7d2da883ec0c62f564807e5
This commit is contained in:
Masahito Muroi 2018-06-08 18:39:23 +09:00 committed by Pierre Riteau
parent 70a44bc7b3
commit 4b23129d05
2 changed files with 10 additions and 10 deletions

View File

@ -253,7 +253,7 @@ class ManagerService(service_utils.RPCServer):
end_date = self._date_from_string(end_date)
if start_date < now:
raise common_ex.NotAuthorized(
raise common_ex.InvalidInput(
'Start date must be later than current date')
if end_date <= start_date:
@ -383,21 +383,21 @@ class ManagerService(service_utils.RPCServer):
if (lease['start_date'] < now and
values['start_date'] != lease['start_date']):
raise common_ex.NotAuthorized(
raise common_ex.InvalidInput(
'Cannot modify the start date of already started leases')
if (lease['start_date'] > now and
values['start_date'] < now):
raise common_ex.NotAuthorized(
raise common_ex.InvalidInput(
'Start date must be later than current date')
if lease['end_date'] < now:
raise common_ex.NotAuthorized(
raise common_ex.InvalidInput(
'Terminated leases can only be renamed')
if (values['end_date'] < now or
values['end_date'] < values['start_date']):
raise common_ex.NotAuthorized(
raise common_ex.InvalidInput(
'End date must be later than current and start date')
with trusts.create_ctx_from_trust(lease['trust_id']):

View File

@ -656,7 +656,7 @@ class ServiceTestCase(tests.TestCase):
'trust_id': 'exxee111qwwwwe'}
self.assertRaises(
exceptions.NotAuthorized, self.manager.create_lease, lease_values)
exceptions.InvalidInput, self.manager.create_lease, lease_values)
def test_create_lease_end_before_start(self):
lease_values = {
@ -1220,7 +1220,7 @@ class ServiceTestCase(tests.TestCase):
mock.Mock(wraps=datetime.datetime)) as patched:
patched.utcnow.return_value = target
self.assertRaises(
exceptions.NotAuthorized, self.manager.update_lease,
exceptions.InvalidInput, self.manager.update_lease,
lease_id=self.lease_id, values=lease_values)
def test_update_lease_not_started_start_date_before_current_time(self):
@ -1234,7 +1234,7 @@ class ServiceTestCase(tests.TestCase):
mock.Mock(wraps=datetime.datetime)) as patched:
patched.utcnow.return_value = target
self.assertRaises(
exceptions.NotAuthorized, self.manager.update_lease,
exceptions.InvalidInput, self.manager.update_lease,
lease_id=self.lease_id, values=lease_values)
def test_update_lease_end_date_before_current_time(self):
@ -1248,7 +1248,7 @@ class ServiceTestCase(tests.TestCase):
mock.Mock(wraps=datetime.datetime)) as patched:
patched.utcnow.return_value = target
self.assertRaises(
exceptions.NotAuthorized, self.manager.update_lease,
exceptions.InvalidInput, self.manager.update_lease,
lease_id=self.lease_id, values=lease_values)
def test_update_lease_completed_modify_dates(self):
@ -1262,7 +1262,7 @@ class ServiceTestCase(tests.TestCase):
mock.Mock(wraps=datetime.datetime)) as patched:
patched.utcnow.return_value = target
self.assertRaises(
exceptions.NotAuthorized, self.manager.update_lease,
exceptions.InvalidInput, self.manager.update_lease,
lease_id=self.lease_id, values=lease_values)
def test_update_lease_start_date_event_not_found(self):