@Test public void testBlackListedIpAllow() throws UnknownHostException { // given a black listed ip ImmutableSet<InetAddress> blackList = ImmutableSet.<InetAddress>builder().add(InetAddress.getByName("172.22.10.1")).build(); ImmutableSet<InetAddress> whiteList = ImmutableSet.of(); // and given a black list filter and firewall in the pipeline IpFilterConfig ipFilterConfig = new IpFilterConfig(blackList, whiteList); BlackListFilter ipFilter = new BlackListFilter(ipFilterConfig); Firewall firewall = new Firewall(new MetricRegistry()); // when the an ip connects that is NOT black listed MyEmbeddedChannel channel = new MyEmbeddedChannel("172.22.10.5", ipFilter, firewall); channel.runPendingTasks(); // then the channel is NOT closed assertTrue(channel.isActive()); assertTrue(channel.isOpen()); }
@Test public void testBlackListedIpDeny() throws UnknownHostException { // given a black listed ip ImmutableSet<InetAddress> blackList = ImmutableSet.<InetAddress>builder().add(InetAddress.getByName("172.22.10.1")).build(); ImmutableSet<InetAddress> whiteList = ImmutableSet.of(); // and given a black list filter and firewall in the pipeline IpFilterConfig ipFilterConfig = new IpFilterConfig(blackList, whiteList); BlackListFilter ipFilter = new BlackListFilter(ipFilterConfig); Firewall firewall = new Firewall(new MetricRegistry()); // when the black listed ip connects MyEmbeddedChannel channel = new MyEmbeddedChannel("172.22.10.1", ipFilter, firewall); channel.runPendingTasks(); // then the channel is closed assertFalse(channel.isActive()); assertFalse(channel.isOpen()); }
pipeline.addLast("l4WhiteListFilter", new WhiteListFilter(appState.getIpFilterConfig())); } else if (config.isBlackListEnabled()) { pipeline.addLast("l4BlackListFilter", new BlackListFilter(appState.getIpFilterConfig()));