コード例 #1
0
  @Test
  public void shouldRejectNonPlayerSender() {
    // given
    CommandSender sender = mock(BlockCommandSender.class);
    ChangePasswordCommand command = new ChangePasswordCommand();

    // when
    command.executeCommand(sender, new ArrayList<String>(), commandService);

    // then
    assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
  }
コード例 #2
0
  @Test
  public void shouldRejectPasswordEqualToNick() {
    // given
    CommandSender sender = initPlayerWithName("tester", true);
    ChangePasswordCommand command = new ChangePasswordCommand();

    // when
    command.executeCommand(sender, Arrays.asList("old_", "Tester"), commandService);

    // then
    verify(commandService).send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
    assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
  }
コード例 #3
0
  @Test
  public void shouldDenyInvalidPassword() {
    // given
    CommandSender sender = initPlayerWithName("name", true);
    ChangePasswordCommand command = new ChangePasswordCommand();

    // when
    command.executeCommand(sender, Arrays.asList("old123", "!pass"), commandService);

    // then
    verify(commandService).send(sender, MessageKey.PASSWORD_MATCH_ERROR);
    assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
  }
コード例 #4
0
  @Test
  public void shouldRejectNotLoggedInPlayer() {
    // given
    CommandSender sender = initPlayerWithName("name", false);
    ChangePasswordCommand command = new ChangePasswordCommand();

    // when
    command.executeCommand(sender, Arrays.asList("pass", "pass"), commandService);

    // then
    verify(commandService).send(sender, MessageKey.NOT_LOGGED_IN);
    assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
  }
コード例 #5
0
  @Test
  public void shouldRejectTooShortPassword() {
    // given
    CommandSender sender = initPlayerWithName("abc12", true);
    ChangePasswordCommand command = new ChangePasswordCommand();
    given(commandService.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH)).willReturn(7);

    // when
    command.executeCommand(sender, Arrays.asList("oldverylongpassword", "tester"), commandService);

    // then
    verify(commandService).send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
    assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
  }
コード例 #6
0
  @Test
  public void shouldRejectUnsafeCustomPassword() {
    // given
    CommandSender sender = initPlayerWithName("player", true);
    ChangePasswordCommand command = new ChangePasswordCommand();
    given(commandService.getProperty(SecuritySettings.UNSAFE_PASSWORDS))
        .willReturn(Arrays.asList("test", "abc123"));

    // when
    command.executeCommand(sender, Arrays.asList("oldpw", "abc123"), commandService);

    // then
    verify(commandService).send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
    assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
  }
コード例 #7
0
  @Test
  public void shouldForwardTheDataForValidPassword() {
    // given
    CommandSender sender = initPlayerWithName("parker", true);
    ChangePasswordCommand command = new ChangePasswordCommand();

    // when
    command.executeCommand(sender, Arrays.asList("abc123", "abc123"), commandService);

    // then
    verify(commandService, never()).send(eq(sender), any(MessageKey.class));
    ArgumentCaptor<ChangePasswordTask> taskCaptor =
        ArgumentCaptor.forClass(ChangePasswordTask.class);
    verify(commandService).runTaskAsynchronously(taskCaptor.capture());
    ChangePasswordTask task = taskCaptor.getValue();
    assertThat(
        (String) ReflectionTestUtils.getFieldValue(ChangePasswordTask.class, task, "newPassword"),
        equalTo("abc123"));
  }