예제 #1
0
  @Test
  public void testMatches_ips() {
    GroupPermission groupPermission = new GroupPermission("tcp", 1433, 1433, "0.0.0.0/0");
    IpPermission ipPermission = new IpPermission();
    ipPermission.setIpProtocol("tcp");
    ipPermission.setToPort(65535);
    ipPermission.setFromPort(0);
    Collection<String> ips = new ArrayList<String>();
    ips.add("127.0.0.1");
    ipPermission.setIpRanges(ips);
    assertFalse(groupPermission.matches(ipPermission));

    ips.clear();
    ips.add("0.0.0.0/0");
    ipPermission.setIpRanges(ips);
    assertTrue(groupPermission.matches(ipPermission));
  }
예제 #2
0
  @Test
  public void testMatches_SecurityGroup() throws Exception {
    GroupPermission groupPermission = new GroupPermission("tcp", 1433, 1433, "securityGroup");

    IpPermission ipPermission =
        new IpPermission().withIpProtocol("tcp").withFromPort(1433).withToPort(1433);
    ipPermission.setUserIdGroupPairs(
        Arrays.asList(new UserIdGroupPair().withGroupName("securityGroup")));
    assertThat(groupPermission.matches(ipPermission)).isTrue();

    assertThat(new GroupPermission("tcp", 1433, 1433, "securityGroup2").matches(ipPermission))
        .isFalse();
  }
예제 #3
0
 @Test
 public void testMatches_groupWithSamePort() {
   GroupPermission groupPermission = new GroupPermission("tcp", 1433, 1433, "0.0.0.0/0");
   IpPermission ipPermission = new IpPermission();
   ipPermission.setIpProtocol("tcp");
   ipPermission.setToPort(65535);
   ipPermission.setFromPort(0);
   Collection<UserIdGroupPair> ips = new ArrayList<UserIdGroupPair>();
   ips.add(
       new UserIdGroupPair()
           .withGroupId("0.0.0.0/0")
           .withGroupName("0.0.0.0/0")
           .withUserId("0.0.0.0/0"));
   ipPermission.setUserIdGroupPairs(ips);
   assertThat(groupPermission.matches(ipPermission)).isTrue();
 }