diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index 2edbdb421..9ac7c9c53 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -193,6 +193,15 @@ class Hostapd: vals[name] = value return vals + def get_mib(self): + res = self.request("MIB") + lines = res.splitlines() + vals = dict() + for l in lines: + [name,value] = l.split('=', 1) + vals[name] = value + return vals + def add_ap(ifname, params, wait_enabled=True): logger.info("Starting AP " + ifname) hapd_global = HostapdGlobal() @@ -204,7 +213,8 @@ def add_ap(ifname, params, wait_enabled=True): hapd.set_defaults() fields = [ "ssid", "wpa_passphrase", "nas_identifier", "wpa_key_mgmt", "wpa", - "wpa_pairwise", "rsn_pairwise", "auth_server_addr" ] + "wpa_pairwise", "rsn_pairwise", "auth_server_addr", + "acct_server_addr" ] for field in fields: if field in params: hapd.set(field, params[field]) diff --git a/tests/hwsim/test_radius.py b/tests/hwsim/test_radius.py new file mode 100644 index 000000000..0818270c2 --- /dev/null +++ b/tests/hwsim/test_radius.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# +# RADIUS tests +# Copyright (c) 2013, Jouni Malinen +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. + +import logging +logger = logging.getLogger() +import time + +import hostapd + +def connect(dev, ssid, wait_connect=True): + dev.connect(ssid, key_mgmt="WPA-EAP", scan_freq="2412", + eap="PSK", identity="psk.user@example.com", + password_hex="0123456789abcdef0123456789abcdef", + wait_connect=wait_connect) + +def test_radius_auth_unreachable(dev, apdev): + """RADIUS Authentication server unreachable""" + params = hostapd.wpa2_eap_params(ssid="radius-auth") + params['auth_server_port'] = "18139" + hostapd.add_ap(apdev[0]['ifname'], params) + hapd = hostapd.Hostapd(apdev[0]['ifname']) + connect(dev[0], "radius-auth", wait_connect=False) + ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"]) + if ev is None: + raise Exception("Timeout on EAP start") + logger.info("Checking for RADIUS retries") + time.sleep(4) + mib = hapd.get_mib() + if "radiusAuthClientAccessRequests" not in mib: + raise Exception("Missing MIB fields") + if int(mib["radiusAuthClientAccessRetransmissions"]) < 1: + raise Exception("Missing RADIUS Authentication retransmission") + if int(mib["radiusAuthClientPendingRequests"]) < 1: + raise Exception("Missing pending RADIUS Authentication request") + +def test_radius_acct_unreachable(dev, apdev): + """RADIUS Accounting server unreachable""" + params = hostapd.wpa2_eap_params(ssid="radius-acct") + params['acct_server_addr'] = "127.0.0.1" + params['acct_server_port'] = "18139" + params['acct_server_shared_secret'] = "radius" + hostapd.add_ap(apdev[0]['ifname'], params) + hapd = hostapd.Hostapd(apdev[0]['ifname']) + connect(dev[0], "radius-acct") + logger.info("Checking for RADIUS retries") + time.sleep(4) + mib = hapd.get_mib() + if "radiusAccClientRetransmissions" not in mib: + raise Exception("Missing MIB fields") + if int(mib["radiusAccClientRetransmissions"]) < 2: + raise Exception("Missing RADIUS Accounting retransmissions") + if int(mib["radiusAccClientPendingRequests"]) < 2: + raise Exception("Missing pending RADIUS Accounting requests")