From 476daa0585bed2b87460b062a6e744908c2a769f Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 31 Aug 2015 12:47:38 +0300 Subject: [PATCH] tests: WPS UPnP SetSelectedRegistrar protocol testing Signed-off-by: Jouni Malinen --- tests/hwsim/test_ap_wps.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/hwsim/test_ap_wps.py b/tests/hwsim/test_ap_wps.py index ed4ee79..29c02a4 100644 --- a/tests/hwsim/test_ap_wps.py +++ b/tests/hwsim/test_ap_wps.py @@ -5,6 +5,7 @@ # See README for more details. import base64 +import binascii import os import time import stat @@ -4785,3 +4786,61 @@ def test_ap_wps_config_methods(dev, apdev): "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", "config_methods": "display push_button" } hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) + +def test_ap_wps_set_selected_registrar_proto(dev, apdev): + """WPS UPnP SetSelectedRegistrar protocol testing""" + ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" + hapd = add_ssdp_ap(apdev[0]['ifname'], ap_uuid) + + location = ssdp_get_location(ap_uuid) + urls = upnp_get_urls(location) + eventurl = urlparse.urlparse(urls['event_sub_url']) + ctrlurl = urlparse.urlparse(urls['control_url']) + url = urlparse.urlparse(location) + conn = httplib.HTTPConnection(url.netloc) + + class WPSERHTTPServer(SocketServer.StreamRequestHandler): + def handle(self): + data = self.rfile.readline().strip() + logger.debug(data) + self.wfile.write(gen_wps_event()) + + server = MyTCPServer(("127.0.0.1", 12345), WPSERHTTPServer) + server.timeout = 1 + + headers = { "callback": '', + "NT": "upnp:event", + "timeout": "Second-1234" } + conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) + resp = conn.getresponse() + if resp.status != 200: + raise Exception("Unexpected HTTP response: %d" % resp.status) + sid = resp.getheader("sid") + logger.debug("Subscription SID " + sid) + server.handle_request() + + tests = [ (500, "10"), + (200, "104a000110" + "1041000101" + "101200020000" + + "105300023148" + + "1049002c00372a0001200124111111111111222222222222333333333333444444444444555555555555666666666666" + + "10480010362db47ba53a519188fb5458b986b2e4"), + (200, "104a000110" + "1041000100" + "101200020000" + + "105300020000"), + (200, "104a000110" + "1041000100"), + (200, "104a000110") ] + for status,test in tests: + tlvs = binascii.unhexlify(test) + newmsg = base64.b64encode(tlvs) + msg = '\n' + msg += '' + msg += '' + msg += '' + msg += '' + msg += newmsg + msg += "" + headers = { "Content-type": 'text/xml; charset="utf-8"' } + headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % "SetSelectedRegistrar" + conn.request("POST", ctrlurl.path, msg, headers) + resp = conn.getresponse() + if resp.status != status: + raise Exception("Unexpected HTTP response: %d (expected %d)" % (resp.status, status)) -- 2.1.4