Made the key be UUID4 instead of a UUID1.

This commit is contained in:
Dariusz Suchojad
2012-02-27 12:10:49 +01:00
parent 06b8f6bfcc
commit 72f03935b3
2 changed files with 11 additions and 2 deletions

View File

@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
#
import unittest
# stdlib
import base64, unittest, uuid
# websocket-client
import websocket as ws
TRACABLE=False
@@ -213,6 +216,12 @@ class WebSocketTest(unittest.TestCase):
self.assertRaises(error, s.send, "Hello")
self.assertRaises(error, s.recv)
def testUUID4(self):
""" WebSocket key should be a UUID4.
"""
key = ws._create_sec_websocket_key()
u = uuid.UUID(bytes=base64.b64decode(key))
self.assertEquals(4, u.version)
if __name__ == "__main__":

View File

@@ -166,7 +166,7 @@ _MAX_CHAR_BYTE = (1<<8) -1
# http://axod.blogspot.com/2010/06/websocket-gets-update-and-it-breaks.html
def _create_sec_websocket_key():
uid = uuid.uuid1()
uid = uuid.uuid4()
return base64.encodestring(uid.bytes).strip()
_HEADERS_TO_CHECK = {