Skip to content
test_clients.py 1.81 KiB
Newer Older
Dom Sekotill's avatar
Dom Sekotill committed
#  Copyright 2021, 2024  Dom Sekotill <dom.sekotill@kodo.org.uk>
Dom Sekotill's avatar
Dom Sekotill committed
#
#  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
Dom Sekotill's avatar
Dom Sekotill committed
import unittest
Dom Sekotill's avatar
Dom Sekotill committed

from tests.integration.util import start_server
from wpa_supplicant.client import GlobalClient
Dom Sekotill's avatar
Dom Sekotill committed
class Tests(unittest.IsolatedAsyncioTestCase):
Dom Sekotill's avatar
Dom Sekotill committed
	"""
	Tests against live wpa_suppplicant servers

	The 'wpa_supplicant' executable is required in a PATH directory for these tests to work.
	"""

Dom Sekotill's avatar
Dom Sekotill committed
	async def test_connect(self) -> None:
Dom Sekotill's avatar
Dom Sekotill committed
		"""
		Test connecting to the global wpa_supplicant control socket
		"""
		async with start_server() as sock, GlobalClient() as client:
Dom Sekotill's avatar
Dom Sekotill committed
			await client.connect(sock)
			ifaces = await client.list_interfaces()
			assert len(ifaces) == 0

Dom Sekotill's avatar
Dom Sekotill committed
	async def test_new_interface(self) -> None:
Dom Sekotill's avatar
Dom Sekotill committed
		"""
		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:
Dom Sekotill's avatar
Dom Sekotill committed
			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),
					)