mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-13 11:11:19 +01:00
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:
parent
b96ae61697
commit
6b875a9ba4
@ -1,5 +1,5 @@
|
||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||
<!-- File auto-generated on Sat Aug 12 13:42:15 CEST 2017. See docs/permissions/permission_nodes.tpl.md -->
|
||||
<!-- File auto-generated on Thu Aug 31 12:11:53 CEST 2017. See docs/permissions/permission_nodes.tpl.md -->
|
||||
|
||||
## AuthMe Permission Nodes
|
||||
The following are the permission nodes that are currently supported by the latest dev builds.
|
||||
@ -31,6 +31,7 @@ The following are the permission nodes that are currently supported by the lates
|
||||
- **authme.admin.updatemessages** – Permission to use the update messages command.
|
||||
- **authme.allowmultipleaccounts** – Permission to be able to register multiple accounts.
|
||||
- **authme.bypassantibot** – Permission node to bypass AntiBot protection.
|
||||
- **authme.bypasscountrycheck** – Permission to use to see own other accounts.
|
||||
- **authme.bypassforcesurvival** – Permission for users to bypass force-survival mode.
|
||||
- **authme.bypasspurge** – Permission to bypass the purging process.
|
||||
- **authme.debug.command** – General permission to use the /authme debug command.
|
||||
@ -62,4 +63,4 @@ The following are the permission nodes that are currently supported by the lates
|
||||
|
||||
---
|
||||
|
||||
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Aug 12 13:42:15 CEST 2017
|
||||
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Thu Aug 31 12:11:53 CEST 2017
|
||||
|
@ -168,15 +168,15 @@ public class OnJoinVerifier implements Reloadable {
|
||||
/**
|
||||
* Checks that the player's country is admitted.
|
||||
*
|
||||
* @param player the player
|
||||
* @param isAuthAvailable whether or not the user is registered
|
||||
* @param playerIp the ip address of the player
|
||||
* @throws FailedVerificationException if the verification fails
|
||||
*/
|
||||
public void checkPlayerCountry(boolean isAuthAvailable,
|
||||
String playerIp) throws FailedVerificationException {
|
||||
public void checkPlayerCountry(Player player, boolean isAuthAvailable) throws FailedVerificationException {
|
||||
if ((!isAuthAvailable || settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED))
|
||||
&& settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)
|
||||
&& !validationService.isCountryAdmitted(playerIp)) {
|
||||
&& !permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_COUNTRY_CHECK)
|
||||
&& !validationService.isCountryAdmitted(player.getAddress().getAddress().getHostAddress())) {
|
||||
throw new FailedVerificationException(MessageKey.COUNTRY_BANNED_ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ public class PlayerListener implements Listener {
|
||||
onJoinVerifier.checkKickNonRegistered(isAuthAvailable);
|
||||
onJoinVerifier.checkAntibot(player, isAuthAvailable);
|
||||
onJoinVerifier.checkNameCasing(player, auth);
|
||||
onJoinVerifier.checkPlayerCountry(isAuthAvailable, event.getAddress().getHostAddress());
|
||||
onJoinVerifier.checkPlayerCountry(player, isAuthAvailable);
|
||||
} catch (FailedVerificationException e) {
|
||||
event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs()));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
|
@ -29,7 +29,12 @@ public enum PlayerStatePermission implements PermissionNode {
|
||||
/**
|
||||
* Permission to bypass the purging process.
|
||||
*/
|
||||
BYPASS_PURGE("authme.bypasspurge", DefaultPermission.NOT_ALLOWED);
|
||||
BYPASS_PURGE("authme.bypasspurge", DefaultPermission.NOT_ALLOWED),
|
||||
|
||||
/**
|
||||
* Permission to use to see own other accounts.
|
||||
*/
|
||||
BYPASS_COUNTRY_CHECK("authme.bypasscountrycheck", DefaultPermission.NOT_ALLOWED);
|
||||
|
||||
/**
|
||||
* The permission node.
|
||||
|
@ -154,6 +154,9 @@ permissions:
|
||||
authme.bypassantibot:
|
||||
description: Permission node to bypass AntiBot protection.
|
||||
default: op
|
||||
authme.bypasscountrycheck:
|
||||
description: Permission to use to see own other accounts.
|
||||
default: false
|
||||
authme.bypassforcesurvival:
|
||||
description: Permission for users to bypass force-survival mode.
|
||||
default: op
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user