Harden the setup wizard after the branch review

Written-by: Gemini 4 Hydrogen (Antigravity)
Written-by: Claude Fable 5.2
This commit is contained in:
Rsclub2_2 committed 2026-11-18 21:32:12 +01:00
1 parent f871f551f7
commit a8cfe94853
13 files changed
+248 -31

No files matched your search

@@ -2619,6 +2619,10 @@ public class ChatPreferences {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(xmlConfigFile);
Element rootElement = doc.getDocumentElement();
if (rootElement == null || !"praktiKST".equals(rootElement.getTagName())) {
readable = false;
}
NodeList list;
// --- Schema version (optional) ---
@@ -45,6 +45,18 @@ class ChatPreferencesReadResultTest {
assertFalse(Files.exists(file), "reading a missing file must not create it");
}
@Test
void aWellFormedXmlWithForeignRootIsReportedAsUnreadable() throws IOException {
Path file = temporaryDirectory.resolve("foreign.xml");
byte[] original = "<somethingElse><station><LoginCallSign>DL0TEST</LoginCallSign></station></somethingElse>"
.getBytes(StandardCharsets.UTF_8);
Files.write(file, original);
ChatPreferences preferences = new ChatPreferences(file);
assertFalse(preferences.readPreferencesFromXmlFile(), "a foreign XML root must be reported as unreadable");
assertArrayEquals(original, Files.readAllBytes(file), "the foreign XML file must be left untouched");
}
@Test
void theBundledTemplateIsReadable() throws IOException {
Path templateCopy = temporaryDirectory.resolve("template.xml");