builder.ipProtocol(IpProtocol.TCP);
builder.fromPort(50);
builder.toPort(60);
builder.cidrBlock("0.0.0.0/0");
IpPermission perm = builder.build();
SecurityGroup newGroup = securityGroupExtension.get().addIpPermission(IpProtocol.TCP,
50,
60,
emptyMultimap(),
ImmutableSet.of("0.0.0.0/0"),
emptyStringSet(),
group);
assertTrue(newGroup.getIpPermissions().contains(perm));
if (securityGroupExtension.get().supportsGroupIds()) {
IpPermission.Builder secondBuilder = IpPermission.builder();
int fromPort;
int toPort;
if (securityGroupExtension.get().supportsPortRangesForGroups()) {
fromPort = 70;
toPort = 80;
} else {
fromPort = 1;
toPort = 65535;
}
secondBuilder.ipProtocol(IpProtocol.TCP);
secondBuilder.fromPort(fromPort);
secondBuilder.toPort(toPort);
secondBuilder.groupId(group.getId());
IpPermission secondPerm = secondBuilder.build();
SecurityGroup secondNewGroup = securityGroupExtension.get().addIpPermission(IpProtocol.TCP,
fromPort,
toPort,
emptyMultimap(),
emptyStringSet(),
ImmutableSet.of(group.getId()),
newGroup);
assertTrue(secondNewGroup.getIpPermissions().contains(secondPerm), "permissions for second group should contain "
+ secondPerm + " but do not: " + secondNewGroup.getIpPermissions());
}
if (securityGroupExtension.get().supportsTenantIdGroupNamePairs()
|| securityGroupExtension.get().supportsTenantIdGroupIdPairs()) {
IpPermission.Builder thirdBuilder = IpPermission.builder();
int fromPort;
int toPort;
if (securityGroupExtension.get().supportsPortRangesForGroups()) {
fromPort = 90;
toPort = 100;
} else {
fromPort = 1;
toPort = 65535;
}
thirdBuilder.ipProtocol(IpProtocol.TCP);
thirdBuilder.fromPort(fromPort);
thirdBuilder.toPort(toPort);
if (securityGroupExtension.get().supportsTenantIdGroupIdPairs()) {
thirdBuilder.tenantIdGroupNamePair(group.getOwnerId(), group.getProviderId());
} else if (securityGroupExtension.get().supportsTenantIdGroupNamePairs()) {
thirdBuilder.tenantIdGroupNamePair(group.getOwnerId(), group.getName());
}
IpPermission thirdPerm = thirdBuilder.build();
SecurityGroup thirdNewGroup = securityGroupExtension.get().addIpPermission(IpProtocol.TCP,
fromPort,
toPort,
thirdPerm.getTenantIdGroupNamePairs(),
emptyStringSet(),
emptyStringSet(),
newGroup);
assertTrue(thirdNewGroup.getIpPermissions().contains(thirdPerm));