31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
import unittest
|
|
|
|
from poc import wire
|
|
|
|
|
|
class WireTest(unittest.TestCase):
|
|
def test_chunked_framing_exact(self):
|
|
blob = wire.frame_chunked("/index.php", b"ABCDEFGH", "127.0.0.1:18110", chunk=4)
|
|
self.assertTrue(blob.startswith(
|
|
b"POST /index.php HTTP/1.1\r\nHost: 127.0.0.1:18110\r\n"
|
|
b"Content-Type: multipart/form-data; boundary=CCCCCCCCCC\r\n"
|
|
b"Transfer-Encoding: chunked\r\nConnection: close\r\n\r\n"))
|
|
self.assertIn(b"4\r\nABCD\r\n4\r\nEFGH\r\n0\r\n\r\n", blob)
|
|
self.assertNotIn(b"Content-Length", blob)
|
|
|
|
def test_plain_framing_has_content_length(self):
|
|
blob = wire.frame_plain("/index.php", b"XY", "127.0.0.1:18110")
|
|
self.assertTrue(blob.endswith(b"\r\n\r\nXY"))
|
|
self.assertIn(b"Content-Length: 2\r\n", blob)
|
|
self.assertNotIn(b"Transfer-Encoding", blob)
|
|
|
|
def test_cookie_extract(self):
|
|
resp = b"HTTP/1.1 200\r\nSet-Cookie: PHPSESSID=a%2Bb\r\n\r\n"
|
|
self.assertEqual(wire.cookie(resp, b"PHPSESSID"), b"a+b")
|
|
|
|
def test_cookie_absent(self):
|
|
self.assertIsNone(wire.cookie(b"HTTP/1.1 200\r\n\r\n", b"PHPSESSID"))
|
|
|
|
def test_status(self):
|
|
self.assertEqual(wire.status(b"HTTP/1.1 500 Internal\r\n\r\n"), "HTTP/1.1 500 Internal")
|