mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-11-19 01:52:29 +01:00
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:
13 files changed
+225
-8
No files matched your search
@@ -517,9 +517,11 @@ wizard.source.stationKeep=Station unverändert lassen (Locator {0})
|
|||||||
wizard.personal.title=Persönliches
|
wizard.personal.title=Persönliches
|
||||||
wizard.personal.lead=Gehört zum Operator.
|
wizard.personal.lead=Gehört zum Operator.
|
||||||
wizard.personal.name=Anzeigename im Chat
|
wizard.personal.name=Anzeigename im Chat
|
||||||
|
wizard.personal.nameInvalid=Der Name darf kein Zeichen | enthalten.
|
||||||
wizard.login.title=Anmeldung bei ON4KST
|
wizard.login.title=Anmeldung bei ON4KST
|
||||||
wizard.login.lead=Die Zugangsdaten deines ON4KST-Kontos.
|
wizard.login.lead=Die Zugangsdaten deines ON4KST-Kontos.
|
||||||
wizard.login.callsignInvalid=Das sieht nicht nach einem Rufzeichen aus.
|
wizard.login.callsignInvalid=Das sieht nicht nach einem Rufzeichen aus.
|
||||||
|
wizard.login.passwordInvalid=Das Passwort darf nicht mit einem Leerzeichen beginnen oder enden und kein Zeichen | enthalten.
|
||||||
wizard.site.title=Standort und Bänder
|
wizard.site.title=Standort und Bänder
|
||||||
wizard.site.lead=Gehört zur Station, nicht zum Operator.
|
wizard.site.lead=Gehört zur Station, nicht zum Operator.
|
||||||
wizard.site.locatorInvalid=Sechsstelliger Maidenhead-Locator, zum Beispiel JO50AA.
|
wizard.site.locatorInvalid=Sechsstelliger Maidenhead-Locator, zum Beispiel JO50AA.
|
||||||
|
|||||||
@@ -526,9 +526,11 @@ wizard.source.stationKeep=Leave the station unchanged (locator {0})
|
|||||||
wizard.personal.title=Personal
|
wizard.personal.title=Personal
|
||||||
wizard.personal.lead=Belongs to the operator.
|
wizard.personal.lead=Belongs to the operator.
|
||||||
wizard.personal.name=Name shown in the chat
|
wizard.personal.name=Name shown in the chat
|
||||||
|
wizard.personal.nameInvalid=The name must not contain a | character.
|
||||||
wizard.login.title=ON4KST login
|
wizard.login.title=ON4KST login
|
||||||
wizard.login.lead=The credentials of your ON4KST account.
|
wizard.login.lead=The credentials of your ON4KST account.
|
||||||
wizard.login.callsignInvalid=This does not look like a callsign.
|
wizard.login.callsignInvalid=This does not look like a callsign.
|
||||||
|
wizard.login.passwordInvalid=The password must not begin or end with a blank and must not contain a | character.
|
||||||
wizard.site.title=Location and bands
|
wizard.site.title=Location and bands
|
||||||
wizard.site.lead=Belongs to the station, not to the operator.
|
wizard.site.lead=Belongs to the station, not to the operator.
|
||||||
wizard.site.locatorInvalid=Six-character Maidenhead locator, for example JO50AA.
|
wizard.site.locatorInvalid=Six-character Maidenhead locator, for example JO50AA.
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
private static final java.util.concurrent.atomic.AtomicBoolean SETUP_WIZARD_REQUESTED =
|
private static final java.util.concurrent.atomic.AtomicBoolean SETUP_WIZARD_REQUESTED =
|
||||||
new java.util.concurrent.atomic.AtomicBoolean(false);
|
new java.util.concurrent.atomic.AtomicBoolean(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guards {@link #switchProfile(OperatorProfile)} against re-entry while window teardown
|
||||||
|
* inside {@link Kst4ContestApplication#shutdownRuntime()} is still pumping events.
|
||||||
|
*/
|
||||||
|
private static final java.util.concurrent.atomic.AtomicBoolean SWITCH_IN_PROGRESS =
|
||||||
|
new java.util.concurrent.atomic.AtomicBoolean(false);
|
||||||
|
|
||||||
private ApplicationRuntimeLauncher() {
|
private ApplicationRuntimeLauncher() {
|
||||||
// Utility class.
|
// Utility class.
|
||||||
}
|
}
|
||||||
@@ -83,6 +90,20 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
return SETUP_WIZARD_REQUESTED.getAndSet(false);
|
return SETUP_WIZARD_REQUESTED.getAndSet(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a profile switch as in progress if none is currently running.
|
||||||
|
*
|
||||||
|
* @return true if this call obtained the mark
|
||||||
|
*/
|
||||||
|
static boolean beginSwitch() {
|
||||||
|
return SWITCH_IN_PROGRESS.compareAndSet(false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Clears the in-progress mark of a profile switch. */
|
||||||
|
static void endSwitch() {
|
||||||
|
SWITCH_IN_PROGRESS.set(false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rebuilds the runtime of the active profile with the setup wizard in front of it.
|
* Rebuilds the runtime of the active profile with the setup wizard in front of it.
|
||||||
*
|
*
|
||||||
@@ -100,7 +121,16 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestSetupWizard();
|
requestSetupWizard();
|
||||||
return switchProfile(active.getProfile());
|
try {
|
||||||
|
boolean switched = switchProfile(active.getProfile());
|
||||||
|
if (!switched) {
|
||||||
|
consumeSetupWizardRequest();
|
||||||
|
}
|
||||||
|
return switched;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
consumeSetupWizardRequest();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,6 +141,11 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
*/
|
*/
|
||||||
public static boolean switchProfile(final OperatorProfile targetProfile) {
|
public static boolean switchProfile(final OperatorProfile targetProfile) {
|
||||||
|
|
||||||
|
if (!beginSwitch()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
if (targetProfile == null) {
|
if (targetProfile == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -139,5 +174,8 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
|
|
||||||
setCurrent(nextRuntime);
|
setCurrent(nextRuntime);
|
||||||
return true;
|
return true;
|
||||||
|
} finally {
|
||||||
|
endSwitch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ private fun categoryName(number: Int): String = ChatCategory(number).getChatCate
|
|||||||
* The wizard's pages and its button row.
|
* The wizard's pages and its button row.
|
||||||
*
|
*
|
||||||
* All decisions are in [state]; this draws them. The texts are read from [languageStore] in
|
* All decisions are in [state]; this draws them. The texts are read from [languageStore] in
|
||||||
* the composition, so the language picker on the first page switches the wizard itself.
|
* the composition, so the language picker on the personal page switches the wizard itself.
|
||||||
*
|
*
|
||||||
* @param saveFailed whether the last Save could not write the file
|
* @param saveFailed whether the last Save could not write the file
|
||||||
* @param onLater the operator does not want to set up now; nothing is written
|
* @param onLater the operator does not want to set up now; nothing is written
|
||||||
@@ -183,6 +183,7 @@ private fun PersonalPage(state: SetupWizardState, strings: Strings, languageStor
|
|||||||
onSelect = { languageStore.use(it) },
|
onSelect = { languageStore.use(it) },
|
||||||
)
|
)
|
||||||
Form.text(strings.wizardPersonalName, state.name) { state.name = it }
|
Form.text(strings.wizardPersonalName, state.name) { state.name = it }
|
||||||
|
if (state.nameRefused) Refusal(strings.wizardPersonalNameInvalid)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -192,6 +193,7 @@ private fun LoginPage(state: SetupWizardState, strings: Strings) {
|
|||||||
Form.text(strings.stationCallsign, state.callsign) { state.callsign = it }
|
Form.text(strings.stationCallsign, state.callsign) { state.callsign = it }
|
||||||
if (state.callsignRefused) Refusal(strings.wizardLoginCallsignInvalid)
|
if (state.callsignRefused) Refusal(strings.wizardLoginCallsignInvalid)
|
||||||
Form.password(strings.stationPassword, state.password) { state.password = it }
|
Form.password(strings.stationPassword, state.password) { state.password = it }
|
||||||
|
if (state.passwordRefused) Refusal(strings.wizardLoginPasswordInvalid)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -249,6 +251,10 @@ private fun SummaryPage(state: SetupWizardState, strings: Strings, saveFailed: B
|
|||||||
if (state.leavesIntegrationsUntouched) Text(strings.wizardSummaryIntegrationsUnchanged)
|
if (state.leavesIntegrationsUntouched) Text(strings.wizardSummaryIntegrationsUnchanged)
|
||||||
|
|
||||||
Form.section(strings.wizardSummaryPersonal) {
|
Form.section(strings.wizardSummaryPersonal) {
|
||||||
|
SummaryRow(
|
||||||
|
strings.guiLanguage,
|
||||||
|
if (state.language == SYSTEM_LANGUAGE) strings.guiLanguageSystem else state.language.uppercase(),
|
||||||
|
)
|
||||||
SummaryRow(strings.wizardPersonalName, state.name.ifBlank { strings.wizardSummaryNone })
|
SummaryRow(strings.wizardPersonalName, state.name.ifBlank { strings.wizardSummaryNone })
|
||||||
Form.button(strings.wizardChange) { state.edit(WizardPage.PERSONAL) }
|
Form.button(strings.wizardChange) { state.edit(WizardPage.PERSONAL) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,10 +204,10 @@ class SetupWizardState(prefs: ChatPreferences) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val personalComplete: Boolean
|
private val personalComplete: Boolean
|
||||||
get() = name.isNotBlank()
|
get() = isStorableName(name)
|
||||||
|
|
||||||
private val loginComplete: Boolean
|
private val loginComplete: Boolean
|
||||||
get() = isPlausibleCallsign(callsign) && password.isNotEmpty()
|
get() = isPlausibleCallsign(callsign) && isStorablePassword(password)
|
||||||
|
|
||||||
private val stationComplete: Boolean
|
private val stationComplete: Boolean
|
||||||
get() = isLocator(locator) && bands.isNotEmpty() && category in CATEGORY_NUMBERS &&
|
get() = isLocator(locator) && bands.isNotEmpty() && category in CATEGORY_NUMBERS &&
|
||||||
@@ -217,10 +217,18 @@ class SetupWizardState(prefs: ChatPreferences) {
|
|||||||
val mandatoryComplete: Boolean
|
val mandatoryComplete: Boolean
|
||||||
get() = personalComplete && loginComplete && stationComplete
|
get() = personalComplete && loginComplete && stationComplete
|
||||||
|
|
||||||
|
/** A chat name that was typed and cannot be sent. An empty or blank field is not an error yet. */
|
||||||
|
val nameRefused: Boolean
|
||||||
|
get() = name.isNotBlank() && !isStorableName(name)
|
||||||
|
|
||||||
/** A callsign that was typed and does not look like one. An empty field is not an error yet. */
|
/** A callsign that was typed and does not look like one. An empty field is not an error yet. */
|
||||||
val callsignRefused: Boolean
|
val callsignRefused: Boolean
|
||||||
get() = callsign.isNotBlank() && !isPlausibleCallsign(callsign)
|
get() = callsign.isNotBlank() && !isPlausibleCallsign(callsign)
|
||||||
|
|
||||||
|
/** A password that was typed and cannot be stored or sent. An empty field is not an error yet. */
|
||||||
|
val passwordRefused: Boolean
|
||||||
|
get() = password.isNotEmpty() && !isStorablePassword(password)
|
||||||
|
|
||||||
/** A locator that was typed and is not one. An empty field is not an error yet. */
|
/** A locator that was typed and is not one. An empty field is not an error yet. */
|
||||||
val locatorRefused: Boolean
|
val locatorRefused: Boolean
|
||||||
get() = locator.isNotBlank() && !isLocator(locator)
|
get() = locator.isNotBlank() && !isLocator(locator)
|
||||||
@@ -342,6 +350,21 @@ class SetupWizardState(prefs: ChatPreferences) {
|
|||||||
/** Whether a text is a six-character Maidenhead locator, in either case. */
|
/** Whether a text is a six-character Maidenhead locator, in either case. */
|
||||||
fun isLocator(text: String): Boolean = LOCATOR.matches(text.trim())
|
fun isLocator(text: String): Boolean = LOCATOR.matches(text.trim())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a password can be stored in preferences.xml and sent in an ON4KST login frame:
|
||||||
|
* not blank, free of surrounding whitespace (which the XML reader trims), and free of
|
||||||
|
* frame delimiters.
|
||||||
|
*/
|
||||||
|
fun isStorablePassword(text: String): Boolean =
|
||||||
|
text.isNotBlank() && text == text.trim() && '|' !in text && '\r' !in text && '\n' !in text
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a chat display name can be sent in an ON4KST frame: not blank and free of
|
||||||
|
* frame delimiters.
|
||||||
|
*/
|
||||||
|
fun isStorableName(text: String): Boolean =
|
||||||
|
text.isNotBlank() && '|' !in text && '\r' !in text && '\n' !in text
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The chat category the lowest band belongs to: 1 for 50/70 MHz, 2 for 144/432 MHz,
|
* The chat category the lowest band belongs to: 1 for 50/70 MHz, 2 for 144/432 MHz,
|
||||||
* 3 above. Null without a band. A suggestion only -- the operator confirms it.
|
* 3 above. Null without a band. A suggestion only -- the operator confirms it.
|
||||||
|
|||||||
@@ -145,9 +145,11 @@ object SetupWizardLauncher {
|
|||||||
/*
|
/*
|
||||||
* A file that cannot be read is not a profile to set up: the wizard would start from
|
* A file that cannot be read is not a profile to set up: the wizard would start from
|
||||||
* compiled-in defaults and Save would write them over whatever the file holds. The
|
* compiled-in defaults and Save would write them over whatever the file holds. The
|
||||||
* runtime deals with such a file as it always did.
|
* runtime deals with such a file as it always did. A throwing read counts as failed too.
|
||||||
*/
|
*/
|
||||||
if (!prefs.readPreferencesFromXmlFile()) return SetupWizardOutcome.NOT_SHOWN
|
if (!runCatching { prefs.readPreferencesFromXmlFile() }.getOrDefault(false)) {
|
||||||
|
return SetupWizardOutcome.NOT_SHOWN
|
||||||
|
}
|
||||||
|
|
||||||
if (!forced && !LoginConfiguration.isUnconfigured(prefs)) return SetupWizardOutcome.NOT_SHOWN
|
if (!forced && !LoginConfiguration.isUnconfigured(prefs)) return SetupWizardOutcome.NOT_SHOWN
|
||||||
|
|
||||||
|
|||||||
+38
@@ -1,5 +1,8 @@
|
|||||||
package kst4contest.view;
|
package kst4contest.view;
|
||||||
|
|
||||||
|
import kst4contest.controller.ActiveOperatorProfile;
|
||||||
|
import kst4contest.model.OperatorProfile;
|
||||||
|
import kst4contest.model.OperatorProfileSelection;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
@@ -20,4 +23,39 @@ class ApplicationRuntimeLauncherSetupWizardTest {
|
|||||||
assertTrue(ApplicationRuntimeLauncher.consumeSetupWizardRequest());
|
assertTrue(ApplicationRuntimeLauncher.consumeSetupWizardRequest());
|
||||||
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(), "the request must not stick");
|
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(), "the request must not stick");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void switchGuardAllowsOnlyOneSwitchAtATime() {
|
||||||
|
try {
|
||||||
|
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
|
||||||
|
assertFalse(ApplicationRuntimeLauncher.beginSwitch(),
|
||||||
|
"a second switch must be refused while one is in progress");
|
||||||
|
} finally {
|
||||||
|
ApplicationRuntimeLauncher.endSwitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertTrue(ApplicationRuntimeLauncher.beginSwitch(),
|
||||||
|
"ending the first switch must release the guard");
|
||||||
|
} finally {
|
||||||
|
ApplicationRuntimeLauncher.endSwitch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void rerunSetupWizardWhileSwitchInProgressReturnsFalseAndClearsRequest() {
|
||||||
|
OperatorProfileSelection previous = ActiveOperatorProfile.get();
|
||||||
|
OperatorProfile profile = new OperatorProfile("wizard-guard-test", "Wizard Guard Test", false, false);
|
||||||
|
ActiveOperatorProfile.set(new OperatorProfileSelection(profile, "preferences.xml", "worked.db", false));
|
||||||
|
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
|
||||||
|
try {
|
||||||
|
assertFalse(ApplicationRuntimeLauncher.rerunSetupWizard());
|
||||||
|
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(),
|
||||||
|
"a refused rerun must not leave a wizard request behind");
|
||||||
|
} finally {
|
||||||
|
ApplicationRuntimeLauncher.endSwitch();
|
||||||
|
ApplicationRuntimeLauncher.consumeSetupWizardRequest();
|
||||||
|
ActiveOperatorProfile.set(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+12
@@ -112,4 +112,16 @@ class SetupWizardContentScreenTest {
|
|||||||
|
|
||||||
onNodeWithText("The settings could not be written. Nothing was changed.").assertExists()
|
onNodeWithText("The settings could not be written. Nothing was changed.").assertExists()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun theSummaryShowsTheChosenLanguage() = runComposeUiTest {
|
||||||
|
val state = SetupWizardState(configuredProfile().apply { setGuiOptions_language("de") })
|
||||||
|
state.chooseLoginSource(WizardSource.KEEP)
|
||||||
|
state.chooseStationSource(WizardSource.KEEP)
|
||||||
|
state.next()
|
||||||
|
state.next()
|
||||||
|
show(state)
|
||||||
|
|
||||||
|
onNodeWithText("DE").assertExists()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+16
-1
@@ -12,7 +12,7 @@ import java.nio.file.Path
|
|||||||
import java.nio.file.StandardCopyOption
|
import java.nio.file.StandardCopyOption
|
||||||
|
|
||||||
/** When the wizard opens at all, decided without a window. */
|
/** When the wizard opens at all, decided without a window. */
|
||||||
class SetupWizardLauncherTest(@TempDir private val directory: Path) {
|
class SetupWizardLauncherTest(@param:TempDir private val directory: Path) {
|
||||||
|
|
||||||
private fun templateFile(): Path {
|
private fun templateFile(): Path {
|
||||||
val file = directory.resolve("preferences.xml")
|
val file = directory.resolve("preferences.xml")
|
||||||
@@ -81,6 +81,21 @@ class SetupWizardLauncherTest(@TempDir private val directory: Path) {
|
|||||||
assertArrayEquals(before, Files.readAllBytes(garbage), "the unreadable file was touched")
|
assertArrayEquals(before, Files.readAllBytes(garbage), "the unreadable file was touched")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun aFileTheReaderThrowsOnNeverOpensTheWizard() {
|
||||||
|
val file = templateFile()
|
||||||
|
val original = Files.readString(file)
|
||||||
|
assertTrue(original.contains("<ChatCategory>2</ChatCategory>"))
|
||||||
|
Files.writeString(file, original.replace("<ChatCategory>2</ChatCategory>", "<ChatCategory>2.0</ChatCategory>"))
|
||||||
|
val before = Files.readAllBytes(file)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
SetupWizardOutcome.NOT_SHOWN,
|
||||||
|
SetupWizardLauncher.run(ChatPreferences(file), forced = true, neverShown),
|
||||||
|
)
|
||||||
|
assertArrayEquals(before, Files.readAllBytes(file), "the unreadable file was touched")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun aFailedSaveKeepsTheWizardOpen() {
|
fun aFailedSaveKeepsTheWizardOpen() {
|
||||||
val source = ChatPreferences(templateFile()).apply { assertTrue(readPreferencesFromXmlFile()) }
|
val source = ChatPreferences(templateFile()).apply { assertTrue(readPreferencesFromXmlFile()) }
|
||||||
|
|||||||
@@ -351,4 +351,67 @@ class SetupWizardStateTest {
|
|||||||
assertTrue(state.mandatoryComplete)
|
assertTrue(state.mandatoryComplete)
|
||||||
assertFalse(state.pages.contains(WizardPage.SITE))
|
assertFalse(state.pages.contains(WizardPage.SITE))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun storablePasswordsAndNamesRejectDelimitersAndOuterWhitespace() {
|
||||||
|
listOf("secret", "se cret").forEach {
|
||||||
|
assertTrue(SetupWizardState.isStorablePassword(it), "'$it' must be accepted")
|
||||||
|
}
|
||||||
|
listOf("", " ", " secret", "secret ", "se|cret", "se\ncret", "se\rcret").forEach {
|
||||||
|
assertFalse(SetupWizardState.isStorablePassword(it), "'$it' must be refused")
|
||||||
|
}
|
||||||
|
|
||||||
|
listOf("Philipp", "Philipp W").forEach {
|
||||||
|
assertTrue(SetupWizardState.isStorableName(it), "'$it' must be accepted")
|
||||||
|
}
|
||||||
|
listOf("", " ", "Phil|ipp", "Phil\nipp", "Phil\ripp").forEach {
|
||||||
|
assertFalse(SetupWizardState.isStorableName(it), "'$it' must be refused")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun aRefusedPasswordOrNameIsReportedAndBlocksCompletion() {
|
||||||
|
val state = SetupWizardState(freshInstallation())
|
||||||
|
assertFalse(state.nameRefused)
|
||||||
|
state.name = " "
|
||||||
|
assertFalse(state.nameRefused)
|
||||||
|
assertFalse(state.canGoNext)
|
||||||
|
state.name = "Phil|ipp"
|
||||||
|
assertTrue(state.nameRefused)
|
||||||
|
assertFalse(state.canGoNext)
|
||||||
|
|
||||||
|
state.fillFirstInstallation()
|
||||||
|
state.back()
|
||||||
|
assertEquals(WizardPage.LOGIN, state.page)
|
||||||
|
assertFalse(state.passwordRefused)
|
||||||
|
|
||||||
|
listOf(" secret", "secret ", " ", "se|cret", "se\ncret").forEach { refused ->
|
||||||
|
state.password = refused
|
||||||
|
assertTrue(state.passwordRefused, "'$refused' must set passwordRefused")
|
||||||
|
assertFalse(state.canGoNext, "'$refused' must block Next on login")
|
||||||
|
assertFalse(state.mandatoryComplete, "'$refused' must block mandatoryComplete")
|
||||||
|
}
|
||||||
|
|
||||||
|
state.password = ""
|
||||||
|
assertFalse(state.passwordRefused)
|
||||||
|
assertFalse(state.canGoNext)
|
||||||
|
|
||||||
|
state.password = "se cret"
|
||||||
|
assertFalse(state.passwordRefused)
|
||||||
|
assertTrue(state.canGoNext)
|
||||||
|
assertTrue(state.mandatoryComplete)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun keepingALoginWithAStorablePasswordSkipsTheLoginPage() {
|
||||||
|
val state = SetupWizardState(configuredProfile())
|
||||||
|
state.chooseLoginSource(WizardSource.KEEP)
|
||||||
|
state.chooseStationSource(WizardSource.KEEP)
|
||||||
|
state.next()
|
||||||
|
|
||||||
|
assertFalse(state.pages.contains(WizardPage.LOGIN))
|
||||||
|
assertEquals(WizardPage.PERSONAL, state.page)
|
||||||
|
state.next()
|
||||||
|
assertEquals(WizardPage.SUMMARY, state.page)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ import java.nio.file.StandardCopyOption
|
|||||||
* What the wizard does to a real preferences file: nothing until Save, exactly the answers
|
* What the wizard does to a real preferences file: nothing until Save, exactly the answers
|
||||||
* afterwards, and every setting it never asked about left as it was.
|
* afterwards, and every setting it never asked about left as it was.
|
||||||
*/
|
*/
|
||||||
class SetupWizardWriteTest(@TempDir private val directory: Path) {
|
class SetupWizardWriteTest(@param:TempDir private val directory: Path) {
|
||||||
|
|
||||||
/** A copy of the bundled template, read the way the runtime reads a profile. */
|
/** A copy of the bundled template, read the way the runtime reads a profile. */
|
||||||
private fun templateFile(): Path {
|
private fun templateFile(): Path {
|
||||||
|
|||||||
@@ -2619,6 +2619,10 @@ public class ChatPreferences {
|
|||||||
|
|
||||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||||
Document doc = db.parse(xmlConfigFile);
|
Document doc = db.parse(xmlConfigFile);
|
||||||
|
Element rootElement = doc.getDocumentElement();
|
||||||
|
if (rootElement == null || !"praktiKST".equals(rootElement.getTagName())) {
|
||||||
|
readable = false;
|
||||||
|
}
|
||||||
NodeList list;
|
NodeList list;
|
||||||
|
|
||||||
// --- Schema version (optional) ---
|
// --- Schema version (optional) ---
|
||||||
|
|||||||
@@ -45,6 +45,18 @@ class ChatPreferencesReadResultTest {
|
|||||||
assertFalse(Files.exists(file), "reading a missing file must not create it");
|
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
|
@Test
|
||||||
void theBundledTemplateIsReadable() throws IOException {
|
void theBundledTemplateIsReadable() throws IOException {
|
||||||
Path templateCopy = temporaryDirectory.resolve("template.xml");
|
Path templateCopy = temporaryDirectory.resolve("template.xml");
|
||||||
|
|||||||
Reference in new issue
Block a user