Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Add unit tests
Dieser Commit ist enthalten in:
Ursprung
9ce4294e6e
Commit
5bf936d1b9
@ -138,8 +138,15 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String cleanVhost(String hostname) {
|
/**
|
||||||
// Clean out any anything after any zero byte
|
* Cleans the specified virtual host hostname.
|
||||||
|
*
|
||||||
|
* @param hostname the host name to clean
|
||||||
|
* @return the cleaned hostname
|
||||||
|
*/
|
||||||
|
static String cleanVhost(String hostname) {
|
||||||
|
// Clean out any anything after any zero bytes (this includes BungeeCord forwarding and the
|
||||||
|
// legacy Forge handshake indicator).
|
||||||
String cleaned = hostname;
|
String cleaned = hostname;
|
||||||
int zeroIdx = cleaned.indexOf('\0');
|
int zeroIdx = cleaned.indexOf('\0');
|
||||||
if (zeroIdx > -1) {
|
if (zeroIdx > -1) {
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.velocitypowered.proxy.connection.client;
|
||||||
|
|
||||||
|
import static com.velocitypowered.proxy.connection.client.HandshakeSessionHandler.cleanVhost;
|
||||||
|
import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class HandshakeSessionHandlerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cleanVhostHandlesGoodHostname() {
|
||||||
|
assertEquals("localhost", cleanVhost("localhost"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cleanVhostHandlesTrailingOctet() {
|
||||||
|
assertEquals("localhost", cleanVhost("localhost."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cleanVhostHandlesForge() {
|
||||||
|
assertEquals("localhost", cleanVhost("localhost" + HANDSHAKE_HOSTNAME_TOKEN));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cleanVhostHandlesOctetsAndForge() {
|
||||||
|
assertEquals("localhost", cleanVhost("localhost." + HANDSHAKE_HOSTNAME_TOKEN));
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren