134 lines
6.6 KiB
QML
134 lines
6.6 KiB
QML
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Networking
|
|
import "."
|
|
import "components"
|
|
|
|
ShellRoot {
|
|
id: test
|
|
property var device: null
|
|
property var network: null
|
|
property var controller: null
|
|
property var card: null
|
|
property int scenario: -1
|
|
property int successes: 0
|
|
property int secretRequests: 0
|
|
property bool finished: false
|
|
readonly property var names: ["connect and duplicate prevention", "failure and credentials request", "device removal", "disconnect", "timeout", "unmanaged device", "PSK forwarding", "wrong adapter", "credential field lifecycle"]
|
|
Component {
|
|
id: devices
|
|
QtObject {
|
|
property bool connected: false
|
|
property bool nmManaged: true
|
|
property int type: DeviceType.Wifi
|
|
property int state: 0
|
|
property int disconnects: 0
|
|
function disconnect() { disconnects++; connected = false; }
|
|
}
|
|
}
|
|
Component {
|
|
id: networks
|
|
QtObject {
|
|
property var device: null
|
|
property bool connected: false
|
|
property int state: 0
|
|
property int connects: 0
|
|
property string name: "Test network"
|
|
property bool known: false
|
|
property real signalStrength: 0.8
|
|
property int security: WifiSecurityType.Wpa2Psk
|
|
property int pskConnects: 0
|
|
property string captured: ""
|
|
signal connectionFailed(int reason)
|
|
function connect() { connects++; }
|
|
function connectWithPsk(value) { pskConnects++; captured = value; }
|
|
}
|
|
}
|
|
Component { id: cards; NetworkCard { width: 400; active: true; network: test.network; device: test.device; controller: test.controller } }
|
|
Component { id: controllers; NetworkController { timeoutMs: 1000 } }
|
|
Connections {
|
|
target: test.controller
|
|
function onSucceeded(action) { test.successes++; }
|
|
function onNeedsSecret(network) { test.secretRequests++; }
|
|
function onBusyChanged() { if (test.scenario === 4 && !test.controller.busy) Qt.callLater(test.finishTimeout); }
|
|
}
|
|
function check(value, message) { if (!value) { finished = true; console.error("NETWORK_TEST_FAIL: " + message); Qt.exit(1); throw new Error(message); } }
|
|
function complete() { console.log("PASS network controller: " + names[scenario]); Qt.callLater(next); }
|
|
function finishTimeout() {
|
|
check(controller.error !== "", "timeout error missing");
|
|
check(successes === 0 && device.disconnects === 0, "timeout triggered a mutation or success");
|
|
complete();
|
|
}
|
|
function next() {
|
|
if (card) { card.destroy(); card = null; }
|
|
if (controller) controller.destroy();
|
|
if (network) network.destroy();
|
|
if (device) device.destroy();
|
|
controller = null; network = null; device = null;
|
|
scenario++; successes = 0; secretRequests = 0;
|
|
if (scenario === names.length) { finished = true; console.log("NETWORK_TEST_PASS: 9 scenarios"); Qt.quit(); return; }
|
|
device = devices.createObject(test);
|
|
network = networks.createObject(test, {device: device});
|
|
controller = controllers.createObject(test, {device: device});
|
|
if (scenario === 0) {
|
|
check(controller.requestConnect(network), "connect rejected");
|
|
check(controller.busy && network.connects === 1, "connect not sent");
|
|
check(!controller.requestConnect(network), "duplicate request accepted");
|
|
network.connected = true;
|
|
check(!controller.busy && successes === 1, "connected state did not complete request");
|
|
} else if (scenario === 1) {
|
|
controller.requestConnect(network);
|
|
network.connectionFailed(ConnectionFailReason.NoSecrets);
|
|
check(!controller.busy && controller.error !== "", "failure lost");
|
|
check(secretRequests === 1 && successes === 0, "wrong failure result");
|
|
} else if (scenario === 2) {
|
|
controller.requestConnect(network);
|
|
controller.device = null;
|
|
check(!controller.busy && controller.error !== "" && successes === 0, "removed device not handled");
|
|
} else if (scenario === 3) {
|
|
device.connected = true;
|
|
check(controller.requestDisconnect(), "disconnect rejected");
|
|
check(device.disconnects === 1 && !controller.busy && successes === 1, "disconnect did not complete");
|
|
} else if (scenario === 4) {
|
|
controller.timeoutMs = 30;
|
|
controller.requestConnect(network);
|
|
return;
|
|
} else if (scenario === 5) {
|
|
device.nmManaged = false;
|
|
check(!controller.requestConnect(network) && network.connects === 0, "unmanaged device mutated");
|
|
} else if (scenario === 6) {
|
|
check(controller.requestConnect(network, "synthetic-test-key"), "PSK request rejected");
|
|
check(network.pskConnects === 1 && network.connects === 0 && network.captured === "synthetic-test-key", "PSK not forwarded correctly");
|
|
network.connectionFailed(ConnectionFailReason.NoSecrets);
|
|
check(!controller.error.includes("synthetic-test-key"), "PSK leaked into error");
|
|
} else if (scenario === 7) {
|
|
network.device = null;
|
|
check(!controller.requestConnect(network) && network.connects === 0, "wrong adapter accepted");
|
|
} else if (scenario === 8) {
|
|
card = cards.createObject(test);
|
|
const password = findItem(card, "networkPassword");
|
|
check(password !== null, "credential field not found");
|
|
card.credentials = true; password.text = "synthetic-test-key";
|
|
check(password.echoMode === TextInput.Password, "password is not masked");
|
|
card.active = false;
|
|
check(password.text === "" && !card.credentials, "password survived page close");
|
|
card.active = true;
|
|
controller.requestConnect(network);
|
|
network.connectionFailed(ConnectionFailReason.NoSecrets);
|
|
check(card.credentials, "credential prompt not opened");
|
|
password.text = "synthetic-test-key";
|
|
network.connected = true;
|
|
check(password.text === "" && !card.credentials, "password survived connection");
|
|
}
|
|
complete();
|
|
}
|
|
function findItem(parent, name) {
|
|
if (parent.objectName === name) return parent;
|
|
for (const child of parent.children || []) { const found = findItem(child, name); if (found) return found; }
|
|
return null;
|
|
}
|
|
Component.onCompleted: Qt.callLater(next)
|
|
Timer { interval: 15000; running: !test.finished; onTriggered: test.check(false, "harness timeout") }
|
|
}
|