Set the hosts for Mojang API connections

This commit is contained in:
games647
2022-02-10 18:23:40 +01:00
parent e0f1cb1729
commit f8c2a09014
2 changed files with 29 additions and 1 deletions

View File

@ -382,6 +382,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>3.2.38</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>

View File

@ -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<String, String> 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));