Use more specific query to get logged in players without email
- Reduces the amount of data returned from the DB and the work required to build objects
This commit is contained in:
+6
-16
@@ -101,14 +101,11 @@ public class ChangePasswordAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
String player = "my_user12";
|
||||
String password = "passPass";
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
|
||||
given(playerCache.isAuthenticated(player)).willReturn(true);
|
||||
given(playerCache.getAuth(player)).willReturn(auth);
|
||||
|
||||
HashedPassword hashedPassword = mock(HashedPassword.class);
|
||||
given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
|
||||
given(dataSource.updatePassword(auth)).willReturn(true);
|
||||
given(dataSource.updatePassword(player, hashedPassword)).willReturn(true);
|
||||
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
|
||||
|
||||
// when
|
||||
@@ -119,8 +116,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
verify(validationService).validatePassword(password, player);
|
||||
verify(service).send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
verify(passwordSecurity).computeHash(password, player);
|
||||
verify(auth).setPassword(hashedPassword);
|
||||
verify(dataSource).updatePassword(auth);
|
||||
verify(dataSource).updatePassword(player, hashedPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,15 +125,13 @@ public class ChangePasswordAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
String player = "my_user12";
|
||||
String password = "passPass";
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(playerCache.isAuthenticated(player)).willReturn(false);
|
||||
given(dataSource.isAuthAvailable(player)).willReturn(true);
|
||||
given(dataSource.getAuth(player)).willReturn(auth);
|
||||
given(dataSource.updatePassword(auth)).willReturn(true);
|
||||
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
|
||||
|
||||
HashedPassword hashedPassword = mock(HashedPassword.class);
|
||||
given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
|
||||
given(dataSource.updatePassword(player, hashedPassword)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
@@ -147,8 +141,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
verify(validationService).validatePassword(password, player);
|
||||
verify(service).send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
verify(passwordSecurity).computeHash(password, player);
|
||||
verify(auth).setPassword(hashedPassword);
|
||||
verify(dataSource).updatePassword(auth);
|
||||
verify(dataSource).updatePassword(player, hashedPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,14 +150,12 @@ public class ChangePasswordAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
String player = "my_user12";
|
||||
String password = "passPass";
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(playerCache.isAuthenticated(player)).willReturn(true);
|
||||
given(playerCache.getAuth(player)).willReturn(auth);
|
||||
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
|
||||
|
||||
HashedPassword hashedPassword = mock(HashedPassword.class);
|
||||
given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
|
||||
given(dataSource.updatePassword(auth)).willReturn(false);
|
||||
given(dataSource.updatePassword(player, hashedPassword)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
@@ -174,8 +165,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
verify(validationService).validatePassword(password, player);
|
||||
verify(service).send(sender, MessageKey.ERROR);
|
||||
verify(passwordSecurity).computeHash(password, player);
|
||||
verify(auth).setPassword(hashedPassword);
|
||||
verify(dataSource).updatePassword(auth);
|
||||
verify(dataSource).updatePassword(player, hashedPassword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -348,7 +348,8 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
public void shouldPerformOperationsOnIsLoggedColumnSuccessfully() {
|
||||
DataSource dataSource = getDataSource();
|
||||
// on startup no one should be marked as logged
|
||||
assertThat(dataSource.getLoggedPlayers(), empty());
|
||||
assertThat(dataSource.isLogged("user"), equalTo(false));
|
||||
assertThat(dataSource.isLogged("bobby"), equalTo(false));
|
||||
|
||||
// Mark user as logged
|
||||
dataSource.setLogged("user");
|
||||
@@ -361,15 +362,16 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
// Set bobby logged and unlog user
|
||||
dataSource.setLogged("bobby");
|
||||
dataSource.setUnlogged("user");
|
||||
assertThat(dataSource.getLoggedPlayers(),
|
||||
contains(hasAuthBasicData("bobby", "Bobby", "your@email.com", "123.45.67.89")));
|
||||
|
||||
assertThat(dataSource.isLogged("user"), equalTo(false));
|
||||
assertThat(dataSource.isLogged("bobby"), equalTo(true));
|
||||
|
||||
// Set both as logged (even if Bobby already is logged)
|
||||
dataSource.setLogged("user");
|
||||
dataSource.setLogged("bobby");
|
||||
dataSource.purgeLogged();
|
||||
assertThat(dataSource.isLogged("user"), equalTo(false));
|
||||
assertThat(dataSource.getLoggedPlayers(), empty());
|
||||
assertThat(dataSource.isLogged("bobby"), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -400,4 +402,18 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
assertThat(email1.getValue(), equalTo("user@example.org"));
|
||||
assertThat(email2, is(DataSourceResult.unknownPlayer()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetLoggedPlayersWithoutEmail() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
dataSource.setLogged("bobby");
|
||||
dataSource.setLogged("user");
|
||||
|
||||
// when
|
||||
List<String> loggedPlayersWithEmptyMail = dataSource.getLoggedPlayersWithEmptyMail();
|
||||
|
||||
// then
|
||||
assertThat(loggedPlayersWithEmptyMail, contains("Bobby"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user