Test a HTTP -> WebSocket upgrade
(tctx)
| 60 | |
| 61 | |
| 62 | def test_upgrade(tctx): |
| 63 | """Test a HTTP -> WebSocket upgrade""" |
| 64 | tctx.server.address = ("example.com", 80) |
| 65 | tctx.server.state = ConnectionState.OPEN |
| 66 | flow = Placeholder(HTTPFlow) |
| 67 | assert ( |
| 68 | Playbook(http.HttpLayer(tctx, HTTPMode.transparent)) |
| 69 | >> DataReceived( |
| 70 | tctx.client, |
| 71 | b"GET / HTTP/1.1\r\n" |
| 72 | b"Connection: upgrade\r\n" |
| 73 | b"Upgrade: websocket\r\n" |
| 74 | b"Sec-WebSocket-Version: 13\r\n" |
| 75 | b"\r\n", |
| 76 | ) |
| 77 | << http.HttpRequestHeadersHook(flow) |
| 78 | >> reply() |
| 79 | << http.HttpRequestHook(flow) |
| 80 | >> reply() |
| 81 | << SendData( |
| 82 | tctx.server, |
| 83 | b"GET / HTTP/1.1\r\n" |
| 84 | b"Connection: upgrade\r\n" |
| 85 | b"Upgrade: websocket\r\n" |
| 86 | b"Sec-WebSocket-Version: 13\r\n" |
| 87 | b"\r\n", |
| 88 | ) |
| 89 | >> DataReceived( |
| 90 | tctx.server, |
| 91 | b"HTTP/1.1 101 Switching Protocols\r\n" |
| 92 | b"Upgrade: websocket\r\n" |
| 93 | b"Connection: Upgrade\r\n" |
| 94 | b"\r\n", |
| 95 | ) |
| 96 | << http.HttpResponseHeadersHook(flow) |
| 97 | >> reply() |
| 98 | << http.HttpResponseHook(flow) |
| 99 | >> reply() |
| 100 | << SendData( |
| 101 | tctx.client, |
| 102 | b"HTTP/1.1 101 Switching Protocols\r\n" |
| 103 | b"Upgrade: websocket\r\n" |
| 104 | b"Connection: Upgrade\r\n" |
| 105 | b"\r\n", |
| 106 | ) |
| 107 | << websocket.WebsocketStartHook(flow) |
| 108 | >> reply() |
| 109 | >> DataReceived(tctx.client, masked_bytes(b"\x81\x0bhello world")) |
| 110 | << websocket.WebsocketMessageHook(flow) |
| 111 | >> reply() |
| 112 | << SendData(tctx.server, masked(b"\x81\x0bhello world")) |
| 113 | >> DataReceived(tctx.server, b"\x82\nhello back") |
| 114 | << websocket.WebsocketMessageHook(flow) |
| 115 | >> reply() |
| 116 | << SendData(tctx.client, b"\x82\nhello back") |
| 117 | >> DataReceived(tctx.client, masked_bytes(b"\x81\x0bhello again")) |
| 118 | << websocket.WebsocketMessageHook(flow) |
| 119 | >> reply() |
nothing calls this directly
no test coverage detected
searching dependent graphs…