diff --git a/tests/001-test-parser.py b/tests/001-test-parser.py new file mode 100644 index 00000000..a690d256 --- /dev/null +++ b/tests/001-test-parser.py @@ -0,0 +1,165 @@ +import t + +@t.request("001.http") +def test_001(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + + t.eq(p.method, "PUT") + t.eq(p.version, (1,0)) + t.eq(p.path, "/stuff/here") + t.eq(p.query_string, "foo=bar") + t.eq(sorted(p.headers), [ + ('Content-Length', '14'), + ('Content-Type', 'application/json'), + ('Server', 'http://127.0.0.1:5984') + ]) + body, tr = p.filter_body(buf[i:]) + t.eq(body, '{"nom": "nom"}') + +@t.request("002.http") +def test_002(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + + t.eq(p.method, "GET") + t.eq(p.version, (1, 1)) + t.eq(p.path, "/test") + t.eq(p.query_string, "") + t.eq(sorted(p.headers), [ + ("Accept", "*/*"), + ("Host", "0.0.0.0=5000"), + ("User-Agent", "curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1") + ]) + body, tr = p.filter_body(buf[i:]) + t.eq(body, "") + +@t.request("003.http") +def test_003(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + t.eq(p.method, "GET") + t.eq(p.version, (1, 1)) + t.eq(p.path, "/favicon.ico") + t.eq(p.query_string, "") + t.eq(sorted(p.headers), [ + ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), + ("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"), + ("Accept-Encoding", "gzip,deflate"), + ("Accept-Language", "en-us,en;q=0.5"), + ("Connection", "keep-alive"), + ("Host", "0.0.0.0=5000"), + ("Keep-Alive", "300"), + ("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0"), + ]) + body, tr = p.filter_body(buf[i:]) + t.eq(body, "") + +@t.request("004.http") +def test_004(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + t.eq(p.method, "GET") + t.eq(p.version, (1, 1)) + t.eq(p.path, "/dumbfuck") + t.eq(p.query_string, "") + t.eq(p.headers, [("Aaaaaaaaaaaaa", "++++++++++")]) + body, tr = p.filter_body(buf[i:]) + t.eq(body, "") + + +@t.request("005.http") +def test_005(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + t.eq(p.method, "GET") + t.eq(p.version, (1, 1)) + t.eq(p.path, "/forums/1/topics/2375") + t.eq(p.query_string, "page=1") + + + t.eq(p.fragment, "posts-17408") + body, tr = p.filter_body(buf[i:]) + t.eq(body, "") + +@t.request("006.http") +def test_006(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + t.eq(p.method, "GET") + t.eq(p.version, (1, 1)) + t.eq(p.path, "/get_no_headers_no_body/world") + t.eq(p.query_string, "") + t.eq(p.fragment, "") + body, tr = p.filter_body(buf[i:]) + t.eq(body, "") + +@t.request("007.http") +def test_007(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + t.eq(p.method, "GET") + t.eq(p.version, (1, 1)) + t.eq(p.path, "/get_one_header_no_body") + t.eq(p.query_string, "") + t.eq(p.fragment, "") + t.eq(p.headers, [('Accept', '*/*')]) + body, tr = p.filter_body(buf[i:]) + t.eq(body, "") + +@t.request("008.http") +def test_008(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + t.eq(p.method, "GET") + t.eq(p.version, (1, 0)) + t.eq(p.path, "/get_funky_content_length_body_hello") + t.eq(p.query_string, "") + t.eq(p.fragment, "") + t.eq(p.headers, [('Content-Length', '5')]) + body, tr = p.filter_body(buf[i:]) + t.eq(body, "HELLO") + +@t.request("009.http") +def test_009(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + t.eq(p.method, "POST") + t.eq(p.version, (1, 1)) + t.eq(p.path, "/post_identity_body_world") + t.eq(p.query_string, "q=search") + t.eq(p.fragment, "hey") + t.eq(sorted(p.headers), [ + ('Accept', '*/*'), + ('Content-Length', '5'), + ('Transfer-Encoding', 'identity') + ]) + body, tr = p.filter_body(buf[i:]) + t.eq(body, "World") + +@t.request("010.http") +def test_010(buf, p): + headers = [] + i = p.filter_headers(headers, buf) + t.ne(i, -1) + t.eq(p.method, "POST") + t.eq(p.version, (1, 1)) + t.eq(p.path, "/post_chunked_all_your_base") + t.eq(p.headers, [('Transfer-Encoding', 'chunked')]) + t.eq(p.is_chunked, True) + body = "" + buf = buf[i:] + print buf + while not p.body_eof(): + chunk, buf = p.filter_body(buf) + body += chunk + t.eq(body, "all your base are belong to us") diff --git a/tests/requests/001.http b/tests/requests/001.http new file mode 100644 index 00000000..4ad7ed9d --- /dev/null +++ b/tests/requests/001.http @@ -0,0 +1,6 @@ +PUT /stuff/here?foo=bar HTTP/1.0 +Server: http://127.0.0.1:5984 +Content-Type: application/json +Content-Length: 14 + +{"nom": "nom"} \ No newline at end of file diff --git a/tests/requests/002.http b/tests/requests/002.http new file mode 100644 index 00000000..4dac660e --- /dev/null +++ b/tests/requests/002.http @@ -0,0 +1,5 @@ +GET /test HTTP/1.1 +User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1 +Host: 0.0.0.0=5000 +Accept: */* + diff --git a/tests/requests/003.http b/tests/requests/003.http new file mode 100644 index 00000000..583f1a26 --- /dev/null +++ b/tests/requests/003.http @@ -0,0 +1,10 @@ +GET /favicon.ico HTTP/1.1 +Host: 0.0.0.0=5000 +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0 +Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 +Accept-Language: en-us,en;q=0.5 +Accept-Encoding: gzip,deflate +Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 +Keep-Alive: 300 +Connection: keep-alive + diff --git a/tests/requests/004.http b/tests/requests/004.http new file mode 100644 index 00000000..a1f5c2fc --- /dev/null +++ b/tests/requests/004.http @@ -0,0 +1,3 @@ +GET /dumbfuck HTTP/1.1 +aaaaaaaaaaaaa:++++++++++ + diff --git a/tests/requests/005.http b/tests/requests/005.http new file mode 100644 index 00000000..4907a20c --- /dev/null +++ b/tests/requests/005.http @@ -0,0 +1,2 @@ +GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1 + diff --git a/tests/requests/006.http b/tests/requests/006.http new file mode 100644 index 00000000..78c7b3a2 --- /dev/null +++ b/tests/requests/006.http @@ -0,0 +1,2 @@ +GET /get_no_headers_no_body/world HTTP/1.1 + diff --git a/tests/requests/007.http b/tests/requests/007.http new file mode 100644 index 00000000..0e450f2d --- /dev/null +++ b/tests/requests/007.http @@ -0,0 +1,3 @@ +GET /get_one_header_no_body HTTP/1.1 +Accept: */* + diff --git a/tests/requests/008.http b/tests/requests/008.http new file mode 100644 index 00000000..86f42b7e --- /dev/null +++ b/tests/requests/008.http @@ -0,0 +1,4 @@ +GET /get_funky_content_length_body_hello HTTP/1.0 +conTENT-Length: 5 + +HELLO \ No newline at end of file diff --git a/tests/requests/009.http b/tests/requests/009.http new file mode 100644 index 00000000..7cebe7f1 --- /dev/null +++ b/tests/requests/009.http @@ -0,0 +1,6 @@ +POST /post_identity_body_world?q=search#hey HTTP/1.1 +Accept: */* +Transfer-Encoding: identity +Content-Length: 5 + +World \ No newline at end of file diff --git a/tests/requests/010.http b/tests/requests/010.http new file mode 100644 index 00000000..c619c8f1 --- /dev/null +++ b/tests/requests/010.http @@ -0,0 +1,6 @@ +POST /post_chunked_all_your_base HTTP/1.1 +Transfer-Encoding: chunked + +1e +all your base are belong to us +0 diff --git a/tests/requests/011.http b/tests/requests/011.http new file mode 100644 index 00000000..09cac99c --- /dev/null +++ b/tests/requests/011.http @@ -0,0 +1,8 @@ +POST /two_chunks_mult_zero_end HTTP/1.1 +Transfer-Encoding: chunked + +5 +hello +6 + world +000 diff --git a/tests/requests/012.http b/tests/requests/012.http new file mode 100644 index 00000000..60570af7 --- /dev/null +++ b/tests/requests/012.http @@ -0,0 +1,10 @@ +POST /chunked_w_trailing_headers HTTP/1.1 +Transfer-Encoding: chunked + +5 +hello +6 + world +0 +Vary: * +Content-Type: text/plain diff --git a/tests/requests/013.http b/tests/requests/013.http new file mode 100644 index 00000000..3d035cd7 --- /dev/null +++ b/tests/requests/013.http @@ -0,0 +1,8 @@ +POST /chunked_w_bullshit_after_length HTTP/1.1 +Transfer-Encoding: chunked + +5; some; parameters=stuff +hello +6; blahblah; blah + world +0 diff --git a/tests/requests/014.http b/tests/requests/014.http new file mode 100644 index 00000000..beb09ee5 --- /dev/null +++ b/tests/requests/014.http @@ -0,0 +1,2 @@ +GET /with_"stupid"_quotes?foo="bar" HTTP/1.1 + diff --git a/tests/requests/015.http b/tests/requests/015.http new file mode 100644 index 00000000..6baf0951 --- /dev/null +++ b/tests/requests/015.http @@ -0,0 +1,5 @@ +GET /test HTTP/1.0 +Host: 0.0.0.0:5000 +User-Agent: ApacheBench/2.3 +Accept: */* + diff --git a/tests/requests/016.http b/tests/requests/016.http new file mode 100644 index 00000000..a37dd1cd --- /dev/null +++ b/tests/requests/016.http @@ -0,0 +1,33 @@ +GET / HTTP/1.1 +X-SSL-Bullshit: -----BEGIN CERTIFICATE----- + MIIFbTCCBFWgAwIBAgICH4cwDQYJKoZIhvcNAQEFBQAwcDELMAkGA1UEBhMCVUsx + ETAPBgNVBAoTCGVTY2llbmNlMRIwEAYDVQQLEwlBdXRob3JpdHkxCzAJBgNVBAMT + AkNBMS0wKwYJKoZIhvcNAQkBFh5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMu + dWswHhcNMDYwNzI3MTQxMzI4WhcNMDcwNzI3MTQxMzI4WjBbMQswCQYDVQQGEwJV + SzERMA8GA1UEChMIZVNjaWVuY2UxEzARBgNVBAsTCk1hbmNoZXN0ZXIxCzA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9jYS5ncmlkLXN1cHBvcnQuYWMudWsvcHViL2NybC9jYWNybC + 5jcmwwPwYDVR0fBDgwNjA0oDKgMIYuaHR0cDovL2NhLmdyaWQt5hYy51ay9wdWIv + Y3JsL2NhY3JsLmNybDANBgkqhkiG9w0BAQUFAAOCAQEAS/U4iiooBENGW/Hwmmd3 + XCy6Zrt08YjKCzGNjorT98g8uGsqYjSxv/hmi0qlnlHs+k/3Iobc3LjS5AMYr5L8 + UO7OSkgFFlLHQyC9JzPfmLCAugvzEbyv4Olnsr8hbxF1MbKZoQxUZtMVu29wjfXk + hTeApBv7eaKCWpSp7MCbvgzm74izKhu3vlDk9w6qVrxePfGgpKPqfHiOoGhFnbTK + wTC6o2xq5y0qZ03JonF7OJspEd3I5zKY3E+ov7/ZhW6DqT8UFvsAdjvQbXyhV8Eu + Yhixw1aKEPzNjNowuIseVogKOLXxWI5vAi5HgXdS0/ES5gDGsABo4fqovUKlgop3 + RA== + -----END CERTIFICATE----- diff --git a/tests/responses/001.http b/tests/responses/001.http new file mode 100644 index 00000000..8a68daad --- /dev/null +++ b/tests/responses/001.http @@ -0,0 +1,15 @@ +HTTP/1.1 301 Moved Permanently +Location: http://www.google.com/ +Content-Type: text/html; charset=UTF-8 +Date: Sun, 26 Apr 2009 11:11:49 GMT +Expires: Tue, 26 May 2009 11:11:49 GMT +Cache-Control: public, max-age=2592000 +Server: gws +Content-Length: 219 + +
+