use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class SecurityGroupsTest method testSinglePort.
@Test
public void testSinglePort() throws JSONException {
SecurityGroup sg = new SecurityGroup(_securityGroups.getJSONObject(0), null);
List<IpAccessListLine> inboundRules = new LinkedList<>();
List<IpAccessListLine> outboundRules = new LinkedList<>();
sg.addInOutAccessLines(inboundRules, outboundRules, _region);
assertThat(inboundRules, equalTo(ImmutableList.of(IpAccessListLine.builder().setAction(LineAction.ACCEPT).setIpProtocols(Sets.newHashSet(IpProtocol.TCP)).setSrcIps(Sets.newHashSet(new IpWildcard("1.2.3.4/32"))).setDstPorts(Sets.newHashSet(new SubRange(22, 22))).build(), _rejectSynOnly, _allowAllReverseOutboundRule)));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class SecurityGroupsTest method testStatefulTcpRules.
@Test
public void testStatefulTcpRules() throws JSONException {
SecurityGroup sg = new SecurityGroup(_securityGroups.getJSONObject(8), null);
List<IpAccessListLine> inboundRules = new LinkedList<>();
List<IpAccessListLine> outboundRules = new LinkedList<>();
sg.addInOutAccessLines(inboundRules, outboundRules, _region);
assertThat(inboundRules, equalTo(ImmutableList.of(IpAccessListLine.builder().setAction(LineAction.ACCEPT).setIpProtocols(Sets.newHashSet(IpProtocol.TCP)).setSrcIps(Sets.newHashSet(new IpWildcard("1.2.3.4/32"))).setDstPorts(Sets.newHashSet(new SubRange(22, 22))).build(), _rejectSynOnly, // reverse of outbound rule
IpAccessListLine.builder().setAction(LineAction.ACCEPT).setIpProtocols(Sets.newHashSet(IpProtocol.TCP)).setSrcIps(Sets.newHashSet(new IpWildcard("5.6.7.8/32"))).setSrcPorts(Sets.newHashSet(new SubRange(80, 80))).build())));
assertThat(outboundRules, equalTo(ImmutableList.of(IpAccessListLine.builder().setAction(LineAction.ACCEPT).setIpProtocols(Sets.newHashSet(IpProtocol.TCP)).setDstIps(Sets.newHashSet(new IpWildcard("5.6.7.8/32"))).setDstPorts(Sets.newHashSet(new SubRange(80, 80))).build(), _rejectSynOnly, // reverse of inbound rule
IpAccessListLine.builder().setAction(LineAction.ACCEPT).setIpProtocols(Sets.newHashSet(IpProtocol.TCP)).setDstIps(Sets.newHashSet(new IpWildcard("1.2.3.4/32"))).setSrcPorts(Sets.newHashSet(new SubRange(22, 22))).build())));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class SecurityGroupsTest method testBeginningHalfOpenInterval.
@Test
public void testBeginningHalfOpenInterval() throws JSONException {
SecurityGroup sg = new SecurityGroup(_securityGroups.getJSONObject(1), null);
List<IpAccessListLine> inboundRules = new LinkedList<>();
List<IpAccessListLine> outboundRules = new LinkedList<>();
sg.addInOutAccessLines(inboundRules, outboundRules, _region);
assertThat(inboundRules, equalTo(ImmutableList.of(IpAccessListLine.builder().setAction(LineAction.ACCEPT).setIpProtocols(Sets.newHashSet(IpProtocol.TCP)).setSrcIps(Sets.newHashSet(new IpWildcard("1.2.3.4/32"))).setDstPorts(Sets.newHashSet(new SubRange(0, 22))).build(), _rejectSynOnly, _allowAllReverseOutboundRule)));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class SecurityGroupsTest method setup.
@Before
public void setup() throws JSONException {
_securityGroups = new JSONObject(CommonUtil.readResource("org/batfish/representation/aws/SecurityGroupTest.json")).getJSONArray(JSON_KEY_SECURITY_GROUPS);
_rejectSynOnly = IpAccessListLine.builder().setTcpFlags(ImmutableSet.of(TcpFlags.SYN_ONLY)).setAction(LineAction.REJECT).build();
_allowAllReverseOutboundRule = IpAccessListLine.builder().setAction(LineAction.ACCEPT).setSrcIps(Sets.newHashSet(new IpWildcard("0.0.0.0/0"))).build();
_region = new Region("test");
_flowBuilder = new Builder();
_flowBuilder.setIngressNode("foo");
_flowBuilder.setTag("TEST");
_flowBuilder.setIpProtocol(IpProtocol.TCP);
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class SecurityGroupsTest method testInvalidEndInterval.
@Test
public void testInvalidEndInterval() throws JSONException {
SecurityGroup sg = new SecurityGroup(_securityGroups.getJSONObject(7), null);
List<IpAccessListLine> inboundRules = new LinkedList<>();
List<IpAccessListLine> outboundRules = new LinkedList<>();
sg.addInOutAccessLines(inboundRules, outboundRules, _region);
assertThat(inboundRules, equalTo(ImmutableList.of(IpAccessListLine.builder().setAction(LineAction.ACCEPT).setIpProtocols(Sets.newHashSet(IpProtocol.TCP)).setSrcIps(Sets.newHashSet(new IpWildcard("1.2.3.4/32"))).setDstPorts(Sets.newHashSet(new SubRange(30, 65535))).build(), _rejectSynOnly, _allowAllReverseOutboundRule)));
}
Aggregations