Check time order between start_date and end_date
The create lease API doesn't check time order between start_date and end_date. This allows users to create leases that end before they start. Change-Id: I90b0559f22cbde9e68727de73958cc778a84d698
This commit is contained in:
parent
505ce767ad
commit
539f32ce23
|
@ -256,6 +256,10 @@ class ManagerService(service_utils.RPCServer):
|
|||
raise common_ex.NotAuthorized(
|
||||
'Start date must be later than current date')
|
||||
|
||||
if end_date <= start_date:
|
||||
raise common_ex.InvalidInput(
|
||||
'End date must be later than start date.')
|
||||
|
||||
with trusts.create_ctx_from_trust(trust_id) as ctx:
|
||||
# NOTE(priteau): We should not get user_id from ctx, because we are
|
||||
# in the context of the trustee (blazar user).
|
||||
|
|
|
@ -658,6 +658,16 @@ class ServiceTestCase(tests.TestCase):
|
|||
self.assertRaises(
|
||||
exceptions.NotAuthorized, self.manager.create_lease, lease_values)
|
||||
|
||||
def test_create_lease_end_before_start(self):
|
||||
lease_values = {
|
||||
'name': 'lease-name',
|
||||
'start_date': '2026-11-13 13:13',
|
||||
'end_date': '2026-11-13 12:13',
|
||||
'trust_id': 'exxee111qwwwwe'}
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.InvalidInput, self.manager.create_lease, lease_values)
|
||||
|
||||
def test_create_lease_unsupported_resource_type(self):
|
||||
lease_values = {
|
||||
'id': self.lease_id,
|
||||
|
|
Loading…
Reference in New Issue