From b344e21f7f729998eb4b1b7d948bc184594b8864 Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Thu, 29 Jun 2023 07:22:13 -0400 Subject: [PATCH] Fix loading contents keys of encrypted resource packs (#3925) --- .../registry/loader/ResourcePackLoader.java | 2 +- .../loader/ResourcePackLoaderTest.java | 27 ++++++++++++++++++ core/src/test/resources/empty_pack.mcpack | Bin 0 -> 557 bytes core/src/test/resources/encrypted_pack.zip | Bin 0 -> 638 bytes .../src/test/resources/encrypted_pack.zip.key | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 core/src/test/resources/empty_pack.mcpack create mode 100644 core/src/test/resources/encrypted_pack.zip create mode 100644 core/src/test/resources/encrypted_pack.zip.key diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java index afb5a2fe8d4..452550d878e 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java @@ -146,7 +146,7 @@ public static GeyserResourcePack readPack(Path path) throws IllegalArgumentExcep // 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) 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); } catch (Exception e) { diff --git a/core/src/test/java/org/geysermc/geyser/registry/loader/ResourcePackLoaderTest.java b/core/src/test/java/org/geysermc/geyser/registry/loader/ResourcePackLoaderTest.java index 8150ac44635..b66fd0811ad 100644 --- a/core/src/test/java/org/geysermc/geyser/registry/loader/ResourcePackLoaderTest.java +++ b/core/src/test/java/org/geysermc/geyser/registry/loader/ResourcePackLoaderTest.java @@ -25,11 +25,16 @@ package org.geysermc.geyser.registry.loader; +import org.geysermc.geyser.api.pack.ResourcePack; import org.junit.jupiter.api.Test; +import java.net.URISyntaxException; +import java.net.URL; import java.nio.file.Path; 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.assertTrue; @@ -54,4 +59,26 @@ public void testPathMatcher() { assertFalse(matcher.matches(Path.of("pack.7zip"))); 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()); + } } diff --git a/core/src/test/resources/empty_pack.mcpack b/core/src/test/resources/empty_pack.mcpack new file mode 100644 index 0000000000000000000000000000000000000000..6891357a58f71e3e1eb57c4a3d79077055dd11fc GIT binary patch literal 557 zcmWIWW@Zs#0D&Dl?}ULFP=X6c7ndfb<>#cN7U>5-)p0QV&T2^S9&+y{XgRv`?Jz zuUvc^hi~uQ%WuvY=Np~>{#UkT`j%TIS4`(;thu69*`Q?We{Uj}$--i{<;xsS_r8fu znf!d^BKHcHM3esv&0*Dt1*@d${Fv)3Lzw0jY{*#fwd*+V%Qlr*R_$94XGk2h{I0qr zCgGm9VN%3a(fiYP_gu3)$>BI{W7D+AeJfqhMr_oU+#3sNhAlvzAtM6=FOW{o&nrpID=F5?D$dWldvGCNlY<1q z1MRYS2Q#zY|Hle99ZpI+cj#H##yjgHwn*@>`B<5oEl&}e>bD?Z!DJ5>g%4sZ95$@? z-K%n^RHhhg-?F(Z#!!|eTq7V$ae}n>lUfG|G9jpFXFAH^zP$>Iu`u)tDpDzx( zy!_E9u(tfq1&)7gMjU?%p0Ne8TQ7gzW*^IKwUK?sgRj=y9d_)zX2CBfrT_3LXtPb~ zm;N}o*F$mpA~}|FlZ6g>x2#|7w9z{?XRW4nN%HdVZ`Uo_ zH*M;afT>w4*1q!1uUa}QcJ+#w_4BVMS;uhQnqA|hvp9a?zeh_`|9vYuFCH$o;0oK8 zZ5!T;{LN0>Q3LckBa=M?uDDVG1_KBvfJwBN