1 import ./make-test-python.nix ({ pkgs, lib, ...}:
3 name = "wpa_supplicant";
4 meta = with lib.maintainers; {
5 maintainers = [ rnhmjoj ];
8 nodes.machine = { ... }: {
9 imports = [ ../modules/profiles/minimal.nix ];
11 # add a virtual wlan interface
12 boot.kernelModules = [ "mac80211_hwsim" ];
14 # wireless access point
20 wpaPassphrase = "reproducibility";
24 networking.wireless = {
25 # the override is needed because the wifi is
26 # disabled with mkVMOverride in qemu-vm.nix.
27 enable = lib.mkOverride 0 true;
28 userControlled.enable = true;
29 interfaces = [ "wlan1" ];
30 fallbackToWPA2 = true;
36 authProtocols = [ "WPA-PSK" "SAE" ];
40 authProtocols = [ "SAE" ];
44 nixos-test.psk = "@PSK_NIXOS_TEST@";
46 # secrets substitution test cases
47 test1.psk = "@PSK_VALID@"; # should be replaced
48 test2.psk = "@PSK_SPECIAL@"; # should be replaced
49 test3.psk = "@PSK_MISSING@"; # should not be replaced
50 test4.psk = "P@ssowrdWithSome@tSymbol"; # should not be replaced
54 environmentFile = pkgs.writeText "wpa-secrets" ''
55 PSK_NIXOS_TEST="reproducibility"
56 PSK_VALID="S0m3BadP4ssw0rd";
57 # taken from https://github.com/minimaxir/big-list-of-naughty-strings
58 PSK_SPECIAL=",./;'[]\-= <>?:\"{}|_+ !@#$%^\&*()`~";
66 config_file = "/run/wpa_supplicant/wpa_supplicant.conf"
68 with subtest("Configuration file is inaccessible to other users"):
69 machine.wait_for_file(config_file)
70 machine.fail(f"sudo -u nobody ls {config_file}")
72 with subtest("Secrets variables have been substituted"):
73 machine.fail(f"grep -q @PSK_VALID@ {config_file}")
74 machine.fail(f"grep -q @PSK_SPECIAL@ {config_file}")
75 machine.succeed(f"grep -q @PSK_MISSING@ {config_file}")
76 machine.succeed(f"grep -q P@ssowrdWithSome@tSymbol {config_file}")
78 with subtest("WPA2 fallbacks have been generated"):
79 assert int(machine.succeed(f"grep -c sae-only {config_file}")) == 1
80 assert int(machine.succeed(f"grep -c mixed-wpa {config_file}")) == 2
82 # save file for manual inspection
83 machine.copy_from_vm(config_file)
85 with subtest("Daemon is running and accepting connections"):
86 machine.wait_for_unit("wpa_supplicant-wlan1.service")
87 status = machine.succeed("wpa_cli -i wlan1 status")
88 assert "Failed to connect" not in status, \
89 "Failed to connect to the daemon"
91 with subtest("Daemon can connect to the access point"):
92 machine.wait_until_succeeds(
93 "wpa_cli -i wlan1 status | grep -q wpa_state=COMPLETED"