# Copyright 2021, 2024 Dom Sekotill # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ Test connecting and communicating with a server """ import os import sys import unittest from tests.integration.util import start_server from wpa_supplicant.client import GlobalClient class Tests(unittest.IsolatedAsyncioTestCase): """ Tests against live wpa_suppplicant servers The 'wpa_supplicant' executable is required in a PATH directory for these tests to work. """ async def test_connect(self) -> None: """ Test connecting to the global wpa_supplicant control socket """ async with start_server() as sock, GlobalClient() as client: await client.connect(sock) ifaces = await client.list_interfaces() assert len(ifaces) == 0 async def test_new_interface(self) -> None: """ Test adding a wireless interface and scanning for stations This test requires root privileges """ if os.getuid() != 0: self.skipTest("test_new_interface requires root privileges") async with start_server() as sock, GlobalClient() as mclient: await mclient.connect(sock) async with await mclient.connect_interface('wlan0') as iclient: async for iface in iclient.scan(): sys.stdout.write( "{id:>2}: {bssid} {freq} {noise}/{level} {ssid:32} {flags}\n" .format(**iface), )