Add independent Companion Bluetooth stealth flag
Keep stealth separate from custom, saved-random and rotating MAC policies without migrating the development MAC mode. Persist authenticated peer state, guard advertising transitions and recovery, and expose the setting through the CLI and WebConfig. Add regression and CI checks and record exact XIAO BLE pairing, reconnect, reboot and address-rotation hardware results.
This commit is contained in:
1 parent
4b400ea56b
commit
6958d82432
29 files changed
+3984
-2020
No files matched your search
+10
-1
@@ -20,6 +20,10 @@ python3 test/test_companion_transport_selector.py # Indicator transport-selecto
|
||||
python3 test/test_color_theme.py # shared color-display dark-palette contract
|
||||
python3 test/test_indicator_font_recovery.py # Indicator TLS/SD font recovery contract
|
||||
python3 test/test_companion_terminal_profile.py # Companion CLI capability gates
|
||||
python3 test/test_bluetooth_mac_contract.py # MAC policies, separate stealth flag and BLE backend integration
|
||||
python3 test/test_companion_settings_persistence_contract.py # Atomic settings and appended Bluetooth fields
|
||||
python3 test/test_webconfig_ui.py # Web controls, reboot handling and generated-page consistency
|
||||
python3 test/test_webconfig_ui_runtime.py # Real Chromium, including independent stealth toggle
|
||||
python3 test/test_nrf52_uf2reset_cli.py # all nRF52 text-CLI reset dispatchers
|
||||
python3 test/test_client_login_profile_contract.py # ACL login ordering/role contract
|
||||
python3 test/test_client_acl_spiffs.py # Actual ACL: first login, replay/reboot, failed storage
|
||||
@@ -40,6 +44,11 @@ python3 test/test_temp_radio_reply_delivery_contract.py # TempRadio ACK path/ba
|
||||
python3 test/test_tls_download_clock_gates.py # Fresh-NTP/TLS download integration contract
|
||||
```
|
||||
|
||||
The WebConfig browser suite skips if no Chromium-family browser is available.
|
||||
With a sandboxed browser that cannot read `/tmp`, set `TMPDIR` to a writable
|
||||
directory visible to that browser before running it. The Bluetooth settings
|
||||
contracts and WebConfig suites also run in the unit-test GitHub workflow.
|
||||
|
||||
A green `[PASSED]` per suite means GoogleTest returned 0 (all assertions
|
||||
passed). PlatformIO's "0 test cases" line is just its Unity-style counter and
|
||||
does not reflect the GoogleTest count -- run the built binary directly
|
||||
@@ -96,7 +105,7 @@ does not reflect the GoogleTest count -- run the built binary directly
|
||||
| `test_lazy_persistence` | `src/helpers/LazyPersistence.h` | first-write scheduling without postponement, zero-sentinel rollover preservation, capped exponential save-failure backoff that mutations cannot defeat, and reset only after success |
|
||||
| `test_client_acl_file_transaction` | `src/helpers/ClientACLFileTransaction.h` | verified temp publication, preservation of the prior ACL on verification/rename failure, post-commit cleanup-failure handling, and recovery at every temp/backup/primary boundary |
|
||||
| `test_cad_timing` | `src/helpers/radiolib/CadTiming.h`, `LR2021SideDetectorConfig.h`, `RadioAirtime.h` | Cascade and slow-profile CAD deadlines; invalid airtime handling; bounded LR2021 side-detector parsing and LDRO recomputation |
|
||||
| `test_companion_node_prefs` | `examples/companion_radio/NodePrefs.h` | independent device power saving, RXPS, Wi-Fi, FEM, Bluetooth name, and Bluetooth address preferences; random-static address validation/generation; one-time migration of the regressed power-saving default |
|
||||
| `test_companion_node_prefs` | `examples/companion_radio/NodePrefs.h` | independent device power saving, RXPS, Wi-Fi, FEM, Bluetooth name, address policy and stealth flag; random-static address validation/generation; idempotent stealth toggles, pairing reset and armed rotation policy matching; one-time migration of the regressed power-saving default |
|
||||
| `test_config_serializer` | `src/helpers/ConfigSerializer.cpp`, Companion `NodePrefs` | escaped config save/load, whitespace and malformed input, unknown fields, and FEM/ESP-NOW bridge-format preference round trips |
|
||||
| `test_deferred_cli_command` | `src/helpers/DeferredCliCommand.h` | copying authenticated command context, single-pending-command enforcement, clearing, and length rejection |
|
||||
| `test_host_cli_bridge` | `src/helpers/HostCliBridge.h` | bounded request/reply parsing, Base64URL serial framing, correlation preservation, one-time service-claim proofs, request-token fields, line safety, and UTF-8-safe truncation |
|
||||
|
||||
@@ -26,9 +26,12 @@ class BluetoothMacContractTests(unittest.TestCase):
|
||||
for header in (self.nrf_header, self.esp_header):
|
||||
self.assertIn("const uint8_t* custom_address = nullptr", header)
|
||||
self.assertIn("bool clear_bonds = false", header)
|
||||
self.assertIn("bool stealth_pair_once = false", header)
|
||||
self.assertIn("bonded_only_peer", header)
|
||||
|
||||
self.assertIn("the_mesh.getBLEPin(), bluetooth_address,", self.main)
|
||||
self.assertIn("clear_bonds))", self.main)
|
||||
self.assertIn("clear_bonds, stealth_pair_once,", self.main)
|
||||
self.assertIn("bonded_only_peer_ptr))", self.main)
|
||||
|
||||
def test_nrf52_uses_random_static_softdevice_address(self):
|
||||
self.assertIn("BLE_GAP_ADDR_TYPE_RANDOM_STATIC", self.nrf_source)
|
||||
@@ -53,15 +56,143 @@ class BluetoothMacContractTests(unittest.TestCase):
|
||||
)
|
||||
self.assertIn("clear_bonds = true;", self.main)
|
||||
|
||||
def test_cli_exposes_custom_random_every_boot_and_default(self):
|
||||
def test_cli_exposes_all_address_modes(self):
|
||||
self.assertIn('"get bluetooth.mac"', self.mesh)
|
||||
self.assertIn('"set bluetooth.mac"', self.mesh)
|
||||
self.assertIn('strcmp(value, "random")', self.mesh)
|
||||
self.assertIn('strcmp(value, "random-every-boot")', self.mesh)
|
||||
self.assertIn('strcmp(value, "random everyboot")', self.mesh)
|
||||
self.assertIn('strcmp(value, "random-after-connect")', self.mesh)
|
||||
self.assertNotIn('strcmp(value, "stealth")', self.mesh)
|
||||
self.assertIn('strcmp(value, "default")', self.mesh)
|
||||
self.assertIn("parseBluetoothMac(custom_value, address)", self.mesh)
|
||||
|
||||
def test_stealth_is_a_separate_idempotent_flag(self):
|
||||
self.assertIn('"get bluetooth.stealth"', self.mesh)
|
||||
self.assertIn('"set bluetooth.stealth"', self.mesh)
|
||||
self.assertIn('"get ble.stealth"', self.mesh)
|
||||
self.assertIn('"set ble.stealth"', self.mesh)
|
||||
setter = self.mesh[
|
||||
self.mesh.index("bool MyMesh::applyAndSaveBluetoothStealth("):
|
||||
self.mesh.index("void MyMesh::formatBluetoothStealthStatus(")
|
||||
]
|
||||
self.assertIn('strcmp(value, "on")', setter)
|
||||
self.assertIn('strcmp(value, "off")', setter)
|
||||
self.assertIn("setCompanionBluetoothStealth(_prefs,", setter)
|
||||
self.assertIn("&& !savePrefs()", setter)
|
||||
self.assertIn("_prefs.bluetooth_stealth_mode = previous_mode", setter)
|
||||
self.assertNotIn("saveBluetoothMac(", setter)
|
||||
self.assertNotIn("_prefs.bluetooth_mac_mode =", setter)
|
||||
self.assertNotIn("getRNG()", setter)
|
||||
self.assertNotIn("|stealth|", self.mesh)
|
||||
|
||||
def test_rotation_and_stealth_share_the_authenticated_event(self):
|
||||
self.assertIn("companion_bluetooth_session_stealth_mode", self.main)
|
||||
self.assertIn("prefs->bluetooth_stealth_mode", self.main)
|
||||
self.assertIn("bluetoothMacPoliciesMatch(", self.main)
|
||||
start = self.mesh.index("bool MyMesh::prepareBluetoothMacForBoot(")
|
||||
end = self.mesh.index("bool MyMesh::armBluetoothMacRotationAfterConnection(")
|
||||
self.assertIn("BLUETOOTH_MAC_RANDOM_EVERY_BOOT", self.mesh[start:end])
|
||||
self.assertIn("resetBluetoothStealthPairing()", self.mesh[start:end])
|
||||
start = self.mesh.index("bool MyMesh::saveBluetoothStealthPeer(")
|
||||
end = self.mesh.index("bool MyMesh::resetBluetoothStealthPairing()")
|
||||
save_peer = self.mesh[start:end]
|
||||
self.assertLess(save_peer.index("BLUETOOTH_MAC_RANDOM_AFTER_CONNECT_ARMED"),
|
||||
save_peer.index("if (savePrefs())"))
|
||||
self.assertIn("_prefs.bluetooth_mac_mode = previous_mode", save_peer)
|
||||
start = self.mesh.index("bool MyMesh::saveBluetoothMac(")
|
||||
end = self.mesh.index("bool MyMesh::applyAndSaveBluetoothMac(")
|
||||
self.assertIn("clearCompanionBluetoothStealthPeer(_prefs)", self.mesh[start:end])
|
||||
self.assertIn("_prefs.bluetooth_stealth_mode = previous_stealth_mode",
|
||||
self.mesh[start:end])
|
||||
|
||||
def test_web_snapshot_and_dispatch_keep_flag_separate(self):
|
||||
self.assertIn('strcmp(key, "bluetooth.stealth")', self.mesh)
|
||||
self.assertIn("s.bluetooth_stealth =", self.mesh)
|
||||
self.assertNotIn('sizeof(s.bluetooth_mac), "stealth"', self.mesh)
|
||||
self.assertIn("CAP_BLUETOOTH_STEALTH", self.mesh)
|
||||
|
||||
def test_random_after_connect_arms_after_authentication(self):
|
||||
self.assertIn("takeSuccessfulConnection(", self.nrf_header)
|
||||
self.assertIn("takeSuccessfulConnection(", self.esp_header)
|
||||
self.assertIn(
|
||||
"_successfulConnectionPending.store(", self.nrf_source
|
||||
)
|
||||
self.assertIn(
|
||||
"_successfulConnectionPending.store(", self.esp_source
|
||||
)
|
||||
self.assertIn("prepareBluetoothMacForBoot", self.main)
|
||||
self.assertIn("armBluetoothMacRotationAfterConnection", self.main)
|
||||
self.assertIn("bluetoothMacModeIsRandomAfterConnect", self.main)
|
||||
self.assertIn(
|
||||
"companion_bluetooth_clear_bonds_this_boot", self.main
|
||||
)
|
||||
|
||||
def test_stealth_switches_to_bonded_peer_only_advertising(self):
|
||||
for header in (self.nrf_header, self.esp_header):
|
||||
self.assertIn("enableBondedOnlyAdvertising", header)
|
||||
self.assertIn("takeBondedOnlyRecovery", header)
|
||||
self.assertIn("cancelStealthPairingTransition", header)
|
||||
|
||||
self.assertIn(
|
||||
"BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED",
|
||||
self.nrf_source,
|
||||
)
|
||||
self.assertIn("Bluefruit.Advertising.clearData()", self.nrf_source)
|
||||
self.assertIn("Bluefruit.ScanResponse.clearData()", self.nrf_source)
|
||||
self.assertIn("setPeerAddress(native_peer)", self.nrf_source)
|
||||
self.assertIn("sd_ble_gap_device_identities_set(", self.nrf_source)
|
||||
self.assertIn("serviceBondedOnlyTransition()", self.nrf_source)
|
||||
self.assertIn("_bonded_only_configure_pending", self.nrf_source)
|
||||
self.assertIn("ble_gap_wl_set(&native_peer, 1)", self.esp_source)
|
||||
self.assertIn("esp_ble_gap_clear_whitelist()", self.esp_source)
|
||||
self.assertIn("esp_ble_gap_update_whitelist", self.esp_source)
|
||||
self.assertIn("advertising->setScanFilter(true, true)", self.esp_source)
|
||||
self.assertIn("advertising->setScanResponse(false)", self.esp_source)
|
||||
self.assertIn("saveBluetoothStealthPeer", self.main)
|
||||
|
||||
def test_stealth_holds_general_advertising_during_transition(self):
|
||||
for source_text in (self.nrf_source, self.esp_source):
|
||||
self.assertIn("_advertisingSuppressed.store(", source_text)
|
||||
self.assertIn("advertisingAllowed()", source_text)
|
||||
callback_at = source_text.index(
|
||||
"void SerialBLEInterface::noteSuccessfulConnection"
|
||||
)
|
||||
callback_end = source_text.index("\n}", callback_at)
|
||||
callback = source_text[callback_at:callback_end]
|
||||
self.assertLess(
|
||||
callback.index("_advertisingSuppressed.store("),
|
||||
callback.index("_successfulConnectionPending.store("),
|
||||
)
|
||||
self.assertIn("restartOnDisconnect(false)", self.nrf_source)
|
||||
self.assertIn(
|
||||
"_conn_handle != BLE_CONN_HANDLE_INVALID",
|
||||
self.nrf_source[
|
||||
self.nrf_source.index(
|
||||
"bool SerialBLEInterface::enableBondedOnlyAdvertising"
|
||||
) : self.nrf_source.index(
|
||||
"void SerialBLEInterface::serviceBondedOnlyTransition"
|
||||
)
|
||||
],
|
||||
)
|
||||
pairing_callback = self.nrf_source.index(
|
||||
"void SerialBLEInterface::onPairingComplete"
|
||||
)
|
||||
pairing_success = self.nrf_source.index(
|
||||
"pairing successful", pairing_callback
|
||||
)
|
||||
next_callback = self.nrf_source.index(
|
||||
"void SerialBLEInterface::onBLEEvent", pairing_success
|
||||
)
|
||||
self.assertIn(
|
||||
"noteSuccessfulConnection(conn->getPeerAddr())",
|
||||
self.nrf_source[pairing_success:next_callback],
|
||||
)
|
||||
self.assertIn("resetBluetoothStealthPairing", self.main)
|
||||
for source_text in (self.nrf_source, self.esp_source):
|
||||
self.assertIn("BLE_BOND_PERSIST_TIMEOUT_MS", source_text)
|
||||
self.assertIn("new peer bond did not persist", source_text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -165,6 +165,10 @@ TEST(CompanionNodePrefs, BluetoothMacDefaultsToFactoryIdentity) {
|
||||
prefs.bluetooth_mac_mode);
|
||||
EXPECT_FALSE(mesh::companion::hasCustomBluetoothMac(
|
||||
prefs.bluetooth_mac));
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_PEER_ADDRESS_NONE,
|
||||
prefs.bluetooth_stealth_peer_type);
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_STEALTH_OFF,
|
||||
prefs.bluetooth_stealth_mode);
|
||||
}
|
||||
|
||||
TEST(CompanionNodePrefs, BluetoothMacParsesAndFormatsRandomStaticAddress) {
|
||||
@@ -219,6 +223,27 @@ TEST(CompanionNodePrefs, BluetoothMacRandomBytesAreNormalized) {
|
||||
EXPECT_EQ(0xFE, all_one[5]);
|
||||
}
|
||||
|
||||
TEST(CompanionNodePrefs,
|
||||
BluetoothMacRandomAfterConnectCannotReuseTheOldAddress) {
|
||||
uint8_t address[mesh::companion::BLUETOOTH_MAC_BYTES] = {
|
||||
0xC0, 0x00, 0x00, 0x00, 0x00, 0x01};
|
||||
uint8_t previous[mesh::companion::BLUETOOTH_MAC_BYTES];
|
||||
memcpy(previous, address, sizeof(previous));
|
||||
|
||||
mesh::companion::makeRandomStaticBluetoothMacDifferentFrom(
|
||||
address, previous);
|
||||
EXPECT_TRUE(mesh::companion::isValidBluetoothMac(address));
|
||||
EXPECT_NE(0, memcmp(address, previous, sizeof(address)));
|
||||
|
||||
memset(address, 0xFF, sizeof(address));
|
||||
address[5] = 0xFE;
|
||||
memcpy(previous, address, sizeof(previous));
|
||||
mesh::companion::makeRandomStaticBluetoothMacDifferentFrom(
|
||||
address, previous);
|
||||
EXPECT_TRUE(mesh::companion::isValidBluetoothMac(address));
|
||||
EXPECT_NE(0, memcmp(address, previous, sizeof(address)));
|
||||
}
|
||||
|
||||
TEST(CompanionNodePrefs, BluetoothMacModesDescribeSavedAndPerBootUse) {
|
||||
EXPECT_TRUE(mesh::companion::isValidBluetoothMacMode(
|
||||
mesh::companion::BLUETOOTH_MAC_DEFAULT));
|
||||
@@ -228,15 +253,131 @@ TEST(CompanionNodePrefs, BluetoothMacModesDescribeSavedAndPerBootUse) {
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_SAVED));
|
||||
EXPECT_TRUE(mesh::companion::isValidBluetoothMacMode(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_EVERY_BOOT));
|
||||
EXPECT_FALSE(mesh::companion::isValidBluetoothMacMode(4));
|
||||
EXPECT_TRUE(mesh::companion::isValidBluetoothMacMode(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT));
|
||||
EXPECT_TRUE(mesh::companion::isValidBluetoothMacMode(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT_ARMED));
|
||||
EXPECT_FALSE(mesh::companion::isValidBluetoothMacMode(6));
|
||||
EXPECT_FALSE(mesh::companion::isValidBluetoothMacMode(7));
|
||||
EXPECT_FALSE(mesh::companion::isValidBluetoothMacMode(8));
|
||||
EXPECT_TRUE(mesh::companion::bluetoothMacModeUsesSavedAddress(
|
||||
mesh::companion::BLUETOOTH_MAC_CUSTOM));
|
||||
EXPECT_TRUE(mesh::companion::bluetoothMacModeUsesSavedAddress(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_SAVED));
|
||||
EXPECT_TRUE(mesh::companion::bluetoothMacModeUsesSavedAddress(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT));
|
||||
EXPECT_FALSE(mesh::companion::bluetoothMacModeUsesSavedAddress(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_EVERY_BOOT));
|
||||
}
|
||||
|
||||
TEST(CompanionNodePrefs,
|
||||
BluetoothMacRandomAfterConnectRotatesOnlyWhenArmedOrInvalid) {
|
||||
const uint8_t valid[mesh::companion::BLUETOOTH_MAC_BYTES] = {
|
||||
0xC2, 0x11, 0x22, 0x33, 0x44, 0x55};
|
||||
const uint8_t invalid[mesh::companion::BLUETOOTH_MAC_BYTES] = {};
|
||||
|
||||
EXPECT_TRUE(mesh::companion::bluetoothMacModeIsRandomAfterConnect(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT));
|
||||
EXPECT_TRUE(mesh::companion::bluetoothMacModeIsRandomAfterConnect(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT_ARMED));
|
||||
EXPECT_FALSE(mesh::companion::bluetoothMacModeIsRandomAfterConnect(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_EVERY_BOOT));
|
||||
|
||||
EXPECT_FALSE(mesh::companion::bluetoothMacShouldRotateAtBoot(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT, valid));
|
||||
EXPECT_TRUE(mesh::companion::bluetoothMacShouldRotateAtBoot(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT_ARMED, valid));
|
||||
EXPECT_TRUE(mesh::companion::bluetoothMacShouldRotateAtBoot(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT, invalid));
|
||||
EXPECT_FALSE(mesh::companion::bluetoothMacShouldRotateAtBoot(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_SAVED, invalid));
|
||||
}
|
||||
|
||||
TEST(CompanionNodePrefs, BluetoothStealthTracksPairingIndependently) {
|
||||
EXPECT_TRUE(mesh::companion::bluetoothStealthEnabled(
|
||||
mesh::companion::BLUETOOTH_STEALTH_PAIRING));
|
||||
EXPECT_TRUE(mesh::companion::bluetoothStealthEnabled(
|
||||
mesh::companion::BLUETOOTH_STEALTH_PAIRED));
|
||||
EXPECT_FALSE(mesh::companion::bluetoothStealthEnabled(
|
||||
mesh::companion::BLUETOOTH_STEALTH_OFF));
|
||||
EXPECT_FALSE(mesh::companion::isValidBluetoothStealthMode(3));
|
||||
EXPECT_FALSE(mesh::companion::bluetoothStealthEnabled(255));
|
||||
|
||||
mesh::companion::BluetoothPeerIdentity peer;
|
||||
EXPECT_FALSE(mesh::companion::isValidBluetoothPeerIdentity(peer));
|
||||
peer.type = mesh::companion::BLUETOOTH_PEER_ADDRESS_RANDOM;
|
||||
peer.address[0] = 0xC2;
|
||||
peer.address[5] = 0x55;
|
||||
EXPECT_TRUE(mesh::companion::isValidBluetoothPeerIdentity(peer));
|
||||
peer.type = 3;
|
||||
EXPECT_FALSE(mesh::companion::isValidBluetoothPeerIdentity(peer));
|
||||
}
|
||||
|
||||
TEST(CompanionNodePrefs, StealthFlagPreservesEveryMacPolicyAndAddress) {
|
||||
const uint8_t address[] = {0xC2, 0x11, 0x22, 0x33, 0x44, 0x55};
|
||||
for (uint8_t mode = mesh::companion::BLUETOOTH_MAC_DEFAULT;
|
||||
mode <= mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT_ARMED;
|
||||
mode++) {
|
||||
CompanionNodePrefs prefs;
|
||||
prefs.bluetooth_mac_mode = mode;
|
||||
memcpy(prefs.bluetooth_mac, address, sizeof(address));
|
||||
EXPECT_TRUE(setCompanionBluetoothStealth(prefs, true));
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_STEALTH_PAIRING,
|
||||
prefs.bluetooth_stealth_mode);
|
||||
EXPECT_EQ(mode, prefs.bluetooth_mac_mode);
|
||||
EXPECT_EQ(0, memcmp(address, prefs.bluetooth_mac, sizeof(address)));
|
||||
|
||||
prefs.bluetooth_stealth_mode = mesh::companion::BLUETOOTH_STEALTH_PAIRED;
|
||||
prefs.bluetooth_stealth_peer_type = mesh::companion::BLUETOOTH_PEER_ADDRESS_PUBLIC;
|
||||
memcpy(prefs.bluetooth_stealth_peer, address, sizeof(address));
|
||||
EXPECT_FALSE(setCompanionBluetoothStealth(prefs, true));
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_STEALTH_PAIRED,
|
||||
prefs.bluetooth_stealth_mode);
|
||||
EXPECT_EQ(0, memcmp(address, prefs.bluetooth_stealth_peer, sizeof(address)));
|
||||
|
||||
EXPECT_TRUE(setCompanionBluetoothStealth(prefs, false));
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_STEALTH_OFF, prefs.bluetooth_stealth_mode);
|
||||
EXPECT_EQ(mode, prefs.bluetooth_mac_mode);
|
||||
EXPECT_EQ(0, memcmp(address, prefs.bluetooth_mac, sizeof(address)));
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_PEER_ADDRESS_NONE,
|
||||
prefs.bluetooth_stealth_peer_type);
|
||||
const uint8_t empty[mesh::companion::BLUETOOTH_MAC_BYTES] = {};
|
||||
EXPECT_EQ(0, memcmp(empty, prefs.bluetooth_stealth_peer, sizeof(empty)));
|
||||
EXPECT_FALSE(setCompanionBluetoothStealth(prefs, false));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CompanionNodePrefs, AddressChangeReopensPairingWithoutDisablingStealth) {
|
||||
CompanionNodePrefs prefs;
|
||||
prefs.bluetooth_mac_mode = mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT_ARMED;
|
||||
prefs.bluetooth_stealth_mode = mesh::companion::BLUETOOTH_STEALTH_PAIRED;
|
||||
prefs.bluetooth_stealth_peer_type = mesh::companion::BLUETOOTH_PEER_ADDRESS_PUBLIC;
|
||||
memset(prefs.bluetooth_stealth_peer, 0x12, sizeof(prefs.bluetooth_stealth_peer));
|
||||
clearCompanionBluetoothStealthPeer(prefs);
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_STEALTH_PAIRING,
|
||||
prefs.bluetooth_stealth_mode);
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT_ARMED,
|
||||
prefs.bluetooth_mac_mode);
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_PEER_ADDRESS_NONE,
|
||||
prefs.bluetooth_stealth_peer_type);
|
||||
|
||||
prefs.bluetooth_stealth_mode = mesh::companion::BLUETOOTH_STEALTH_OFF;
|
||||
clearCompanionBluetoothStealthPeer(prefs);
|
||||
EXPECT_EQ(mesh::companion::BLUETOOTH_STEALTH_OFF, prefs.bluetooth_stealth_mode);
|
||||
}
|
||||
|
||||
TEST(CompanionNodePrefs, ArmingRotationDoesNotChangeSessionPolicy) {
|
||||
EXPECT_TRUE(mesh::companion::bluetoothMacPoliciesMatch(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT,
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT_ARMED));
|
||||
EXPECT_TRUE(mesh::companion::bluetoothMacPoliciesMatch(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT_ARMED,
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT));
|
||||
EXPECT_FALSE(mesh::companion::bluetoothMacPoliciesMatch(
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_EVERY_BOOT,
|
||||
mesh::companion::BLUETOOTH_MAC_RANDOM_AFTER_CONNECT));
|
||||
}
|
||||
|
||||
TEST(CompanionNodePrefs, MigratesRegressedPowerSavingDefaultOnce) {
|
||||
CompanionNodePrefs prefs = {};
|
||||
prefs.powersaving_enabled = 0;
|
||||
|
||||
@@ -115,8 +115,18 @@ class CompanionSettingsPersistenceContractTests(unittest.TestCase):
|
||||
cad_at = self.prefs.index("uint16_t cad_max_duration_ms")
|
||||
mode_at = self.prefs.index("uint8_t bluetooth_mac_mode", cad_at)
|
||||
address_at = self.prefs.index("uint8_t bluetooth_mac[", mode_at)
|
||||
peer_type_at = self.prefs.index(
|
||||
"uint8_t bluetooth_stealth_peer_type", address_at
|
||||
)
|
||||
peer_at = self.prefs.index(
|
||||
"uint8_t bluetooth_stealth_peer[", peer_type_at
|
||||
)
|
||||
stealth_at = self.prefs.index("uint8_t bluetooth_stealth_mode", peer_at)
|
||||
self.assertLess(cad_at, mode_at)
|
||||
self.assertLess(mode_at, address_at)
|
||||
self.assertLess(address_at, peer_type_at)
|
||||
self.assertLess(peer_type_at, peer_at)
|
||||
self.assertLess(peer_at, stealth_at)
|
||||
|
||||
load = function_body(
|
||||
self.store,
|
||||
@@ -130,7 +140,22 @@ class CompanionSettingsPersistenceContractTests(unittest.TestCase):
|
||||
read_address_at = load.index(
|
||||
"readOptionalField(loaded_prefs.bluetooth_mac", read_mode_at
|
||||
)
|
||||
read_peer_type_at = load.index(
|
||||
"readOptionalField(&loaded_prefs.bluetooth_stealth_peer_type",
|
||||
read_address_at,
|
||||
)
|
||||
read_peer_at = load.index(
|
||||
"readOptionalField(loaded_prefs.bluetooth_stealth_peer",
|
||||
read_peer_type_at,
|
||||
)
|
||||
read_stealth_at = load.index(
|
||||
"readOptionalField(&loaded_prefs.bluetooth_stealth_mode", read_peer_at
|
||||
)
|
||||
self.assertIn("sizeof(loaded_prefs.bluetooth_stealth_mode)", load)
|
||||
self.assertLess(read_mode_at, read_address_at)
|
||||
self.assertLess(read_address_at, read_peer_type_at)
|
||||
self.assertLess(read_peer_type_at, read_peer_at)
|
||||
self.assertLess(read_peer_at, read_stealth_at)
|
||||
|
||||
save = function_body(
|
||||
self.store,
|
||||
@@ -140,7 +165,17 @@ class CompanionSettingsPersistenceContractTests(unittest.TestCase):
|
||||
write_address_at = save.index(
|
||||
"(uint8_t *)_prefs.bluetooth_mac,", write_mode_at
|
||||
)
|
||||
write_peer_type_at = save.index(
|
||||
"&_prefs.bluetooth_stealth_peer_type", write_address_at
|
||||
)
|
||||
write_peer_at = save.index(
|
||||
"(uint8_t *)_prefs.bluetooth_stealth_peer,", write_peer_type_at
|
||||
)
|
||||
write_stealth_at = save.index("&_prefs.bluetooth_stealth_mode", write_peer_at)
|
||||
self.assertLess(write_mode_at, write_address_at)
|
||||
self.assertLess(write_address_at, write_peer_type_at)
|
||||
self.assertLess(write_peer_type_at, write_peer_at)
|
||||
self.assertLess(write_peer_at, write_stealth_at)
|
||||
|
||||
def test_channel_source_discovery_and_open_failures_latch_quarantine(self):
|
||||
load = function_body(self.store, "void DataStore::loadChannels(")
|
||||
|
||||
@@ -10,6 +10,7 @@ TEST(WebConfigKeys, AllowsKnownScalarKeys) {
|
||||
EXPECT_TRUE(wcIsAllowedSetKey("name"));
|
||||
EXPECT_TRUE(wcIsAllowedSetKey("bluetooth.name"));
|
||||
EXPECT_TRUE(wcIsAllowedSetKey("bluetooth.mac"));
|
||||
EXPECT_TRUE(wcIsAllowedSetKey("bluetooth.stealth"));
|
||||
EXPECT_TRUE(wcIsAllowedSetKey("radio"));
|
||||
EXPECT_TRUE(wcIsAllowedSetKey("radio.rxps"));
|
||||
EXPECT_TRUE(wcIsAllowedSetKey("powersaving"));
|
||||
@@ -36,6 +37,7 @@ TEST(WebConfigKeys, RejectsDangerousOrUnknownKeys) {
|
||||
EXPECT_FALSE(wcIsAllowedSetKey("password"));
|
||||
EXPECT_FALSE(wcIsAllowedSetKey("reboot"));
|
||||
EXPECT_FALSE(wcIsAllowedSetKey("bogus"));
|
||||
EXPECT_FALSE(wcIsAllowedSetKey("bluetooth.stealth.extra"));
|
||||
EXPECT_FALSE(wcIsAllowedSetKey("mqtt1.bogus")); // unknown slot field
|
||||
EXPECT_FALSE(wcIsAllowedSetKey(""));
|
||||
}
|
||||
@@ -72,6 +74,8 @@ TEST(WebConfigKeys, IsCaseSensitive) {
|
||||
TEST(WebConfigKeys, AddressChangingKeysAlwaysRequireAReboot) {
|
||||
EXPECT_TRUE(wcSetKeyRequiresReboot("espnow.channel"));
|
||||
EXPECT_TRUE(wcSetKeyRequiresReboot("bluetooth.mac"));
|
||||
EXPECT_TRUE(wcSetKeyRequiresReboot("bluetooth.stealth"));
|
||||
EXPECT_FALSE(wcSetKeyRequiresReboot("bluetooth.stealth.extra"));
|
||||
EXPECT_FALSE(wcSetKeyRequiresReboot(NULL));
|
||||
EXPECT_FALSE(wcSetKeyRequiresReboot("espnow.channel.extra"));
|
||||
EXPECT_FALSE(wcSetKeyRequiresReboot("ESPNOW.channel"));
|
||||
|
||||
@@ -194,9 +194,22 @@ class WebConfigUiTest(unittest.TestCase):
|
||||
self.assertIn('data-k="bluetooth.mac"', page)
|
||||
self.assertIn('case"bluetooth.mac":return r.bluetooth_mac||"";', page)
|
||||
self.assertIn("random-every-boot", page)
|
||||
self.assertIn("random-after-connect", page)
|
||||
self.assertNotIn("random-after-connect, or stealth", page)
|
||||
self.assertIn('("bluetooth.mac" in setmap)', page)
|
||||
self.assertIn("Bluetooth address saved [OK] - rebooting", page)
|
||||
|
||||
def test_stealth_flag_has_independent_control_and_reboot_flow(self):
|
||||
page = SOURCE.read_text(encoding="utf-8")
|
||||
self.assertIn('data-cap="131072"><label>Bluetooth stealth</label>', page)
|
||||
self.assertIn('data-k="bluetooth.stealth"', page)
|
||||
self.assertIn('case"bluetooth.stealth":return r.bluetooth_stealth?"on":"off";', page)
|
||||
self.assertIn('("bluetooth.stealth" in setmap)', page)
|
||||
self.assertIn('("bluetooth.stealth" in st.dirty)', page)
|
||||
self.assertIn('("bluetooth.stealth" in submitted)', page)
|
||||
self.assertIn("Bluetooth stealth saved [OK] - rebooting", page)
|
||||
self.assertNotIn("|stealth|", page)
|
||||
|
||||
def test_scan_panel_exposes_automatic_updates_accessibly(self):
|
||||
page = SOURCE.read_text(encoding="utf-8")
|
||||
self.assertIn('id="wz-scan-btn"', page)
|
||||
|
||||
@@ -347,6 +347,55 @@ class WebConfigUiRuntimeTest(unittest.TestCase):
|
||||
self.assertIn('data-test-dirty-name="Early App Edit"', dom)
|
||||
self.assertIn('data-test-capture="clear"', dom)
|
||||
|
||||
def test_bluetooth_stealth_toggle_preserves_custom_mac(self):
|
||||
status, config = self.setup_values()
|
||||
status["mode"] = "lan"
|
||||
status["capabilities"] = (1 << 16) | (1 << 17)
|
||||
config["radio"]["bluetooth_mac"] = "C2:11:22:33:44:55"
|
||||
config["radio"]["bluetooth_stealth"] = False
|
||||
prelude = """
|
||||
<script>
|
||||
(function(){
|
||||
var status=%s,config=%s;
|
||||
function response(value){
|
||||
return {ok:true,status:200,json:function(){return Promise.resolve(value)}};
|
||||
}
|
||||
window.fetch=function(path){
|
||||
if(path==="/api/status")return Promise.resolve(response(status));
|
||||
if(path==="/api/config")return Promise.resolve(response(config));
|
||||
return Promise.resolve({ok:false,status:404,json:function(){return Promise.resolve({})}});
|
||||
};
|
||||
window.addEventListener("load",function(){
|
||||
setTimeout(function(){
|
||||
var flag=document.querySelector('#v-app [data-k="bluetooth.stealth"]');
|
||||
var mac=document.querySelector('#v-app [data-k="bluetooth.mac"]');
|
||||
var body=document.body;
|
||||
body.setAttribute("data-test-initial-flag",flag.value);
|
||||
flag.value="on";
|
||||
flag.dispatchEvent(new Event("input",{bubbles:true}));
|
||||
flag.dispatchEvent(new Event("change",{bubbles:true}));
|
||||
body.setAttribute("data-test-dirty-flag",st.dirty["bluetooth.stealth"]||"");
|
||||
body.setAttribute("data-test-dirty-keys",Object.keys(st.dirty).join(","));
|
||||
body.setAttribute("data-test-mac",mac.value);
|
||||
body.setAttribute("data-test-config-mac",cfgVal("bluetooth.mac"));
|
||||
flag.value="off";
|
||||
flag.dispatchEvent(new Event("input",{bubbles:true}));
|
||||
flag.dispatchEvent(new Event("change",{bubbles:true}));
|
||||
body.setAttribute("data-test-restored-dirty-count",Object.keys(st.dirty).length);
|
||||
},500);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
""" % (json.dumps(status), json.dumps(config))
|
||||
|
||||
dom = self.run_page(prelude)
|
||||
self.assertIn('data-test-initial-flag="off"', dom)
|
||||
self.assertIn('data-test-dirty-flag="on"', dom)
|
||||
self.assertIn('data-test-dirty-keys="bluetooth.stealth"', dom)
|
||||
self.assertIn('data-test-mac="C2:11:22:33:44:55"', dom)
|
||||
self.assertIn('data-test-config-mac="C2:11:22:33:44:55"', dom)
|
||||
self.assertIn('data-test-restored-dirty-count="0"', dom)
|
||||
|
||||
def test_second_load_auto_password_clear_remains_restorable(self):
|
||||
status, config = self.setup_values()
|
||||
prelude = """
|
||||
|
||||
Reference in new issue
Block a user