geforkt von Mirrors/Paper
#1384: Disable certain PlayerProfile tests, if Mojang's services or internet are not available
By: DerFrZocker <derrieple@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
4862893bef
Commit
2c37043b7f
@ -12,6 +12,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
import org.bukkit.profile.PlayerProfile;
|
import org.bukkit.profile.PlayerProfile;
|
||||||
import org.bukkit.profile.PlayerTextures;
|
import org.bukkit.profile.PlayerTextures;
|
||||||
|
import org.bukkit.support.condition.EnableIfMojangServerAvailable;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class PlayerProfileTest {
|
public class PlayerProfileTest {
|
||||||
@ -60,6 +61,7 @@ public class PlayerProfileTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableIfMojangServerAvailable
|
||||||
public void testProvidedValues() {
|
public void testProvidedValues() {
|
||||||
Property property = new Property(CraftPlayerTextures.PROPERTY_NAME, VALUE, SIGNATURE);
|
Property property = new Property(CraftPlayerTextures.PROPERTY_NAME, VALUE, SIGNATURE);
|
||||||
assertTrue(CraftProfileProperty.hasValidSignature(property), "Invalid test property signature, has the public key changed?");
|
assertTrue(CraftProfileProperty.hasValidSignature(property), "Invalid test property signature, has the public key changed?");
|
||||||
@ -117,6 +119,7 @@ public class PlayerProfileTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableIfMojangServerAvailable
|
||||||
public void testBuildGameProfile() {
|
public void testBuildGameProfile() {
|
||||||
CraftPlayerProfile profile = buildPlayerProfile();
|
CraftPlayerProfile profile = buildPlayerProfile();
|
||||||
GameProfile gameProfile = profile.buildGameProfile();
|
GameProfile gameProfile = profile.buildGameProfile();
|
||||||
@ -140,6 +143,7 @@ public class PlayerProfileTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableIfMojangServerAvailable
|
||||||
public void testSignatureValidation() {
|
public void testSignatureValidation() {
|
||||||
CraftPlayerProfile profile = buildPlayerProfile();
|
CraftPlayerProfile profile = buildPlayerProfile();
|
||||||
assertTrue(profile.getTextures().isSigned(), "Signature is not valid");
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren