389
394
group.authorize('tcp', 80, 81, '0.0.0.0/0')
390
395
group.authorize('icmp', -1, -1, '0.0.0.0/0')
391
396
group.authorize('udp', 80, 81, '0.0.0.0/0')
398
def _assert(message, *args):
400
group.authorize(*args)
401
except boto_exc.EC2ResponseError as e:
402
self.assertEqual(e.status, 400, 'Expected status to be 400')
403
self.assertIn(message, e.error_message, e.error_message)
405
raise self.failureException, 'EC2ResponseError not raised'
392
407
# Invalid CIDR address
393
self.assertRaises(Exception,
394
group.authorize, 'tcp', 80, 81, '0.0.0.0/0444')
408
_assert('Invalid CIDR', 'tcp', 80, 81, '0.0.0.0/0444')
396
self.assertRaises(Exception,
397
group.authorize, 'tcp', '0.0.0.0/0')
410
_assert('Not enough parameters', 'tcp', '0.0.0.0/0')
398
411
# from port cannot be greater than to port
399
self.assertRaises(Exception,
400
group.authorize, 'tcp', 100, 1, '0.0.0.0/0')
412
_assert('Invalid port range', 'tcp', 100, 1, '0.0.0.0/0')
401
413
# For tcp, negative values are not allowed
402
self.assertRaises(Exception,
403
group.authorize, 'tcp', -1, 1, '0.0.0.0/0')
414
_assert('Invalid port range', 'tcp', -1, 1, '0.0.0.0/0')
404
415
# For tcp, valid port range 1-65535
405
self.assertRaises(Exception,
406
group.authorize, 'tcp', 1, 65599, '0.0.0.0/0')
416
_assert('Invalid port range', 'tcp', 1, 65599, '0.0.0.0/0')
407
417
# For icmp, only -1:-1 is allowed for type:code
408
self.assertRaises(Exception,
409
group.authorize, 'icmp', -1, 0, '0.0.0.0/0')
418
_assert('An unknown error has occurred', 'icmp', -1, 0, '0.0.0.0/0')
410
419
# Non valid type:code
411
self.assertRaises(Exception,
412
group.authorize, 'icmp', 0, 3, '0.0.0.0/0')
420
_assert('An unknown error has occurred', 'icmp', 0, 3, '0.0.0.0/0')
413
421
# Invalid Cidr for ICMP type
414
self.assertRaises(Exception,
415
group.authorize, 'icmp', -1, -1, '0.0.444.0/4')
422
_assert('Invalid CIDR', 'icmp', -1, -1, '0.0.444.0/4')
416
423
# Invalid protocol
417
self.assertRaises(Exception,
418
group.authorize, 'xyz', 1, 14, '0.0.0.0/0')
424
_assert('An unknown error has occurred', 'xyz', 1, 14, '0.0.0.0/0')
420
self.assertRaises(Exception,
421
group.authorize, 'tcp', " ", "81", '0.0.0.0/0')
426
_assert('An unknown error has occurred', 'tcp', " ", "81", '0.0.0.0/0')
422
427
# Invalid icmp port
423
self.assertRaises(Exception,
424
group.authorize, 'icmp', " ", "81", '0.0.0.0/0')
425
# Invalid CIDR Address
426
self.assertRaises(Exception,
427
group.authorize, 'icmp', -1, -1, '0.0.0.0')
428
# Invalid CIDR Address
429
self.assertRaises(Exception,
430
group.authorize, 'icmp', -1, -1, '0.0.0.0/')
428
_assert('An unknown error has occurred', 'icmp', " ", "81",
430
# Invalid CIDR Address
431
_assert('Invalid CIDR', 'icmp', -1, -1, '0.0.0.0')
432
# Invalid CIDR Address
433
_assert('Invalid CIDR', 'icmp', -1, -1, '0.0.0.0/')
431
434
# Invalid Cidr ports
432
self.assertRaises(Exception,
433
group.authorize, 'icmp', 1, 256, '0.0.0.0/0')
435
_assert('Invalid port range', 'icmp', 1, 256, '0.0.0.0/0')
435
437
self.expect_http()
436
438
self.mox.ReplayAll()