mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-17 23:01:01 +01:00
#1384: Disable certain PlayerProfile tests, if Mojang's services or internet are not available
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
parent
4862893bef
commit
2c37043b7f
3 changed files with 45 additions and 0 deletions
|
@ -12,6 +12,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
import org.bukkit.profile.PlayerTextures;
|
||||
import org.bukkit.support.condition.EnableIfMojangServerAvailable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PlayerProfileTest {
|
||||
|
@ -60,6 +61,7 @@ public class PlayerProfileTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnableIfMojangServerAvailable
|
||||
public void testProvidedValues() {
|
||||
Property property = new Property(CraftPlayerTextures.PROPERTY_NAME, VALUE, SIGNATURE);
|
||||
assertTrue(CraftProfileProperty.hasValidSignature(property), "Invalid test property signature, has the public key changed?");
|
||||
|
@ -117,6 +119,7 @@ public class PlayerProfileTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnableIfMojangServerAvailable
|
||||
public void testBuildGameProfile() {
|
||||
CraftPlayerProfile profile = buildPlayerProfile();
|
||||
GameProfile gameProfile = profile.buildGameProfile();
|
||||
|
@ -140,6 +143,7 @@ public class PlayerProfileTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnableIfMojangServerAvailable
|
||||
public void testSignatureValidation() {
|
||||
CraftPlayerProfile profile = buildPlayerProfile();
|
||||
assertTrue(profile.getTextures().isSigned(), "Signature is not valid");
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.bukkit.support.condition;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@ExtendWith(EnableIfMojangServerAvailableCondition.class)
|
||||
public @interface EnableIfMojangServerAvailable {
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.bukkit.support.condition;
|
||||
|
||||
import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
|
||||
import java.net.InetAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
public class EnableIfMojangServerAvailableCondition implements ExecutionCondition {
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
|
||||
try {
|
||||
InetAddress address = InetAddress.getByName(YggdrasilEnvironment.PROD.getEnvironment().servicesHost());
|
||||
|
||||
if (!address.isReachable((int) TimeUnit.SECONDS.toMillis(1))) {
|
||||
return ConditionEvaluationResult.disabled("Mojang server is not available");
|
||||
}
|
||||
|
||||
return ConditionEvaluationResult.enabled("Mojang server available");
|
||||
} catch (Exception e) {
|
||||
return ConditionEvaluationResult.disabled(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue