mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix loading contents keys of encrypted resource packs (#3925)
This commit is contained in:
parent
40775149f5
commit
b344e21f7f
5 changed files with 29 additions and 1 deletions
|
@ -146,7 +146,7 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
|
||||||
// Check if a file exists with the same name as the resource pack suffixed by .key,
|
// Check if a file exists with the same name as the resource pack suffixed by .key,
|
||||||
// and set this as content key. (e.g. test.zip, key file would be test.zip.key)
|
// and set this as content key. (e.g. test.zip, key file would be test.zip.key)
|
||||||
Path keyFile = path.resolveSibling(path.getFileName().toString() + ".key");
|
Path keyFile = path.resolveSibling(path.getFileName().toString() + ".key");
|
||||||
String contentKey = Files.exists(keyFile) ? Files.readString(path, StandardCharsets.UTF_8) : "";
|
String contentKey = Files.exists(keyFile) ? Files.readString(keyFile, StandardCharsets.UTF_8) : "";
|
||||||
|
|
||||||
return new GeyserResourcePack(new GeyserPathPackCodec(path), manifest, contentKey);
|
return new GeyserResourcePack(new GeyserPathPackCodec(path), manifest, contentKey);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -25,11 +25,16 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.registry.loader;
|
package org.geysermc.geyser.registry.loader;
|
||||||
|
|
||||||
|
import org.geysermc.geyser.api.pack.ResourcePack;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.PathMatcher;
|
import java.nio.file.PathMatcher;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@ -54,4 +59,26 @@ public class ResourcePackLoaderTest {
|
||||||
assertFalse(matcher.matches(Path.of("pack.7zip")));
|
assertFalse(matcher.matches(Path.of("pack.7zip")));
|
||||||
assertFalse(matcher.matches(Path.of("packs")));
|
assertFalse(matcher.matches(Path.of("packs")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPack() throws Exception {
|
||||||
|
// this mcpack only contains a folder, which the manifest is in
|
||||||
|
Path path = getResource("empty_pack.mcpack");
|
||||||
|
ResourcePack pack = ResourcePackLoader.readPack(path);
|
||||||
|
assertEquals("", pack.contentKey());
|
||||||
|
// should probably add some more tests here related to the manifest
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncryptedPack() throws Exception {
|
||||||
|
// this zip only contains a contents.json and manifest.json at the root
|
||||||
|
Path path = getResource("encrypted_pack.zip");
|
||||||
|
ResourcePack pack = ResourcePackLoader.readPack(path);
|
||||||
|
assertEquals("JAGcSXcXwcODc1YS70GzeWAUKEO172UA", pack.contentKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path getResource(String name) throws URISyntaxException {
|
||||||
|
URL url = Objects.requireNonNull(getClass().getClassLoader().getResource(name), "No resource for name: " + name);
|
||||||
|
return Path.of(url.toURI());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
core/src/test/resources/empty_pack.mcpack
Normal file
BIN
core/src/test/resources/empty_pack.mcpack
Normal file
Binary file not shown.
BIN
core/src/test/resources/encrypted_pack.zip
Normal file
BIN
core/src/test/resources/encrypted_pack.zip
Normal file
Binary file not shown.
1
core/src/test/resources/encrypted_pack.zip.key
Normal file
1
core/src/test/resources/encrypted_pack.zip.key
Normal file
|
@ -0,0 +1 @@
|
||||||
|
JAGcSXcXwcODc1YS70GzeWAUKEO172UA
|
Loading…
Reference in a new issue