mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Failed closed on unreadable takeovers
- Modded config reports unparseable files, non-object takeover sections, and invalid takeover entries instead of returning silent defaults - Takeover reconciliation refuses startup when takeovers are unreadable and the world has an applied takeover state file - Config writes are refused while takeovers are unreadable so fallback defaults never overwrite the operator's file
This commit is contained in:
1 parent
79e220298f
commit
4244aa4ea7
4 files changed
+253
-37
No files matched your search
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedModConfigTest {
|
||||
@Test
|
||||
public void validTakeoversLoadWithoutProblems() throws IOException {
|
||||
Path file = config("{\"dimensionTakeovers\": {\"aether:the_aether\": \"overworld:sky\"}}");
|
||||
try {
|
||||
ModdedModConfig config = ModdedModConfig.read(file);
|
||||
|
||||
assertEquals(Map.of("aether:the_aether", "overworld:sky"), config.dimensionTakeovers());
|
||||
assertEquals(List.of(), config.takeoverProblems());
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(file.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unparseableConfigReportsAProblemNamingTheFile() throws IOException {
|
||||
Path file = config("{\"dimensionTakeovers\": {\"aether:the_aether\": ");
|
||||
try {
|
||||
ModdedModConfig config = ModdedModConfig.read(file);
|
||||
|
||||
assertEquals(Map.of(), config.dimensionTakeovers());
|
||||
assertEquals(1, config.takeoverProblems().size());
|
||||
assertTrue(config.takeoverProblems().getFirst(), config.takeoverProblems().getFirst().contains(file.toString()));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(file.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidTakeoverEntryIsReportedInsteadOfSilentlyDropped() throws IOException {
|
||||
Path file = config("{\"dimensionTakeovers\": {\"aether:the_aether\": \"overworld\", \"Broken Key\": \"overworld\"}}");
|
||||
try {
|
||||
ModdedModConfig config = ModdedModConfig.read(file);
|
||||
|
||||
assertEquals(Map.of("aether:the_aether", "overworld"), config.dimensionTakeovers());
|
||||
assertEquals(1, config.takeoverProblems().size());
|
||||
assertTrue(config.takeoverProblems().getFirst(), config.takeoverProblems().getFirst().contains("Broken Key"));
|
||||
assertTrue(config.takeoverProblems().getFirst(), config.takeoverProblems().getFirst().contains(file.toString()));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(file.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void takeoverSectionThatIsNotAnObjectIsReported() throws IOException {
|
||||
Path file = config("{\"dimensionTakeovers\": [\"aether:the_aether\"]}");
|
||||
try {
|
||||
ModdedModConfig config = ModdedModConfig.read(file);
|
||||
|
||||
assertEquals(Map.of(), config.dimensionTakeovers());
|
||||
assertEquals(1, config.takeoverProblems().size());
|
||||
assertTrue(config.takeoverProblems().getFirst(), config.takeoverProblems().getFirst().contains("dimensionTakeovers"));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(file.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
private static Path config(String json) throws IOException {
|
||||
Path file = Files.createTempDirectory("iris-modded-config").resolve("modded.json");
|
||||
Files.writeString(file, json, StandardCharsets.UTF_8);
|
||||
return file;
|
||||
}
|
||||
}
|
||||
+58
-4
@@ -33,6 +33,7 @@ import java.util.stream.Stream;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedTakeoverReconcilerTest {
|
||||
@@ -64,7 +65,7 @@ public class ModdedTakeoverReconcilerTest {
|
||||
touch(worldRoot.resolve("players/data/player.dat"));
|
||||
|
||||
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of("iristest:skylands", "overworld"), recoveryParent);
|
||||
worldRoot, Map.of("iristest:skylands", "overworld"), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), result.changedLevels());
|
||||
for (String folder : List.of("region", "entities", "poi", "mantle-hydrology", "iris")) {
|
||||
@@ -92,14 +93,14 @@ public class ModdedTakeoverReconcilerTest {
|
||||
touch(region);
|
||||
|
||||
ModdedTakeoverReconciler.Result unchanged = ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of("iristest:skylands", "overworld"), recoveryParent);
|
||||
worldRoot, Map.of("iristest:skylands", "overworld"), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of(), unchanged.changedLevels());
|
||||
assertNull(unchanged.recovery());
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
|
||||
ModdedTakeoverReconciler.Result removed = ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of(), recoveryParent);
|
||||
worldRoot, Map.of(), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), removed.changedLevels());
|
||||
assertFalse(Files.exists(region));
|
||||
@@ -119,7 +120,7 @@ public class ModdedTakeoverReconcilerTest {
|
||||
Files.createDirectories(worldRoot);
|
||||
|
||||
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of("aether:the_aether", "overworld"), recoveryParent);
|
||||
worldRoot, Map.of("aether:the_aether", "overworld"), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("aether:the_aether"), result.changedLevels());
|
||||
assertNull(result.recovery());
|
||||
@@ -130,6 +131,59 @@ public class ModdedTakeoverReconcilerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unreadableConfigWithRecordedTakeoversRefusesWithoutMovingAnything() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-unreadable");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Path recoveryParent = temporary.resolve("config");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/iristest/skylands/region/r.0.0.mca");
|
||||
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("iristest:skylands", "overworld"));
|
||||
touch(region);
|
||||
List<String> problems = List.of("Iris could not read /srv/config/irisworldgen/modded.json: Unterminated object");
|
||||
|
||||
IOException refused = assertThrows(IOException.class, () -> ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of(), problems, recoveryParent));
|
||||
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("modded.json"));
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
assertFalse(Files.exists(recoveryParent));
|
||||
assertEquals(Map.of("iristest:skylands", "overworld"), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unreadableConfigWithAnEmptyStateFileStillRefuses() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-unreadable-empty");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of());
|
||||
|
||||
assertThrows(IOException.class, () -> ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of(), List.of("invalid takeover entry"), temporary.resolve("config")));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unreadableConfigWithoutRecordedStateProceeds() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-unreadable-fresh");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Files.createDirectories(worldRoot);
|
||||
|
||||
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of(), List.of("invalid takeover entry"), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of(), result.changedLevels());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
private static void touch(Path file) throws IOException {
|
||||
Files.createDirectories(file.getParent());
|
||||
Files.writeString(file, "x", StandardCharsets.UTF_8);
|
||||
|
||||
Reference in new issue
Block a user