@@ -48,9 +48,9 @@ def self.name
4848
4949 it 'returns indexed errors corresponding to each invalid rule' do
5050 expect ( subject ) . not_to be_valid
51- expect ( subject . errors . full_messages ) . to include "Rules[0]: protocol must be 'tcp', 'udp', 'icmp', or 'all'"
51+ expect ( subject . errors . full_messages ) . to include "Rules[0]: protocol must be 'tcp', 'udp', 'icmp', 'icmpv6' or 'all'"
5252 expect ( subject . errors . full_messages ) . to include 'Rules[0]: destination must be a valid CIDR, IP address, or IP address range'
53- expect ( subject . errors . full_messages ) . to include "Rules[1]: protocol must be 'tcp', 'udp', 'icmp', or 'all'"
53+ expect ( subject . errors . full_messages ) . to include "Rules[1]: protocol must be 'tcp', 'udp', 'icmp', 'icmpv6' or 'all'"
5454 expect ( subject . errors . full_messages ) . to include 'Rules[1]: destination must be a valid CIDR, IP address, or IP address range'
5555 end
5656 end
@@ -1064,7 +1064,7 @@ def self.name
10641064
10651065 it 'adds an error' do
10661066 expect ( subject ) . not_to be_valid
1067- expect ( subject . errors . full_messages ) . to include "Rules[0]: protocol must be 'tcp', 'udp', 'icmp', or 'all'"
1067+ expect ( subject . errors . full_messages ) . to include "Rules[0]: protocol must be 'tcp', 'udp', 'icmp', 'icmpv6' or 'all'"
10681068 end
10691069 end
10701070
@@ -1073,7 +1073,7 @@ def self.name
10731073
10741074 it 'is not valid' do
10751075 expect ( subject ) . not_to be_valid
1076- expect ( subject . errors . full_messages ) . to include "Rules[0]: protocol must be 'tcp', 'udp', 'icmp', or 'all'"
1076+ expect ( subject . errors . full_messages ) . to include "Rules[0]: protocol must be 'tcp', 'udp', 'icmp', 'icmpv6' or 'all'"
10771077 end
10781078 end
10791079
@@ -1082,7 +1082,7 @@ def self.name
10821082
10831083 it 'adds an error' do
10841084 expect ( subject ) . not_to be_valid
1085- expect ( subject . errors . full_messages ) . to include "Rules[0]: protocol must be 'tcp', 'udp', 'icmp', or 'all'"
1085+ expect ( subject . errors . full_messages ) . to include "Rules[0]: protocol must be 'tcp', 'udp', 'icmp', 'icmpv6' or 'all'"
10861086 end
10871087 end
10881088
@@ -1303,6 +1303,208 @@ def self.name
13031303 expect ( subject . errors . full_messages ) . to include 'Rules[0]: code must be an integer between -1 and 255 (inclusive)'
13041304 end
13051305 end
1306+
1307+ context 'ipv6 is disabled' do
1308+ before do
1309+ TestConfig . config [ :enable_ipv6 ] = false
1310+ end
1311+
1312+ context 'icmpv6 protocol in a rule' do
1313+ let ( :rules ) do
1314+ [
1315+ {
1316+ protocol : 'icmpv6' ,
1317+ destination : '2001:db8::/32' ,
1318+ type : -1 ,
1319+ code : 255
1320+ }
1321+ ]
1322+ end
1323+
1324+ it 'is not valid' do
1325+ expect ( subject ) . not_to be_valid
1326+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: icmpv6 cannot be used if enable_ipv6 is false'
1327+ end
1328+ end
1329+ end
1330+
1331+ context 'ipv6 is enabled' do
1332+ before do
1333+ TestConfig . config [ :enable_ipv6 ] = true
1334+ end
1335+
1336+ context 'icmp protocol contains an IPv6 destination' do
1337+ let ( :rules ) do
1338+ [
1339+ {
1340+ protocol : 'icmp' ,
1341+ destination : '2001:db8::/32' ,
1342+ type : -1 ,
1343+ code : 255
1344+ }
1345+ ]
1346+ end
1347+
1348+ it 'is invalid' do
1349+ expect ( subject ) . not_to be_valid
1350+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmp" you cannot use IPv6 addresses'
1351+ end
1352+ end
1353+
1354+ context 'icmp protocol contains an IPv6 destination range' do
1355+ let ( :rules ) do
1356+ [
1357+ {
1358+ protocol : 'icmp' ,
1359+ destination : '2001:0db8::1-2001:0db8::ff' ,
1360+ type : -1 ,
1361+ code : 255
1362+ }
1363+ ]
1364+ end
1365+
1366+ it 'is invalid' do
1367+ expect ( subject ) . not_to be_valid
1368+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmp" you cannot use IPv6 addresses'
1369+ end
1370+ end
1371+
1372+ context 'icmp protocol contains a comma-delimited list of IPv6 destinations' do
1373+ before do
1374+ TestConfig . config [ :security_groups ] [ :enable_comma_delimited_destinations ] = true
1375+ end
1376+
1377+ let ( :rules ) do
1378+ [
1379+ {
1380+ protocol : 'icmp' ,
1381+ destination : '2001:db8::/32,2001:db8:85a3::/64' ,
1382+ type : -1 ,
1383+ code : 255
1384+ }
1385+ ]
1386+ end
1387+
1388+ it 'is invalid' do
1389+ expect ( subject ) . not_to be_valid
1390+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmp" you cannot use IPv6 addresses'
1391+ end
1392+ end
1393+
1394+ context 'icmpv6 protocol contains an IPv6 destination' do
1395+ let ( :rules ) do
1396+ [
1397+ {
1398+ protocol : 'icmpv6' ,
1399+ destination : '2001:db8::/32' ,
1400+ type : -1 ,
1401+ code : 255
1402+ }
1403+ ]
1404+ end
1405+
1406+ it 'is valid' do
1407+ expect ( subject ) . to be_valid
1408+ end
1409+ end
1410+
1411+ context 'icmpv6 protocol contains a comma-delimited list of IPv6 destinations' do
1412+ before do
1413+ TestConfig . config [ :security_groups ] [ :enable_comma_delimited_destinations ] = true
1414+ end
1415+
1416+ let ( :rules ) do
1417+ [
1418+ {
1419+ protocol : 'icmpv6' ,
1420+ destination : '2001:db8::/32,2001:db8:85a3::/64' ,
1421+ type : -1 ,
1422+ code : 255
1423+ }
1424+ ]
1425+ end
1426+
1427+ it 'is valid' do
1428+ expect ( subject ) . to be_valid
1429+ end
1430+ end
1431+
1432+ context 'icmpv6 protocol contains an IPv4 destination' do
1433+ let ( :rules ) do
1434+ [
1435+ {
1436+ protocol : 'icmpv6' ,
1437+ destination : '10.0.0.0/8' ,
1438+ type : -1 ,
1439+ code : 255
1440+ }
1441+ ]
1442+ end
1443+
1444+ it 'is invalid' do
1445+ expect ( subject ) . not_to be_valid
1446+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmpv6" you cannot use IPv4 addresses'
1447+ end
1448+ end
1449+
1450+ context 'icmpv6 protocol contains an IPv4 destination range' do
1451+ let ( :rules ) do
1452+ [
1453+ {
1454+ protocol : 'icmpv6' ,
1455+ destination : '1.0.0.000-1.0.0.200' ,
1456+ type : -1 ,
1457+ code : 255
1458+ }
1459+ ]
1460+ end
1461+
1462+ it 'is invalid' do
1463+ expect ( subject ) . not_to be_valid
1464+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmpv6" you cannot use IPv4 addresses'
1465+ end
1466+ end
1467+
1468+ context 'icmpv6 protocol contains a comma-delimited list of IPv4/IPv6 destinations' do
1469+ before do
1470+ TestConfig . config [ :security_groups ] [ :enable_comma_delimited_destinations ] = true
1471+ end
1472+
1473+ let ( :rules ) do
1474+ [
1475+ {
1476+ protocol : 'icmpv6' ,
1477+ destination : '10.0.0.0/8,2001:db8::/32' ,
1478+ type : -1 ,
1479+ code : 255
1480+ }
1481+ ]
1482+ end
1483+
1484+ it 'is invalid' do
1485+ expect ( subject ) . not_to be_valid
1486+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmpv6" you cannot use IPv4 addresses'
1487+ end
1488+ end
1489+
1490+ context 'the icmp rules are not provided when the protocol is icmpv6' do
1491+ let ( :rules ) do
1492+ [
1493+ {
1494+ protocol : 'icmpv6' ,
1495+ destination : '2001:db8::/32'
1496+ }
1497+ ]
1498+ end
1499+
1500+ it 'is invalid' do
1501+ expect ( subject ) . not_to be_valid
1502+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: type is required for protocols of type ICMP'
1503+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: code is required for protocols of type ICMP'
1504+ end
1505+ end
1506+
1507+ end
13061508 end
13071509 end
13081510end
0 commit comments