test_radius.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/python
  2. #
  3. # RADIUS tests
  4. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import logging
  9. logger = logging.getLogger()
  10. import time
  11. import hostapd
  12. def connect(dev, ssid, wait_connect=True):
  13. dev.connect(ssid, key_mgmt="WPA-EAP", scan_freq="2412",
  14. eap="PSK", identity="psk.user@example.com",
  15. password_hex="0123456789abcdef0123456789abcdef",
  16. wait_connect=wait_connect)
  17. def test_radius_auth_unreachable(dev, apdev):
  18. """RADIUS Authentication server unreachable"""
  19. params = hostapd.wpa2_eap_params(ssid="radius-auth")
  20. params['auth_server_port'] = "18139"
  21. hostapd.add_ap(apdev[0]['ifname'], params)
  22. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  23. connect(dev[0], "radius-auth", wait_connect=False)
  24. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"])
  25. if ev is None:
  26. raise Exception("Timeout on EAP start")
  27. logger.info("Checking for RADIUS retries")
  28. time.sleep(4)
  29. mib = hapd.get_mib()
  30. if "radiusAuthClientAccessRequests" not in mib:
  31. raise Exception("Missing MIB fields")
  32. if int(mib["radiusAuthClientAccessRetransmissions"]) < 1:
  33. raise Exception("Missing RADIUS Authentication retransmission")
  34. if int(mib["radiusAuthClientPendingRequests"]) < 1:
  35. raise Exception("Missing pending RADIUS Authentication request")
  36. def test_radius_acct_unreachable(dev, apdev):
  37. """RADIUS Accounting server unreachable"""
  38. params = hostapd.wpa2_eap_params(ssid="radius-acct")
  39. params['acct_server_addr'] = "127.0.0.1"
  40. params['acct_server_port'] = "18139"
  41. params['acct_server_shared_secret'] = "radius"
  42. hostapd.add_ap(apdev[0]['ifname'], params)
  43. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  44. connect(dev[0], "radius-acct")
  45. logger.info("Checking for RADIUS retries")
  46. time.sleep(4)
  47. mib = hapd.get_mib()
  48. if "radiusAccClientRetransmissions" not in mib:
  49. raise Exception("Missing MIB fields")
  50. if int(mib["radiusAccClientRetransmissions"]) < 2:
  51. raise Exception("Missing RADIUS Accounting retransmissions")
  52. if int(mib["radiusAccClientPendingRequests"]) < 2:
  53. raise Exception("Missing pending RADIUS Accounting requests")