コード例 #1
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();
  }
コード例 #2
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();
 }
コード例 #3
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));
  }
コード例 #4
0
 @Test
 public void testIsIpDefinition() throws Exception {
   assertThat(GroupPermission.isIpDefinition("127.0.0.1")).isTrue();
   assertThat(GroupPermission.isIpDefinition("0.0.0.0/0")).isTrue();
   assertThat(GroupPermission.isIpDefinition("security-group")).isFalse();
 }