Add permission to bypass country check (#1323)
* Add permission to bypass country check #1321 Still need to fix unit tests * Fix test
This commit is contained in:
@@ -29,6 +29,7 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -438,15 +439,17 @@ public class OnJoinVerifierTest {
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotCheckCountry() throws FailedVerificationException {
|
||||
Player player = newPlayerWithAddress("127.0.0.1");
|
||||
|
||||
// protection setting disabled
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(false);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)).willReturn(true);
|
||||
onJoinVerifier.checkPlayerCountry(false, "127.0.0.1");
|
||||
onJoinVerifier.checkPlayerCountry(player, false);
|
||||
verifyZeroInteractions(validationService);
|
||||
|
||||
// protection for registered players disabled
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)).willReturn(false);
|
||||
onJoinVerifier.checkPlayerCountry(true, "127.0.0.1");
|
||||
onJoinVerifier.checkPlayerCountry(player, true);
|
||||
verifyZeroInteractions(validationService);
|
||||
}
|
||||
|
||||
@@ -454,11 +457,12 @@ public class OnJoinVerifierTest {
|
||||
public void shouldCheckAndAcceptUnregisteredPlayerCountry() throws FailedVerificationException {
|
||||
// given
|
||||
String ip = "192.168.0.1";
|
||||
Player player = newPlayerWithAddress(ip);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(true);
|
||||
given(validationService.isCountryAdmitted(ip)).willReturn(true);
|
||||
|
||||
// when
|
||||
onJoinVerifier.checkPlayerCountry(false, ip);
|
||||
onJoinVerifier.checkPlayerCountry(player, false);
|
||||
|
||||
// then
|
||||
verify(validationService).isCountryAdmitted(ip);
|
||||
@@ -468,12 +472,13 @@ public class OnJoinVerifierTest {
|
||||
public void shouldCheckAndAcceptRegisteredPlayerCountry() throws FailedVerificationException {
|
||||
// given
|
||||
String ip = "192.168.10.24";
|
||||
Player player = newPlayerWithAddress(ip);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(true);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)).willReturn(true);
|
||||
given(validationService.isCountryAdmitted(ip)).willReturn(true);
|
||||
|
||||
// when
|
||||
onJoinVerifier.checkPlayerCountry(true, ip);
|
||||
onJoinVerifier.checkPlayerCountry(player, true);
|
||||
|
||||
// then
|
||||
verify(validationService).isCountryAdmitted(ip);
|
||||
@@ -483,6 +488,7 @@ public class OnJoinVerifierTest {
|
||||
public void shouldThrowForBannedCountry() throws FailedVerificationException {
|
||||
// given
|
||||
String ip = "192.168.40.0";
|
||||
Player player = newPlayerWithAddress(ip);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(true);
|
||||
given(validationService.isCountryAdmitted(ip)).willReturn(false);
|
||||
|
||||
@@ -490,7 +496,7 @@ public class OnJoinVerifierTest {
|
||||
expectValidationExceptionWith(MessageKey.COUNTRY_BANNED_ERROR);
|
||||
|
||||
// when
|
||||
onJoinVerifier.checkPlayerCountry(false, ip);
|
||||
onJoinVerifier.checkPlayerCountry(player, false);
|
||||
}
|
||||
|
||||
private static Player newPlayerWithName(String name) {
|
||||
@@ -499,6 +505,12 @@ public class OnJoinVerifierTest {
|
||||
return player;
|
||||
}
|
||||
|
||||
private static Player newPlayerWithAddress(String ip) {
|
||||
Player player = mock(Player.class);
|
||||
given(player.getAddress()).willReturn(new InetSocketAddress(ip, 80));
|
||||
return player;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private void returnOnlineListFromBukkitServer(Collection<Player> onlineList) {
|
||||
// Note ljacqu 20160529: The compiler gets lost in generics because Collection<? extends Player> is returned
|
||||
|
||||
@@ -47,7 +47,7 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -554,12 +554,12 @@ public class PlayerListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformAllJoinVerificationsSuccessfully() throws FailedVerificationException {
|
||||
public void shouldPerformAllJoinVerificationsSuccessfully() throws FailedVerificationException, UnknownHostException {
|
||||
// given
|
||||
String name = "someone";
|
||||
Player player = mockPlayerWithName(name);
|
||||
String ip = "12.34.56.78";
|
||||
PlayerLoginEvent event = spy(new PlayerLoginEvent(player, "", mockAddrWithIp(ip)));
|
||||
|
||||
PlayerLoginEvent event = spy(new PlayerLoginEvent(player, "", null));
|
||||
given(validationService.isUnrestricted(name)).willReturn(false);
|
||||
given(onJoinVerifier.refusePlayerForFullServer(event)).willReturn(false);
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).build();
|
||||
@@ -576,7 +576,7 @@ public class PlayerListenerTest {
|
||||
verify(onJoinVerifier).checkAntibot(player, true);
|
||||
verify(onJoinVerifier).checkKickNonRegistered(true);
|
||||
verify(onJoinVerifier).checkNameCasing(player, auth);
|
||||
verify(onJoinVerifier).checkPlayerCountry(true, ip);
|
||||
verify(onJoinVerifier).checkPlayerCountry(player, true);
|
||||
verify(teleportationService).teleportOnJoin(player);
|
||||
verifyNoModifyingCalls(event);
|
||||
}
|
||||
@@ -883,11 +883,4 @@ public class PlayerListenerTest {
|
||||
verify(event, atLeast(0)).getAddress();
|
||||
verifyNoMoreInteractions(event);
|
||||
}
|
||||
|
||||
private static InetAddress mockAddrWithIp(String ip) {
|
||||
InetAddress addr = mock(InetAddress.class);
|
||||
given(addr.getHostAddress()).willReturn(ip);
|
||||
return addr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user