| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 import urllib2 | 3 import urllib2 |
| 4 import sys | 4 import sys |
| 5 import threading | 5 import threading |
| 6 from urlparse import urljoin | 6 from urlparse import urljoin |
| 7 from xml.dom import minidom | 7 from xml.dom import minidom |
| 8 | 8 |
| 9 UPDATE_BLOB="""\ | 9 UPDATE_BLOB="""\ |
| 10 <?xml version="1.0" encoding="UTF-8"?> | 10 <?xml version="1.0" encoding="UTF-8"?> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 print data | 73 print data |
| 74 root = update_dom.firstChild | 74 root = update_dom.firstChild |
| 75 update_info = root.getElementsByTagName('updatecheck')[0] | 75 update_info = root.getElementsByTagName('updatecheck')[0] |
| 76 update_url = update_info.getAttribute('codebase') | 76 update_url = update_info.getAttribute('codebase') |
| 77 hash = update_info.getAttribute('hash') | 77 hash = update_info.getAttribute('hash') |
| 78 head_request = urllib2.Request(update_url) | 78 head_request = urllib2.Request(update_url) |
| 79 head_request.get_method = lambda: 'HEAD' | 79 head_request.get_method = lambda: 'HEAD' |
| 80 try: | 80 try: |
| 81 fd = urllib2.urlopen(head_request) | 81 fd = urllib2.urlopen(head_request) |
| 82 except urllib2.HTTPError, e: | 82 except urllib2.HTTPError, e: |
| 83 # HTTP error |
| 83 print 'FAILED: unable to retrieve %s\n\t%s' % (update_url, e) | 84 print 'FAILED: unable to retrieve %s\n\t%s' % (update_url, e) |
| 84 return False | 85 length = 0 |
| 85 length = int(fd.headers.getheaders('Content-Length')[0]) | 86 else: |
| 86 assert length > 0 | 87 # HTTP succeeded |
| 87 print 'Got a valid update response.' | 88 length = int(fd.headers.getheaders('Content-Length')[0]) |
| 88 fd.close() | 89 finally: |
| 89 assert (urllib2.urlopen(urljoin(update_url, 'cksum')).read() == hash) | 90 fd.close() |
| 90 print 'Update cksum matched the one in the update XML.' | 91 return (length > 0) |
| 91 return _verify_download(update_url, length) | |
| 92 | 92 |
| 93 def test(num_clients): | 93 def test(num_clients): |
| 94 # Fake some concurrent requests for each autoupdate operation. | 94 # Fake some concurrent requests for each autoupdate operation. |
| 95 for clients in range(num_clients): | 95 for clients in range(num_clients): |
| 96 for op in (do_version_ping, do_badversion_ping): | 96 for op in (do_version_ping, do_badversion_ping): |
| 97 t = threading.Thread(target=op) | 97 t = threading.Thread(target=op) |
| 98 t.start() | 98 t.start() |
| 99 | 99 |
| 100 if __name__ == '__main__': | 100 if __name__ == '__main__': |
| 101 if len(sys.argv) > 1: | 101 if len(sys.argv) > 1: |
| 102 num_clients = int(sys.argv[1]) | 102 num_clients = int(sys.argv[1]) |
| 103 else: | 103 else: |
| 104 num_clients = 1 | 104 num_clients = 1 |
| 105 test(num_clients) | 105 test(num_clients) |
| OLD | NEW |