Пример #1
0
class TestRequestFileParserWithFileNameAndValidStreamAndBody(Teardown):

    temporary_request_file = "temporary_request_file"
    valid_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"2d2d2d2d2d2d5765624b69")

    @pytest.fixture(autouse=True)
    def setup(self):
        with open(self.temporary_request_file, "w") as f:
            f.write(self.valid_request_stream)

        self.request_file_parser = RequestFileParser(
            self.temporary_request_file)

    def test_run(self):
        self.request_file_parser.run()

        start_line = ["POST", "/login", "HTTP/1.1"]
        headers = {
            "host": "8.8.8.8",
            "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 = "/login"
        version = "HTTP/1.1"
        body = "2d2d2d2d2d2d5765624b69".decode("hex")

        assert getattr(self.request_file_parser, "start_line") == start_line
        assert getattr(self.request_file_parser, "headers") == headers
        assert getattr(self.request_file_parser, "method") == method
        assert getattr(self.request_file_parser, "uri") == uri
        assert getattr(self.request_file_parser, "version") == version
        assert getattr(self.request_file_parser, "body") == body
        assert getattr(self.request_file_parser, "stream") == ""

        Teardown.remove_temp_file(self, self.temporary_request_file)
Пример #2
0
class TestRequestFileParserWithoutFileName(object):
    @pytest.fixture(autouse=True)
    def setup(self):
        self.request_file_parser = RequestFileParser("")

    def test_run(self):
        self.request_file_parser.run()

        assert getattr(self.request_file_parser, "start_line") == []
        assert getattr(self.request_file_parser, "headers") == {}
        assert getattr(self.request_file_parser, "method") == ""
        assert getattr(self.request_file_parser, "uri") == ""
        assert getattr(self.request_file_parser, "version") == ""
        assert getattr(self.request_file_parser, "body") == ""
        assert getattr(self.request_file_parser, "stream") == ""
        assert getattr(self.request_file_parser, "file_name") == ""
Пример #3
0
    def setup(self):
        with open(self.temporary_request_file, "w") as f:
            f.write(self.valid_request_stream)

        self.request_file_parser = RequestFileParser(
            self.temporary_request_file)
Пример #4
0
 def setup(self):
     self.request_file_parser = RequestFileParser("")