@@ -1303,6 +1303,153 @@ 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+ context 'icmp protocol contains an IPv6 destination' do
1336+ let ( :rules ) do
1337+ [
1338+ {
1339+ protocol : 'icmp' ,
1340+ destination : '2001:db8::/32' ,
1341+ type : -1 ,
1342+ code : 255
1343+ }
1344+ ]
1345+ end
1346+
1347+ it 'is invalid' do
1348+ expect ( subject ) . not_to be_valid
1349+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmp" you cannot use IPv6 addresses'
1350+ end
1351+ end
1352+
1353+ context 'icmp protocol contains a comma-delimited list of IPv6 destinations' do
1354+ before do
1355+ TestConfig . config [ :security_groups ] [ :enable_comma_delimited_destinations ] = true
1356+ end
1357+
1358+ let ( :rules ) do
1359+ [
1360+ {
1361+ protocol : 'icmp' ,
1362+ destination : '2001:db8::/32,2001:db8:85a3::/64' ,
1363+ type : -1 ,
1364+ code : 255
1365+ }
1366+ ]
1367+ end
1368+
1369+ it 'is invalid' do
1370+ expect ( subject ) . not_to be_valid
1371+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmp" you cannot use IPv6 addresses'
1372+ end
1373+ end
1374+
1375+ context 'icmpv6 protocol contains an IPv6 destination' do
1376+ let ( :rules ) do
1377+ [
1378+ {
1379+ protocol : 'icmpv6' ,
1380+ destination : '2001:db8::/32' ,
1381+ type : -1 ,
1382+ code : 255
1383+ }
1384+ ]
1385+ end
1386+
1387+ it 'is valid' do
1388+ expect ( subject ) . to be_valid
1389+ end
1390+ end
1391+
1392+ context 'icmpv6 protocol contains a comma-delimited list of IPv6 destinations' do
1393+ before do
1394+ TestConfig . config [ :security_groups ] [ :enable_comma_delimited_destinations ] = true
1395+ end
1396+
1397+ let ( :rules ) do
1398+ [
1399+ {
1400+ protocol : 'icmpv6' ,
1401+ destination : '2001:db8::/32,2001:db8:85a3::/64' ,
1402+ type : -1 ,
1403+ code : 255
1404+ }
1405+ ]
1406+ end
1407+
1408+ it 'is valid' do
1409+ expect ( subject ) . to be_valid
1410+ end
1411+ end
1412+
1413+ context 'icmpv6 protocol contains an IPv4 destination' do
1414+ let ( :rules ) do
1415+ [
1416+ {
1417+ protocol : 'icmpv6' ,
1418+ destination : '10.0.0.0/8' ,
1419+ type : -1 ,
1420+ code : 255
1421+ }
1422+ ]
1423+ end
1424+
1425+ it 'is invalid' do
1426+ expect ( subject ) . not_to be_valid
1427+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmpv6" you cannot use IPv4 addresses'
1428+ end
1429+ end
1430+
1431+ context 'icmpv6 protocol contains a comma-delimited list of IPv4 destinations' do
1432+ before do
1433+ TestConfig . config [ :security_groups ] [ :enable_comma_delimited_destinations ] = true
1434+ end
1435+
1436+ let ( :rules ) do
1437+ [
1438+ {
1439+ protocol : 'icmpv6' ,
1440+ destination : '10.0.0.0/8,192.168.0.0/16' ,
1441+ type : -1 ,
1442+ code : 255
1443+ }
1444+ ]
1445+ end
1446+
1447+ it 'is invalid' do
1448+ expect ( subject ) . not_to be_valid
1449+ expect ( subject . errors . full_messages ) . to include 'Rules[0]: for protocol "icmpv6" you cannot use IPv4 addresses'
1450+ end
1451+ end
1452+ end
13061453 end
13071454 end
13081455end
0 commit comments