class TestRequestParserWithInValidPostRequestAndValidBody(object): invalid_request_stream = ( b"POST /login HTTP/1.1\r\n" b"Host: 8.8.8.8\r\n" b"Connection: keep-alive\r\n" b"Cache-Control: max-age=0\r\n" b"Content-Lengh: 10\r\n" b"Upgrade-Insecure-Requests: 1\r\n" b"User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36\r\n" b"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n" b"Accept-Encoding: gzip, deflate\r\n" b"Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4\r\n" b"\r\n" b"------WebKit") @pytest.fixture(autouse=True) def setup(self): self.request_parser = RequestParser(self.invalid_request_stream) def test_run(self): self.request_parser.run() start_line = ["post", "/login ", "http/1.1"] headers = { "Host": "8.8.8.9", "connection": "keep-alive", "cache-control": "max-age=0", "content-lengh": "10", "upgrade-insecure-requests": "1", "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "accept-encoding": "gzip, deflate", "accept-language": "ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4" } method = "post" uri = "/" version = "HTTP/1.1 " body = "2d2d2d2d2d2d5765624b69".decode("hex") assert getattr(self.request_parser, "start_line") != start_line assert getattr(self.request_parser, "headers") != headers assert getattr(self.request_parser, "method") != method assert getattr(self.request_parser, "uri") != uri assert getattr(self.request_parser, "version") != version assert getattr(self.request_parser, "body") != body assert getattr(self.request_parser, "stream") == self.invalid_request_stream
class TestRequestParserWithoutRequest(object): @pytest.fixture(autouse=True) def setup(self): self.request_parser = RequestParser() def test_run(self): self.request_parser.run() assert getattr(self.request_parser, "start_line") == [] assert getattr(self.request_parser, "headers") == {} assert getattr(self.request_parser, "method") == "" assert getattr(self.request_parser, "uri") == "" assert getattr(self.request_parser, "version") == "" assert getattr(self.request_parser, "body") == "" assert getattr(self.request_parser, "stream") == ""
class TestRequestParserWithValidGetRequestHttp1_0(object): valid_request_stream = ( b"GET / HTTP/1.0\r\n" b"Host: 8.8.8.8\r\n" b"Connection: keep-alive\r\n" b"Cache-Control: max-age=0\r\n" b"Upgrade-Insecure-Requests: 1\r\n" b"User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36\r\n" b"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n" b"Accept-Encoding: gzip, deflate\r\n" b"Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4\r\n") @pytest.fixture(autouse=True) def setup(self): self.request_parser = RequestParser(self.valid_request_stream) def test_run(self): self.request_parser.run() start_line = ["GET", "/", "HTTP/1.0"] headers = { "host": "8.8.8.8", "connection": "keep-alive", "cache-control": "max-age=0", "upgrade-insecure-requests": "1", "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "accept-encoding": "gzip, deflate", "accept-language": "ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4" } method = "GET" uri = "/" version = "HTTP/1.0" body = "" assert getattr(self.request_parser, "start_line") == start_line assert getattr(self.request_parser, "headers") == headers assert getattr(self.request_parser, "method") == method assert getattr(self.request_parser, "uri") == uri assert getattr(self.request_parser, "version") == version assert getattr(self.request_parser, "body") == body assert getattr(self.request_parser, "stream") == self.valid_request_stream
def setup(self): self.request_parser = RequestParser(self.invalid_request_stream)
def setup(self): self.request_parser = RequestParser()