13
0
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:
CraftBukkit/Spigot 2024-04-24 18:12:31 +10:00
Ursprung 4862893bef
Commit 2c37043b7f
3 geänderte Dateien mit 45 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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");

Datei anzeigen

@ -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 {
}

Datei anzeigen

@ -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());
}
}
}