Files
NeilClack 442565508e fix(network): read AP security flags in WiFi scan and unit-test parseAccessPoint
parseAccessPoint() is extracted from an anonymous namespace so the pure
property->AccessPointInfo mapping is testable. getAccessPoints() now reads
the Flags/WpaFlags/RsnFlags properties (they were never read, so every
network was reported Open and connections lacked a security section) and
fixes the double container-enter on the SSID 'ay' read that silently
emptied the scan list.
2026-08-12 12:00:32 -05:00

69 lines
2.5 KiB
C++

#include "network/nm_device.h"
#include <gtest/gtest.h>
#include <string>
using namespace radiantwave::network;
// parseAccessPoint() maps the raw D-Bus AccessPoint property values into an
// AccessPointInfo. It is the pure half of WifiDevice::getAccessPoints(); the
// sd-bus reads that feed it are Linux-only and covered by live testing.
TEST(ParseAccessPointTest, PassthroughOfProperties) {
AccessPointInfo ap = parseAccessPoint(
"/org/freedesktop/NetworkManager/AccessPoint/1",
"MyWiFi", 72, 0x01, 0x0000, 0x0000);
EXPECT_EQ(ap.object_path, "/org/freedesktop/NetworkManager/AccessPoint/1");
EXPECT_EQ(ap.ssid, "MyWiFi");
EXPECT_EQ(ap.signal_strength, 72);
EXPECT_EQ(ap.flags, 0x01u);
EXPECT_EQ(ap.wpa_flags, 0x0000u);
EXPECT_EQ(ap.rsn_flags, 0x0000u);
}
TEST(ParseAccessPointTest, SsidBytesRoundTrip) {
// The SSID arrives as raw bytes (an `ay` array); it must round-trip back
// into the ssid_bytes field so a connection can be built from it.
std::string ssid = "Café WiFi";
AccessPointInfo ap = parseAccessPoint(
"/org/freedesktop/NetworkManager/AccessPoint/2", ssid, 50, 0, 0, 0);
EXPECT_EQ(std::string(ap.ssid_bytes.begin(), ap.ssid_bytes.end()), ssid);
}
TEST(ParseAccessPointTest, DetectsOpenNetwork) {
AccessPointInfo ap = parseAccessPoint("/x", "OpenNet", 30, 0, 0, 0);
EXPECT_EQ(ap.security, SecurityType::Open);
}
TEST(ParseAccessPointTest, DetectsWepFromPrivacyFlag) {
AccessPointInfo ap = parseAccessPoint("/x", "WepNet", 30, 0x01, 0, 0);
EXPECT_EQ(ap.security, SecurityType::WEP);
}
TEST(ParseAccessPointTest, DetectsWpaFromWpaFlags) {
AccessPointInfo ap = parseAccessPoint("/x", "WpaNet", 30, 0, 0x0001, 0);
EXPECT_EQ(ap.security, SecurityType::WPA);
}
TEST(ParseAccessPointTest, DetectsWpa2FromRsnPsk) {
AccessPointInfo ap = parseAccessPoint("/x", "Wpa2Net", 30, 0, 0, 0x0100);
EXPECT_EQ(ap.security, SecurityType::WPA2);
}
TEST(ParseAccessPointTest, DetectsWpa3FromRsnSae) {
AccessPointInfo ap = parseAccessPoint("/x", "Wpa3Net", 30, 0, 0, 0x0400);
EXPECT_EQ(ap.security, SecurityType::WPA3);
}
TEST(ParseAccessPointTest, Wpa3TakesPrecedenceOverWpa2) {
// SAE (0x0400) must win over PSK (0x0100) when both are advertised.
AccessPointInfo ap = parseAccessPoint("/x", "MixedNet", 30, 0, 0, 0x0500);
EXPECT_EQ(ap.security, SecurityType::WPA3);
}
TEST(ParseAccessPointTest, Wpa2TakesPrecedenceOverWpa) {
AccessPointInfo ap = parseAccessPoint("/x", "MixedNet", 30, 0, 0x0001, 0x0100);
EXPECT_EQ(ap.security, SecurityType::WPA2);
}