Kaynağa Gözat

Ignore querystring

master
Roderic Day 5 yıl önce
ebeveyn
işleme
c38ba323bd
3 değiştirilmiş dosya ile 30 ekleme ve 2 silme
  1. +2
    -1
      makefile
  2. +6
    -1
      pico.py
  3. +22
    -0
      test.py

+ 2
- 1
makefile Dosyayı Görüntüle

@@ -1,4 +1,5 @@
default: test deploy
default: test
make deploy

test: venv/ libs/
venv/bin/python -u test.py

+ 6
- 1
pico.py Dosyayı Görüntüle

@@ -6,6 +6,7 @@ import json
import uuid
from functools import partial
from pathlib import Path
from urllib.parse import urlsplit, urlunsplit

import websockets

@@ -13,6 +14,10 @@ import websockets
rooms = collections.defaultdict(dict)


def ignore_querystring(path):
return urlunsplit(urlsplit(path)[:3] + ('', ''))


class PicoProtocol(websockets.WebSocketServerProtocol):

def serve_file(self, path):
@@ -78,7 +83,7 @@ async def recv_json(websocket):


async def handle(ws, path, server_name):
room = rooms[path]
room = rooms[ignore_querystring(path)]
usernames = room.keys()
sockets = room.values()
username = None

+ 22
- 0
test.py Dosyayı Görüntüle

@@ -173,6 +173,28 @@ def test_private_message():
return _test(client1, client2, client3)


def test_query_is_irrelevant():
client1 = _make_client('ws://localhost:8642/x?a=0', 0.10, Script()
+ {'kind': 'login', 'value': 'Alice'}
- {'kind': 'state', 'username': 'Alice'}
- {'kind': 'state', 'online': ['Alice']}
- {'kind': 'state', 'online': ['Alice', 'Bob']}
+ {'kind': 'post', 'value': 'Hey Bob!'}
- {'kind': 'post', 'value': 'Hey Bob!', 'source': 'Alice'}
- {'kind': 'post', 'value': 'Howdy!', 'source': 'Bob'}
)
client2 = _make_client('ws://localhost:8642/x?v=0', 0.11, Script()
+ {'kind': 'login', 'value': 'Bob'}
- {'kind': 'state', 'username': 'Bob'}
- {'kind': 'state', 'online': ['Alice', 'Bob']}
- {'kind': 'post', 'value': 'Hey Bob!', 'source': 'Alice'}
+ {'kind': 'post', 'value': 'Howdy!'}
- {'kind': 'post', 'value': 'Howdy!', 'source': 'Bob'}
- {'kind': 'state', 'online': ['Bob']}
)
return _test(client1, client2)


if __name__ == '__main__':
loop = asyncio.get_event_loop()
for fn_name, fn in list(locals().items()):

Yükleniyor…
İptal
Kaydet