コード例 #1
0
  @Test
  public void test_run_no_temporary_blocks() throws Exception {
    when(accessControlListDao.getTemporaryBlocks(now))
        .thenReturn(Collections.<BlockEvents>emptyList());

    subject.run();

    verify(accessControlListDao, never())
        .savePermanentBlock(anyString(), any(LocalDate.class), anyInt(), anyString());
  }
コード例 #2
0
  @Test
  public void test_run_temporary_blocks_already_denied() throws Exception {
    when(accessControlListDao.getTemporaryBlocks(now.minusDays(30)))
        .thenReturn(Arrays.asList(createBlockEvents(IPV4_PREFIX, 20)));
    when(ipResourceConfiguration.isDenied(any(InetAddress.class))).thenReturn(true);

    subject.run();

    verify(ipResourceConfiguration).isDenied(any(InetAddress.class));
    verify(accessControlListDao, never())
        .savePermanentBlock(anyString(), any(LocalDate.class), anyInt(), anyString());
  }
コード例 #3
0
  private void test_run_temporary_block(final int times, String prefix) {
    when(accessControlListDao.getTemporaryBlocks(now.minusDays(30)))
        .thenReturn(Arrays.asList(createBlockEvents(prefix, times)));

    subject.run();

    if (times < 10) {
      verify(accessControlListDao, never())
          .savePermanentBlock(anyString(), any(LocalDate.class), anyInt(), anyString());
    } else {
      verify(accessControlListDao)
          .savePermanentBlock(
              eq(prefix),
              any(LocalDate.class),
              eq(QUERY_LIMIT),
              eq(
                  "Automatic permanent ban after "
                      + times
                      + " temporary blocks at "
                      + FormatHelper.dateToString(now)));
    }
  }
コード例 #4
0
  @Test
  public void test_date() throws Exception {
    subject.run();

    verify(accessControlListDao, times(1)).getTemporaryBlocks(now.minusDays(30));
  }