From f8c2a0901493d85cbcfeb03c896484b7f94c0c55 Mon Sep 17 00:00:00 2001 From: games647 Date: Thu, 10 Feb 2022 18:23:40 +0100 Subject: [PATCH] Set the hosts for Mojang API connections --- bukkit/pom.xml | 7 ++++++ bukkit/src/test/java/integration/LoginIT.java | 23 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 8646be53..6a015184 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -382,6 +382,13 @@ test + + com.mojang + authlib + 3.2.38 + test + + ch.qos.logback logback-core diff --git a/bukkit/src/test/java/integration/LoginIT.java b/bukkit/src/test/java/integration/LoginIT.java index 96ff74d3..1aab8789 100644 --- a/bukkit/src/test/java/integration/LoginIT.java +++ b/bukkit/src/test/java/integration/LoginIT.java @@ -7,13 +7,17 @@ import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.tcp.TcpClientSession; import com.google.common.io.CharStreams; +import com.mojang.authlib.EnvironmentParser; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import org.junit.Rule; import org.junit.Test; @@ -47,7 +51,7 @@ public class LoginIT { @Rule public GenericContainer minecraftServer = new GenericContainer(DockerImageName.parse(SERVER_IMAGE)) - .withEnv("JDK_JAVA_OPTIONS", "-Dcom.mojang.eula.agree=true") + .withEnv("JDK_JAVA_OPTIONS", buildJVMFlags()) .withExposedPorts(25565) // Done (XXXXs)! For help, type "help" .waitingFor( @@ -55,6 +59,19 @@ public class LoginIT { ) .withReuse(true); + private String buildJVMFlags() { + Map systemProperties = new HashMap<>(); + systemProperties.put("com.mojang.eula.agree", Boolean.toString(true)); + + // set the Yggdrasil hosts that will also be used by the vanilla server + systemProperties.put(EnvironmentParser.PROP_ACCOUNT_HOST, getProxyHost()); + systemProperties.put(EnvironmentParser.PROP_SESSION_HOST, getProxyHost()); + + return systemProperties.entrySet().stream() + .map(entry -> "-D" + entry.getKey() + '=' + entry.getValue()) + .collect(Collectors.joining(" ")); + } + @Test public void checkRunning() throws Exception { assertThat(minecraftServer.isRunning(), is(true)); @@ -84,6 +101,10 @@ public class LoginIT { } } + private String getProxyHost() { + return String.format("https://%s:%d", mockServer.getHost(), mockServer.getServerPort()); + } + @Test public void autoRegisterNewUser() throws Exception { assertThat(mockServer.isRunning(), is(true));