aboutsummaryrefslogtreecommitdiffstats
path: root/test/netlib
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-10-20 11:56:38 +1300
committerAldo Cortesi <aldo@nullcube.com>2016-10-20 11:56:38 +1300
commit8430f857b504a3e7406dc36e54dc32783569d0dd (patch)
treed3116cd540faf01f272a0892fc6a9b83b4f6de8a /test/netlib
parent853e03a5e753354fad3a3fa5384ef3a09384ef43 (diff)
downloadmitmproxy-8430f857b504a3e7406dc36e54dc32783569d0dd.tar.gz
mitmproxy-8430f857b504a3e7406dc36e54dc32783569d0dd.tar.bz2
mitmproxy-8430f857b504a3e7406dc36e54dc32783569d0dd.zip
The final piece: netlib -> mitproxy.net
Diffstat (limited to 'test/netlib')
-rw-r--r--test/netlib/__init__.py0
-rw-r--r--test/netlib/data/clientcert/.gitignore3
-rw-r--r--test/netlib/data/clientcert/client.cnf5
-rw-r--r--test/netlib/data/clientcert/client.pem42
-rw-r--r--test/netlib/data/clientcert/make8
-rw-r--r--test/netlib/data/dercertbin1838 -> 0 bytes
-rw-r--r--test/netlib/data/dhparam.pem13
-rw-r--r--test/netlib/data/htpasswd1
-rw-r--r--test/netlib/data/server.crt14
-rw-r--r--test/netlib/data/server.key15
-rw-r--r--test/netlib/data/text_cert145
-rw-r--r--test/netlib/data/text_cert_239
-rw-r--r--test/netlib/data/text_cert_weird131
-rw-r--r--test/netlib/data/verificationcerts/9da13359.021
-rw-r--r--test/netlib/data/verificationcerts/generate.py66
-rw-r--r--test/netlib/data/verificationcerts/self-signed.crt19
-rw-r--r--test/netlib/data/verificationcerts/self-signed.key27
-rw-r--r--test/netlib/data/verificationcerts/trusted-leaf.crt18
-rw-r--r--test/netlib/data/verificationcerts/trusted-leaf.key27
-rw-r--r--test/netlib/data/verificationcerts/trusted-root.crt21
-rw-r--r--test/netlib/data/verificationcerts/trusted-root.key27
-rw-r--r--test/netlib/data/verificationcerts/trusted-root.srl1
-rw-r--r--test/netlib/http/__init__.py0
-rw-r--r--test/netlib/http/http1/__init__.py0
-rw-r--r--test/netlib/http/http1/test_assemble.py101
-rw-r--r--test/netlib/http/http1/test_read.py371
-rw-r--r--test/netlib/http/http2/__init__.py0
-rw-r--r--test/netlib/http/http2/test_framereader.py1
-rw-r--r--test/netlib/http/test_authentication.py122
-rw-r--r--test/netlib/http/test_cookies.py365
-rw-r--r--test/netlib/http/test_encoding.py73
-rw-r--r--test/netlib/http/test_headers.py106
-rw-r--r--test/netlib/http/test_message.py271
-rw-r--r--test/netlib/http/test_multipart.py24
-rw-r--r--test/netlib/http/test_request.py271
-rw-r--r--test/netlib/http/test_response.py145
-rw-r--r--test/netlib/http/test_status_codes.py6
-rw-r--r--test/netlib/http/test_url.py102
-rw-r--r--test/netlib/http/test_user_agents.py6
-rw-r--r--test/netlib/test_check.py10
-rw-r--r--test/netlib/test_imports.py1
-rw-r--r--test/netlib/test_socks.py189
-rw-r--r--test/netlib/test_tcp.py802
-rw-r--r--test/netlib/test_wsgi.py106
-rw-r--r--test/netlib/tools/getcertnames27
-rw-r--r--test/netlib/tservers.py113
-rw-r--r--test/netlib/websockets/__init__.py0
-rw-r--r--test/netlib/websockets/test_frame.py164
-rw-r--r--test/netlib/websockets/test_masker.py23
-rw-r--r--test/netlib/websockets/test_utils.py105
50 files changed, 0 insertions, 4047 deletions
diff --git a/test/netlib/__init__.py b/test/netlib/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/test/netlib/__init__.py
+++ /dev/null
diff --git a/test/netlib/data/clientcert/.gitignore b/test/netlib/data/clientcert/.gitignore
deleted file mode 100644
index 07bc53d2..00000000
--- a/test/netlib/data/clientcert/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-client.crt
-client.key
-client.req
diff --git a/test/netlib/data/clientcert/client.cnf b/test/netlib/data/clientcert/client.cnf
deleted file mode 100644
index 5046a944..00000000
--- a/test/netlib/data/clientcert/client.cnf
+++ /dev/null
@@ -1,5 +0,0 @@
-[ ssl_client ]
-basicConstraints = CA:FALSE
-nsCertType = client
-keyUsage = digitalSignature, keyEncipherment
-extendedKeyUsage = clientAuth
diff --git a/test/netlib/data/clientcert/client.pem b/test/netlib/data/clientcert/client.pem
deleted file mode 100644
index 4927bca2..00000000
--- a/test/netlib/data/clientcert/client.pem
+++ /dev/null
@@ -1,42 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIEpAIBAAKCAQEAzCpoRjSTfIN24kkNap/GYmP9zVWj0Gk8R5BB/PvvN0OB1Zk0
-EEYPsWCcuhEdK0ehiDZX030doF0DOncKKa6mop/d0x2o+ts42peDhZM6JNUrm6d+
-ZWQVtio33mpp77UMhR093vaA+ExDnmE26kBTVijJ1+fRAVDXG/cmQINEri91Kk/G
-3YJ5e45UrohGI5seBZ4vV0xbHtmczFRhYFlGOvYsoIe4Lvz/eFS2pIrTIpYQ2VM/
-SQQl+JFy+NlQRsWG2NrxtKOzMnnDE7YN4I3z5D5eZFo1EtwZ48LNCeSwrEOdfuzP
-G5q5qbs5KpE/x85H9umuRwSCIArbMwBYV8a8JwIDAQABAoIBAFE3FV/IDltbmHEP
-iky93hbJm+6QgKepFReKpRVTyqb7LaygUvueQyPWQMIriKTsy675nxo8DQr7tQsO
-y3YlSZgra/xNMikIB6e82c7K8DgyrDQw/rCqjZB3Xt4VCqsWJDLXnQMSn98lx0g7
-d7Lbf8soUpKWXqfdVpSDTi4fibSX6kshXyfSTpcz4AdoncEpViUfU1xkEEmZrjT8
-1GcCsDC41xdNmzCpqRuZX7DKSFRoB+0hUzsC1oiqM7FD5kixonRd4F5PbRXImIzt
-6YCsT2okxTA04jX7yByis7LlOLTlkmLtKQYuc3erOFvwx89s4vW+AeFei+GGNitn
-tHfSwbECgYEA7SzV+nN62hAERHlg8cEQT4TxnsWvbronYWcc/ev44eHSPDWL5tPi
-GHfSbW6YAq5Wa0I9jMWfXyhOYEC3MZTC5EEeLOB71qVrTwcy/sY66rOrcgjFI76Q
-5JFHQ4wy3SWU50KxE0oWJO9LIowprG+pW1vzqC3VF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kkNap/GYmP9zVWj0Gk8R5BB/PvvN0OB1Zk0
-EEYPsWCcuhEdK0ehiDZX030doF0DOncKKa6mop/d0x2o+ts42peDhZM6JNUrm6d+
-ZWQVtio33mpp77UMhR093vaA+ExDnmE26kBTVijJ1+fRAVDXG/cmQINEri91Kk/G
-3YJ5e45UrohGI5seBZ4vV0xbHtmczFRhYFlGOvYsoIe4Lvz/eFS2pIrTIpYQ2VM/
-SQQl+JFy+NlQRsWG2NrxtKOzMnnDE7YN4I3z5D5eZFo1EtwZ48LNCeSwrEOdfuzP
-G5q5qbs5KpE/x85H9umuRwSCIArbMwBYV8a8JwIDAQABMA0GCSqGSIb3DQEBBQUA
-A4GBAFvI+cd47B85PQ970n2dU/PlA2/Hb1ldrrXh2guR4hX6vYx/uuk5yRI/n0Rd
-KOXJ3czO0bd2Fpe3ZoNpkW0pOSDej/Q+58ScuJd0gWCT/Sh1eRk6ZdC0kusOuWoY
-bPOPMkG45LPgUMFOnZEsfJP6P5mZIxlbCvSMFC25nPHWlct7
------END CERTIFICATE-----
diff --git a/test/netlib/data/clientcert/make b/test/netlib/data/clientcert/make
deleted file mode 100644
index d1caea81..00000000
--- a/test/netlib/data/clientcert/make
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-openssl genrsa -out client.key 2048
-openssl req -key client.key -new -out client.req
-openssl x509 -req -days 365 -in client.req -signkey client.key -out client.crt -extfile client.cnf -extensions ssl_client
-openssl x509 -req -days 1000 -in client.req -CA ~/.mitmproxy/mitmproxy-ca.pem -CAkey ~/.mitmproxy/mitmproxy-ca.pem -set_serial 00001 -out client.crt -extensions ssl_client
-cat client.key client.crt > client.pem
-openssl x509 -text -noout -in client.pem
diff --git a/test/netlib/data/dercert b/test/netlib/data/dercert
deleted file mode 100644
index 370252af..00000000
--- a/test/netlib/data/dercert
+++ /dev/null
Binary files differ
diff --git a/test/netlib/data/dhparam.pem b/test/netlib/data/dhparam.pem
deleted file mode 100644
index afb41672..00000000
--- a/test/netlib/data/dhparam.pem
+++ /dev/null
@@ -1,13 +0,0 @@
------BEGIN DH PARAMETERS-----
-MIICCAKCAgEAyT6LzpwVFS3gryIo29J5icvgxCnCebcdSe/NHMkD8dKJf8suFCg3
-O2+dguLakSVif/t6dhImxInJk230HmfC8q93hdcg/j8rLGJYDKu3ik6H//BAHKIv
-j5O9yjU3rXCfmVJQic2Nne39sg3CreAepEts2TvYHhVv3TEAzEqCtOuTjgDv0ntJ
-Gwpj+BJBRQGG9NvprX1YGJ7WOFBP/hWU7d6tgvE6Xa7T/u9QIKpYHMIkcN/l3ZFB
-chZEqVlyrcngtSXCROTPcDOQ6Q8QzhaBJS+Z6rcsd7X+haiQqvoFcmaJ08Ks6LQC
-ZIL2EtYJw8V8z7C0igVEBIADZBI6OTbuuhDwRw//zU1uq52Oc48CIZlGxTYG/Evq
-o9EWAXUYVzWkDSTeBH1r4z/qLPE2cnhtMxbFxuvK53jGB0emy2y1Ei6IhKshJ5qX
-IB/aE7SSHyQ3MDHHkCmQJCsOd4Mo26YX61NZ+n501XjqpCBQ2+DfZCBh8Va2wDyv
-A2Ryg9SUz8j0AXViRNMJgJrr446yro/FuJZwnQcO3WQnXeqSBnURqKjmqkeFP+d8
-6mk2tqJaY507lRNqtGlLnj7f5RNoBFJDCLBNurVgfvq9TCVWKDIFD4vZRjCrnl6I
-rD693XKIHUCWOjMh1if6omGXKHH40QuME2gNa50+YPn1iYDl88uDbbMCAQI=
------END DH PARAMETERS-----
diff --git a/test/netlib/data/htpasswd b/test/netlib/data/htpasswd
deleted file mode 100644
index 54c95b8c..00000000
--- a/test/netlib/data/htpasswd
+++ /dev/null
@@ -1 +0,0 @@
-test:$apr1$/LkYxy3x$WI4.YbiJlu537jLGEW2eu1
diff --git a/test/netlib/data/server.crt b/test/netlib/data/server.crt
deleted file mode 100644
index 68f61bac..00000000
--- a/test/netlib/data/server.crt
+++ /dev/null
@@ -1,14 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICOzCCAaQCCQDC7f5GsEpo9jANBgkqhkiG9w0BAQUFADBiMQswCQYDVQQGEwJO
-WjEOMAwGA1UECBMFT3RhZ28xEDAOBgNVBAcTB0R1bmVkaW4xDzANBgNVBAoTBm5l
-dGxpYjEPMA0GA1UECxMGbmV0bGliMQ8wDQYDVQQDEwZuZXRsaWIwHhcNMTIwNjI0
-MjI0MTU0WhcNMjIwNjIyMjI0MTU0WjBiMQswCQYDVQQGEwJOWjEOMAwGA1UECBMF
-T3RhZ28xEDAOBgNVBAcTB0R1bmVkaW4xDzANBgNVBAoTBm5ldGxpYjEPMA0GA1UE
-CxMGbmV0bGliMQ8wDQYDVQQDEwZuZXRsaWIwgZ8wDQYJKoZIhvcNAQEBBQADgY0A
-MIGJAoGBALJSVEl9y3QUSYuXTH0UjBOPQgS0nHmNWej9hjqnA0KWvEnGY+c6yQeP
-/rmwswlKw1iVV5o8kRK9Wej88YWQl/hl/xruyeJgGic0+yqY/FcueZxRudwBcWu2
-7+46aEftwLLRF0GwHZxX/HwWME+TcCXGpXGSG2qs921M4iVeBn5hAgMBAAEwDQYJ
-KoZIhvcNAQEFBQADgYEAODZCihEv2yr8zmmQZDrfqg2ChxAoOXWF5+W2F/0LAUBf
-2bHP+K4XE6BJWmadX1xKngj7SWrhmmTDp1gBAvXURoDaScOkB1iOCOHoIyalscTR
-0FvSHKqFF8fgSlfqS6eYaSbXU3zQolvwP+URzIVnGDqgQCWPtjMqLD3Kd5tuwos=
------END CERTIFICATE-----
diff --git a/test/netlib/data/server.key b/test/netlib/data/server.key
deleted file mode 100644
index b1b658ab..00000000
--- a/test/netlib/data/server.key
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQCyUlRJfct0FEmLl0x9FIwTj0IEtJx5jVno/YY6pwNClrxJxmPn
-OskHj/65sLMJSsNYlVeaPJESvVno/PGFkJf4Zf8a7sniYBonNPsqmPxXLnmcUbnc
-AXFrtu/uOmhH7cCy0RdBsB2cV/x8FjBPk3AlxqVxkhtqrPdtTOIlXgZ+YQIDAQAB
-AoGAQEpGcSiVTYhy64zk2sOprPOdTa0ALSK1I7cjycmk90D5KXAJXLho+f0ETVZT
-dioqO6m8J7NmamcyHznyqcDzyNRqD2hEBDGVRJWmpOjIER/JwWLNNbpeVjsMHV8I
-40P5rZMOhBPYlwECSC5NtMwaN472fyGNNze8u37IZKiER/ECQQDe1iY5AG3CgkP3
-tEZB3Vtzcn4PoOr3Utyn1YER34lPqAmeAsWUhmAVEfR3N1HDe1VFD9s2BidhBn1a
-/Bgqxz4DAkEAzNw0m+uO0WkD7aEYRBW7SbXCX+3xsbVToIWC1jXFG+XDzSWn++c1
-DMXEElzEJxPDA+FzQUvRTml4P92bTAbGywJAS9H7wWtm7Ubbj33UZfbGdhqfz/uF
-109naufXedhgZS0c0JnK1oV+Tc0FLEczV9swIUaK5O/lGDtYDcw3AN84NwJBAIw5
-/1jrOOtm8uVp6+5O4dBmthJsEZEPCZtLSG/Qhoe+EvUN3Zq0fL+tb7USAsKs6ERz
-wizj9PWzhDhTPMYhrVkCQGIponZHx6VqiFyLgYUH9+gDTjBhYyI+6yMTYzcRweyL
-9Suc2NkS3X2Lp+wCjvVZdwGtStp6Vo8z02b3giIsAIY=
------END RSA PRIVATE KEY-----
diff --git a/test/netlib/data/text_cert b/test/netlib/data/text_cert
deleted file mode 100644
index 36ca33b9..00000000
--- a/test/netlib/data/text_cert
+++ /dev/null
@@ -1,145 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIadTCCGd6gAwIBAgIGR09PUAFtMA0GCSqGSIb3DQEBBQUAMEYxCzAJBgNVBAYT
-AlVTMRMwEQYDVQQKEwpHb29nbGUgSW5jMSIwIAYDVQQDExlHb29nbGUgSW50ZXJu
-ZXQgQXV0aG9yaXR5MB4XDTEyMDExNzEyNTUwNFoXDTEzMDExNzEyNTUwNFowTDEL
-MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExEzARBgNVBAoTCkdvb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5zboIJZ29vZ2xlLnNvgglnb29nbGUuc3SCCWdv
-b2dsZS50ZIIJZ29vZ2xlLnRngglnb29nbGUudGuCCWdvb2dsZS50bIIJZ29vZ2xl
-LnRtgglnb29nbGUudG6CCWdvb2dsZS50b4IJZ29vZ2xlLnRwgglnb29nbGUudHSC
-CWdvb2dsZS51c4IJZ29vZ2xlLnV6gglnb29nbGUudmeCCWdvb2dsZS52dYIJZ29v
-Z2xlLndzMA0GCSqGSIb3DQEBBQUAA4GBAJmZ9RyqpUzrP0UcJnHXoLu/AjIEsIvZ
-Y9hq/9bLry8InfmvERYHr4hNetkOYlW0FeDZtCpWxdPUgJjmWgKAK6j0goOFavTV
-GptkL8gha4p1QUsdLkd36/cvBXeBYSle787veo46N1k4V6Uv2gaDVkre786CNsHv
-Q6MYZ5ClQ+kS
------END CERTIFICATE-----
-
diff --git a/test/netlib/data/text_cert_2 b/test/netlib/data/text_cert_2
deleted file mode 100644
index ffe8faae..00000000
--- a/test/netlib/data/text_cert_2
+++ /dev/null
@@ -1,39 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIGujCCBaKgAwIBAgIDAQlEMA0GCSqGSIb3DQEBBQUAMIGMMQswCQYDVQQGEwJJ
-TDEWMBQGA1UEChMNU3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERpZ2l0
-YWwgQ2VydGlmaWNhdGUgU2lnbmluZzE4MDYGA1UEAxMvU3RhcnRDb20gQ2xhc3Mg
-MSBQcmltYXJ5IEludGVybWVkaWF0ZSBTZXJ2ZXIgQ0EwHhcNMTAwMTExMTkyNzM2
-WhcNMTEwMTEyMDkxNDU1WjCBtDEgMB4GA1UEDRMXMTI2ODMyLU1DeExzWTZUbjFn
-bTdvOTAxCzAJBgNVBAYTAk5aMR4wHAYDVQQKExVQZXJzb25hIE5vdCBWYWxpZGF0
-ZWQxKTAnBgNVBAsTIFN0YXJ0Q29tIEZyZWUgQ2VydGlmaWNhdGUgTWVtYmVyMRgw
-FgYDVQQ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cml0eSBQb2xpY3kgYXZhaWxhYmxlIGF0IGh0dHA6Ly93d3cuc3RhcnRz
-c2wuY29tL3BvbGljeS5wZGYwYQYDVR0fBFowWDAqoCigJoYkaHR0cDovL3d3dy5z
-dGFydHNzbC5jb20vY3J0MS1jcmwuY3JsMCqgKKAmhiRodHRwOi8vY3JsLnN0YXJ0
-c3NsLmNvbS9jcnQxLWNybC5jcmwwgY4GCCsGAQUFBwEBBIGBMH8wOQYIKwYBBQUH
-MAGGLWh0dHA6Ly9vY3NwLnN0YXJ0c3NsLmNvbS9zdWIvY2xhc3MxL3NlcnZlci9j
-YTBCBggrBgEFBQcwAoY2aHR0cDovL3d3dy5zdGFydHNzbC5jb20vY2VydHMvc3Vi
-LmNsYXNzMS5zZXJ2ZXIuY2EuY3J0MCMGA1UdEgQcMBqGGGh0dHA6Ly93d3cuc3Rh
-cnRzc2wuY29tLzANBgkqhkiG9w0BAQUFAAOCAQEAivWID0KT8q1EzWzy+BecsFry
-hQhuLFfAsPkHqpNd9OfkRStGBuJlLX+9DQ9TzjqutdY2buNBuDn71buZK+Y5fmjr
-28rAT6+WMd+KnCl5WLT5IOS6Z9s3cec5TFQbmOGlepSS9Q6Ts9KsXOHHQvDkQeDq
-OV2UqdgXIAyFm5efSL9JXPXntRausNu2s8F2B2rRJe4jPfnUy2LvY8OW1YvjUA++
-vpdWRdfUbJQp55mRfaYMPRnyUm30lAI27QaxgQPFOqDeZUm5llb5eFG/B3f87uhg
-+Y1oEykbEvZrIFN4hithioQ0tb+57FKkkG2sW3uemNiQw2qrEo/GAMb1cI50Rg==
------END CERTIFICATE-----
-
diff --git a/test/netlib/data/text_cert_weird1 b/test/netlib/data/text_cert_weird1
deleted file mode 100644
index 72b09dcb..00000000
--- a/test/netlib/data/text_cert_weird1
+++ /dev/null
@@ -1,31 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIFNDCCBBygAwIBAgIEDFJFNzANBgkqhkiG9w0BAQUFADCBjDELMAkGA1UEBhMC
-REU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2EvcHViL2NybC9nX2NhY3JsLmNybDA3oDWgM4YxaHR0cDov
-L2NkcDIucGNhLmRmbi5kZS93d3UtY2EvcHViL2NybC9nX2NhY3JsLmNybDCBlgYI
-KwYBBQUHAQEEgYkwgYYwQQYIKwYBBQUHMAKGNWh0dHA6Ly9jZHAxLnBjYS5kZm4u
-ZGUvd3d1LWNhL3B1Yi9jYWNlcnQvZ19jYWNlcnQuY3J0MEEGCCsGAQUFBzAChjVo
-dHRwOi8vY2RwMi5wY2EuZGZuLmRlL3d3dS1jYS9wdWIvY2FjZXJ0L2dfY2FjZXJ0
-LmNydDANBgkqhkiG9w0BAQUFAAOCAQEAFfNpagtcKUSDKss7TcqjYn99FQ4FtWjE
-pGmzYL2zX2wsdCGoVQlGkieL9slbQVEUAnBuqM1LPzUNNe9kZpOPV3Rdhq4y8vyS
-xkx3G1v5aGxfPUe8KM8yKIOHRqYefNronHJM0fw7KyjQ73xgbIEgkW+kNXaMLcrb
-EPC36O2Zna8GP9FQxJRLgcfQCcYdRKGVn0EtRSkz2ym5Rbh/hrmJBbbC2yJGGMI0
-Vu5A9piK0EZPekZIUmhMQynD9QcMfWhTEFr7YZfx9ktxKDW4spnu7YrgICfZNcCm
-tfxmnEAFt6a47u9P0w9lpY8+Sx9MNFfTePym+HP4TYha9bIBes+XnA==
------END CERTIFICATE-----
-
diff --git a/test/netlib/data/verificationcerts/9da13359.0 b/test/netlib/data/verificationcerts/9da13359.0
deleted file mode 100644
index b22e4d20..00000000
--- a/test/netlib/data/verificationcerts/9da13359.0
+++ /dev/null
@@ -1,21 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDXTCCAkWgAwIBAgIJAPAfPQGCV/Z4MA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
-BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
-aWRnaXRzIFB0eSBMdGQwHhcNMTUxMTAxMTY0ODAxWhcNMTgwODIxMTY0ODAxWjBF
-MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
-ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
-CgKCAQEArp8LD34JhKCwcQbwIYQMg4+eCgLVN8fwB7+/qOfJbArPs0djFBN+F7c6
-HGvMr24BKUk5u8pn4dPtNurm/vPC8ovNGmcXz62BQJpcMX2veVdRsF7yNwhNacNJ
-Arq+70zNMwYBznx0XUxMF6j6nVFf3AW6SU04ylT4Mp3SY/BUUDAdfl1eRo0mPLNS
-8rpsN+8YBw1Q7SCuBRVqpOgVIsL88svgQUSOlzvMZPBpG/cmB3BNKNrltwb5iFEI
-1jAV7uSj5IcIuNO/246kfsDVPTFMJIzav/CUoidd5UNw+SoFDlzh8sA7L1Bm7D1/
-3KHYSKswGsSR3kynAl10w/SJKDtn8wIDAQABo1AwTjAdBgNVHQ4EFgQUgOcrtxBX
-LxbpnOT65d+vpfyWUkgwHwYDVR0jBBgwFoAUgOcrtxBXLxbpnOT65d+vpfyWUkgw
-DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAEE9bFmUCA+6cvESKPoi2
-TGSpV652d0xd2U66LpEXeiWRJFLz8YGgoJCx3QFGBscJDXxrLxrBBBV/tCpEqypo
-pYIqsawH7M66jpOr83Us3M8JC2eFBZJocMpXxdytWqHik5VKZNx6VQFT8bS7+yVC
-VoUKePhlgcg+pmo41qjqieBNKRMh/1tXS77DI1lgO5wZLVrLXcdqWuDpmaQOKJeq
-G/nxytCW/YJA7bFn/8Gjy8DYypJSeeaKu7o3P3+ONJHdIMHb+MdcheDBS9AOFSeo
-xI0D5EbO9F873O77l7nbD7B0X34HFN0nGczC4poexIpbDFG3hAPekwZ5KC6VwJLc
-1Q==
------END CERTIFICATE-----
diff --git a/test/netlib/data/verificationcerts/generate.py b/test/netlib/data/verificationcerts/generate.py
deleted file mode 100644
index 6d4d8550..00000000
--- a/test/netlib/data/verificationcerts/generate.py
+++ /dev/null
@@ -1,66 +0,0 @@
-"""
-Generate SSL test certificates.
-"""
-import subprocess
-import shlex
-import os
-import shutil
-
-
-ROOT_CA = "trusted-root"
-SUBJECT = "/CN=example.mitmproxy.org/"
-
-
-def do(args):
- print("> %s" % args)
- args = shlex.split(args)
- output = subprocess.check_output(args)
- return output
-
-
-def genrsa(cert):
- do("openssl genrsa -out {cert}.key 2048".format(cert=cert))
-
-
-def sign(cert):
- do("openssl x509 -req -in {cert}.csr "
- "-CA {root_ca}.crt "
- "-CAkey {root_ca}.key "
- "-CAcreateserial "
- "-days 1024 "
- "-out {cert}.crt".format(root_ca=ROOT_CA, cert=cert)
- )
-
-
-def mkcert(cert, args):
- genrsa(cert)
- do("openssl req -new -nodes -batch "
- "-key {cert}.key "
- "{args} "
- "-out {cert}.csr".format(cert=cert, args=args)
- )
- sign(cert)
- os.remove("{cert}.csr".format(cert=cert))
-
-
-# create trusted root CA
-genrsa("trusted-root")
-do("openssl req -x509 -new -nodes -batch "
- "-key trusted-root.key "
- "-days 1024 "
- "-out trusted-root.crt"
- )
-h = do("openssl x509 -hash -noout -in trusted-root.crt").decode("ascii").strip()
-shutil.copyfile("trusted-root.crt", "{}.0".format(h))
-
-# create trusted leaf cert.
-mkcert("trusted-leaf", "-subj {}".format(SUBJECT))
-
-# create self-signed cert
-genrsa("self-signed")
-do("openssl req -x509 -new -nodes -batch "
- "-key self-signed.key "
- "-subj {} "
- "-days 1024 "
- "-out self-signed.crt".format(SUBJECT)
- )
diff --git a/test/netlib/data/verificationcerts/self-signed.crt b/test/netlib/data/verificationcerts/self-signed.crt
deleted file mode 100644
index dce2a7e0..00000000
--- a/test/netlib/data/verificationcerts/self-signed.crt
+++ /dev/null
@@ -1,19 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDEzCCAfugAwIBAgIJAJ945xt1FRsfMA0GCSqGSIb3DQEBCwUAMCAxHjAcBgNV
-BAMMFWV4YW1wbGUubWl0bXByb3h5Lm9yZzAeFw0xNTExMDExNjQ4MDJaFw0xODA4
-MjExNjQ4MDJaMCAxHjAcBgNVBAMMFWV4YW1wbGUubWl0bXByb3h5Lm9yZzCCASIw
-DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALFxyzPfjgIghOMMnJlW80yB84xC
-nJtko3tuyOdozgTCyha2W+NdIKPNZJtWrzN4P0B5PlozCDwfcSYffLs0WZs8LRWv
-BfZX8+oX+14qQjKFsiqgO65cTLP3qlPySYPJQQ37vOP1Y5Yf8nQq2mwQdC18hLtT
-QOANG6OFoSplpBLsYF+QeoMgqCTa6hrl/5GLmQoDRTjXkv3Sj379AUDMybuBqccm
-q5EIqCrE4+xJ8JywJclAVn2YP14baiFrrYCsYYg4sS1Od6xFj+xtpLe7My3AYjB9
-/aeHd8vDiob0cqOW1TFwhqgJKuErfFyg8lZ2hJmStJKyfofWuY/gl/vnvX0CAwEA
-AaNQME4wHQYDVR0OBBYEFB8d32zK8eqZIoKw4jXzYzhw4amPMB8GA1UdIwQYMBaA
-FB8d32zK8eqZIoKw4jXzYzhw4amPMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEL
-BQADggEBAJmo2oKv1OEjZ0Q4yELO6BAnHAkmBKpW+zmLyQa8idxtLVkI9uXk3iqY
-GWugkmcUZCTVFRWv/QXQQSex+00IY3x2rdHbtuZwcyKiz2u8WEmfW1rOIwBaFJ1i
-v7+SA2aZs6vepN2sE56X54c/YbwQooaKZtOb+djWXYMJrc/Ezj0J7oQIJTptYV8v
-/3216yCHRp/KCL7yTLtiw25xKuXNu/gkcd8wZOY9rS2qMUD897MJF0MvgJoauRBd
-d4XEYCNKkrIRmfqrkiRQfAZpvpoutH6NCk7KuQYcI0BlOHlsnHHcs/w72EEqHwFq
-x6476tW/t8GJDZVD74+pNBcLifXxArE=
------END CERTIFICATE-----
diff --git a/test/netlib/data/verificationcerts/self-signed.key b/test/netlib/data/verificationcerts/self-signed.key
deleted file mode 100644
index 71a6ad6a..00000000
--- a/test/netlib/data/verificationcerts/self-signed.key
+++ /dev/null
@@ -1,27 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIEowIBAAKCAQEAsXHLM9+OAiCE4wycmVbzTIHzjEKcm2Sje27I52jOBMLKFrZb
-410go81km1avM3g/QHk+WjMIPB9xJh98uzRZmzwtFa8F9lfz6hf7XipCMoWyKqA7
-rlxMs/eqU/JJg8lBDfu84/Vjlh/ydCrabBB0LXyEu1NA4A0bo4WhKmWkEuxgX5B6
-gyCoJNrqGuX/kYuZCgNFONeS/dKPfv0BQMzJu4GpxyarkQioKsTj7EnwnLAlyUBW
-fZg/XhtqIWutgKxhiDixLU53rEWP7G2kt7szLcBiMH39p4d3y8OKhvRyo5bVMXCG
-qAkq4St8XKDyVnaEmZK0krJ+h9a5j+CX++e9fQIDAQABAoIBAQCT+FvGbych2PJX
-0D2KlXqgE0IAdc/YuYymstSwPLKIP9N8KyfnKtK8Jdw+uYOyfRTp8/EuEJ5OXL3j
-V6CRD++lRwIlseVb7y5EySjh9oVrUhgn+aSrGucPsHkGNeZeEmbAfWugARLBrvRl
-MRMhyHrJL6wT9jIEZInmy9mA3G99IuFW3rS8UR1Yu7zyvhtjvop1xg/wfEUu24Ty
-PvMfnwaDcZHCz2tmu2KJvaxSBAG3FKmAqeMvk1Gt5m2keKgw03M+EX0LrM8ybWqn
-VwB8tnSyMBLVFLIXMpIiSfpji10+p9fdKFMRF++D6qVwyoxPiIq+yEJapxXiqLea
-mkhtJW91AoGBAOvIb7bZvH4wYvi6txs2pygF3ZMjqg/fycnplrmYMrjeeDeeN4v1
-h/5tkN9TeTkHRaN3L7v49NEUDhDyuopLTNfWpYdv63U/BVzvgMm/guacTYkx9whB
-OvQ2YekR/WKg7kuyrTZidTDz+mjU+1b8JaWGjiDc6vFwxZA7uWicaGGHAoGBAMCo
-y/2AwFGwCR+5bET1nTTyxok6iKo4k6R/7DJe4Bq8VLifoyX3zDlGG/33KN3xVqBU
-xnT9gkii1lfX2U+4iM+GOSPl0nG0hOEqEH+vFHszpHybDeNez3FEyIbgOzg6u7sV
-NOy+P94L5EMQVEmWp5g6Vm3k9kr92Bd9UacKQPnbAoGAMN8KyMu41i8RVJze9zUM
-0K7mjmkGBuRL3x4br7xsRwVVxbF1sfzig0oSjTewGLH5LTi3HC8uD2gowjqNj7yr
-4NEM3lXEaDj305uRBkA70bD0IUvJ+FwM7DGZecXQz3Cr8+TFIlCmGc94R+Jddlot
-M3IAY69mw0SsroiylYxV1mECgYAcSGtx8rXJCDO+sYTgdsI2ZLGasbogax/ZlWIC
-XwU9R4qUc/MKft8/RTiUxvT76BMUhH2B7Tl0GlunF6vyVR/Yf1biGzoSsTKUr40u
-gXBbSdCK7mRSjbecZEGf80keTxkCNPHJE4DiwxImej41c2V1JpNLnMI/bhaMFDyp
-bgrt4wKBgHFzZgAgM1v07F038tAkIBGrYLukY1ZFBaZoGZ9xHfy/EmLJM3HCHLO5
-8wszMGhMTe2+39EeChwgj0kFaq1YnDiucU74BC57KR1tD59y7l6UnsQXTm4/32j8
-Or6i8GekBibCb97DzzOU0ZK//fNhHTXpDDXsYt5lJUWSmgW+S9Qp
------END RSA PRIVATE KEY-----
diff --git a/test/netlib/data/verificationcerts/trusted-leaf.crt b/test/netlib/data/verificationcerts/trusted-leaf.crt
deleted file mode 100644
index 6a92de92..00000000
--- a/test/netlib/data/verificationcerts/trusted-leaf.crt
+++ /dev/null
@@ -1,18 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIC4TCCAckCCQCj6D9oVylb8jANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJB
-VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0
-cyBQdHkgTHRkMB4XDTE1MTEwMTE2NDgwMloXDTE4MDgyMTE2NDgwMlowIDEeMBwG
-A1UEAwwVZXhhbXBsZS5taXRtcHJveHkub3JnMIIBIjANBgkqhkiG9w0BAQEFAAOC
-AQ8AMIIBCgKCAQEAy/L5JYHS7QFhSIsjmd6bJTgs2rdqEn6tsmPBVZKZ7SqCAVjW
-hPpEu7Q23akmU6Zm9Fp/vENc3jzxQLlEKhrv7eWmFYSOrCYtbJOz3RQorlwjjfdY
-LlNQh1wYUXQX3PN3r3dyYtt5vTtXKc8+aP4M4vX7qlbW+4j4LrQfmPjS0XOdYpu3
-wh+i1ZMIhZye3hpCjwnpjTf7/ff45ZFxtkoi1uzEC/+swr1RSvamY8Foe12Re17Z
-5ij8ZB0NIdoSk1tDkY3sJ8iNi35+qartl0UYeG9IUXRwDRrPsEKpF4RxY1+X2bdZ
-r6PKb/E4CA5JlMvS5SVmrvxjCVqTQBmTjXfxqwIDAQABMA0GCSqGSIb3DQEBCwUA
-A4IBAQBmpSZJrTDvzSlo6P7P7x1LoETzHyVjwgPeqGYw6ndGXeJMN9rhhsFvRsiB
-I/aHh58MIlSjti7paikDAoFHB3dBvFHR+JUa/ailWEbcZReWRSE3lV6wFiN3G3lU
-OyofR7MKnPW7bv8hSqOLqP1mbupXuQFB5M6vPLRwg5VgiCHI/XBiTvzMamzvNAR3
-UHHZtsJkRqzogYm6K9YJaga7jteSx2nNo+ujLwrxeXsLChTyFMJGnVkp5IyKeNfc
-qwlzNncb3y+4KnUdNkPEtuydgAxAfuyXufiFBYRcUWbQ5/9ycgF7131ySaj9f/Y2
-kMsv2jg+soKvwwVYCABsk1KSHtfz
------END CERTIFICATE-----
diff --git a/test/netlib/data/verificationcerts/trusted-leaf.key b/test/netlib/data/verificationcerts/trusted-leaf.key
deleted file mode 100644
index 783ebf1c..00000000
--- a/test/netlib/data/verificationcerts/trusted-leaf.key
+++ /dev/null
@@ -1,27 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIEpAIBAAKCAQEAy/L5JYHS7QFhSIsjmd6bJTgs2rdqEn6tsmPBVZKZ7SqCAVjW
-hPpEu7Q23akmU6Zm9Fp/vENc3jzxQLlEKhrv7eWmFYSOr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LDoXq15ttTs
-wSUBBMCh2tIy+201XV2eu++XIpMQca84C/v352RFTH8hqtdpZqkY74KsCDGzcd6x
-SQxxfM5efIzoVPb2crEX0MZRAoGAQ2EqFSfL9flo7UQ8GRN0itJ7mUgJV2WxCZT5
-2X9i/y0eSN1feuKOhjfsTPMNLEWk5kwy48GuBs6xpj8Qa10zGUgVHp4bzdeEgAfK
-9DhDSLt1694YZBKkAUpRERj8xXAC6nvWFLZAwjhhbRw7gAqMywgMt/q4i85usYRD
-F0ESE/kCgYBbc083PcLmlHbkn/d1i4IcLI6wFk+tZYIEVYDid7xDOgZOBcOTTyYB
-BrDzNqbKNexKRt7QHVlwR+VOGMdN5P0hf7oH3SMW23OxBKoQe8pUSGF9a4DjCS1v
-vCXMekifb9kIhhUWaG71L8+MaOzNBVAmk1+3NzPZgV/YxHjAWWhGHQ==
------END RSA PRIVATE KEY-----
diff --git a/test/netlib/data/verificationcerts/trusted-root.crt b/test/netlib/data/verificationcerts/trusted-root.crt
deleted file mode 100644
index b22e4d20..00000000
--- a/test/netlib/data/verificationcerts/trusted-root.crt
+++ /dev/null
@@ -1,21 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDXTCCAkWgAwIBAgIJAPAfPQGCV/Z4MA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
-BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
-aWRnaXRzIFB0eSBMdGQwHhcNMTUxMTAxMTY0ODAxWhcNMTgwODIxMTY0ODAxWjBF
-MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
-ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
-CgKCAQEArp8LD34JhKCwcQbwIYQMg4+eCgLVN8fwB7+/qOfJbArPs0djFBN+F7c6
-HGvMr24BKUk5u8pn4dPtNurm/vPC8ovNGmcXz62BQJpcMX2veVdRsF7yNwhNacNJ
-Arq+70zNMwYBznx0XUxMF6j6nVFf3AW6SU04ylT4Mp3SY/BUUDAdfl1eRo0mPLNS
-8rpsN+8YBw1Q7SCuBRVqpOgVIsL88svgQUSOlzvMZPBpG/cmB3BNKNrltwb5iFEI
-1jAV7uSj5IcIuNO/246kfsDVPTFMJIzav/CUoidd5UNw+SoFDlzh8sA7L1Bm7D1/
-3KHYSKswGsSR3kynAl10w/SJKDtn8wIDAQABo1AwTjAdBgNVHQ4EFgQUgOcrtxBX
-LxbpnOT65d+vpfyWUkgwHwYDVR0jBBgwFoAUgOcrtxBXLxbpnOT65d+vpfyWUkgw
-DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAEE9bFmUCA+6cvESKPoi2
-TGSpV652d0xd2U66LpEXeiWRJFLz8YGgoJCx3QFGBscJDXxrLxrBBBV/tCpEqypo
-pYIqsawH7M66jpOr83Us3M8JC2eFBZJocMpXxdytWqHik5VKZNx6VQFT8bS7+yVC
-VoUKePhlgcg+pmo41qjqieBNKRMh/1tXS77DI1lgO5wZLVrLXcdqWuDpmaQOKJeq
-G/nxytCW/YJA7bFn/8Gjy8DYypJSeeaKu7o3P3+ONJHdIMHb+MdcheDBS9AOFSeo
-xI0D5EbO9F873O77l7nbD7B0X34HFN0nGczC4poexIpbDFG3hAPekwZ5KC6VwJLc
-1Q==
------END CERTIFICATE-----
diff --git a/test/netlib/data/verificationcerts/trusted-root.key b/test/netlib/data/verificationcerts/trusted-root.key
deleted file mode 100644
index 05483f77..00000000
--- a/test/netlib/data/verificationcerts/trusted-root.key
+++ /dev/null
@@ -1,27 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIEowIBAAKCAQEArp8LD34JhKCwcQbwIYQMg4+eCgLVN8fwB7+/qOfJbArPs0dj
-FBN+F7c6HGvMr24BKUk5u8pn4dPtNurm/vPC8ovNGmcXz62BQJpcMX2veVdRsF7y
-NwhNacNJArq+70zNMwY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5/RrsoxsSb7UAKJothWTWZ2Karc/xx
-zkNpjsfWjrHPSypbyU4lYQKBgFh1R5/BgnatjO/5LGNSok/uFkOQfxqo6BTtYOh6
-P9efO/5A1lBdtBeE+oIsSphzWO7DTtE6uB9Kw2V3Y/83hw+5RjABoG8Cu+OdMURD
-eqb+WeFH8g45Pn31E8Bbcq34g5u5YR0jhz8Z13ZzuojZabNRPmIntxmGVSf4S78a
-/plrAoGBANMHNng2lyr03nqnHrOM6NXD+60af0YR/YJ+2d/H40RnXxGJ4DXn7F00
-a4vJFPa97uq+xpd0HE+TE+NIrOdVDXPePD2qzBzMTsctGtj30vLzojMOT+Yf/nvO
-WxTL5Q8GruJz2Dn0awSZO2z/3A8S1rmpuVZ/jT5NtRrvOSY6hmxF
------END RSA PRIVATE KEY-----
diff --git a/test/netlib/data/verificationcerts/trusted-root.srl b/test/netlib/data/verificationcerts/trusted-root.srl
deleted file mode 100644
index 4ad962ba..00000000
--- a/test/netlib/data/verificationcerts/trusted-root.srl
+++ /dev/null
@@ -1 +0,0 @@
-A3E83F6857295BF2
diff --git a/test/netlib/http/__init__.py b/test/netlib/http/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/test/netlib/http/__init__.py
+++ /dev/null
diff --git a/test/netlib/http/http1/__init__.py b/test/netlib/http/http1/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/test/netlib/http/http1/__init__.py
+++ /dev/null
diff --git a/test/netlib/http/http1/test_assemble.py b/test/netlib/http/http1/test_assemble.py
deleted file mode 100644
index dac5fdad..00000000
--- a/test/netlib/http/http1/test_assemble.py
+++ /dev/null
@@ -1,101 +0,0 @@
-from mitmproxy import exceptions
-from netlib.http import Headers
-from netlib.http.http1.assemble import (
- assemble_request, assemble_request_head, assemble_response,
- assemble_response_head, _assemble_request_line, _assemble_request_headers,
- _assemble_response_headers,
- assemble_body)
-from mitmproxy.test.tutils import treq, raises, tresp
-
-
-def test_assemble_request():
- assert assemble_request(treq()) == (
- b"GET /path HTTP/1.1\r\n"
- b"header: qvalue\r\n"
- b"content-length: 7\r\n"
- b"host: address:22\r\n"
- b"\r\n"
- b"content"
- )
-
- with raises(exceptions.HttpException):
- assemble_request(treq(content=None))
-
-
-def test_assemble_request_head():
- c = assemble_request_head(treq(content=b"foo"))
- assert b"GET" in c
- assert b"qvalue" in c
- assert b"content-length" in c
- assert b"foo" not in c
-
-
-def test_assemble_response():
- assert assemble_response(tresp()) == (
- b"HTTP/1.1 200 OK\r\n"
- b"header-response: svalue\r\n"
- b"content-length: 7\r\n"
- b"\r\n"
- b"message"
- )
-
- with raises(exceptions.HttpException):
- assemble_response(tresp(content=None))
-
-
-def test_assemble_response_head():
- c = assemble_response_head(tresp())
- assert b"200" in c
- assert b"svalue" in c
- assert b"message" not in c
-
-
-def test_assemble_body():
- c = list(assemble_body(Headers(), [b"body"]))
- assert c == [b"body"]
-
- c = list(assemble_body(Headers(transfer_encoding="chunked"), [b"123456789a", b""]))
- assert c == [b"a\r\n123456789a\r\n", b"0\r\n\r\n"]
-
- c = list(assemble_body(Headers(transfer_encoding="chunked"), [b"123456789a"]))
- assert c == [b"a\r\n123456789a\r\n", b"0\r\n\r\n"]
-
-
-def test_assemble_request_line():
- assert _assemble_request_line(treq().data) == b"GET /path HTTP/1.1"
-
- authority_request = treq(method=b"CONNECT", first_line_format="authority").data
- assert _assemble_request_line(authority_request) == b"CONNECT address:22 HTTP/1.1"
-
- absolute_request = treq(first_line_format="absolute").data
- assert _assemble_request_line(absolute_request) == b"GET http://address:22/path HTTP/1.1"
-
- with raises(RuntimeError):
- _assemble_request_line(treq(first_line_format="invalid_form").data)
-
-
-def test_assemble_request_headers():
- # https://github.com/mitmproxy/mitmproxy/issues/186
- r = treq(content=b"")
- r.headers["Transfer-Encoding"] = "chunked"
- c = _assemble_request_headers(r.data)
- assert b"Transfer-Encoding" in c
-
-
-def test_assemble_request_headers_host_header():
- r = treq()
- r.headers = Headers()
- c = _assemble_request_headers(r.data)
- assert b"host" in c
-
- r.host = None
- c = _assemble_request_headers(r.data)
- assert b"host" not in c
-
-
-def test_assemble_response_headers():
- # https://github.com/mitmproxy/mitmproxy/issues/186
- r = tresp(content=b"")
- r.headers["Transfer-Encoding"] = "chunked"
- c = _assemble_response_headers(r)
- assert b"Transfer-Encoding" in c
diff --git a/test/netlib/http/http1/test_read.py b/test/netlib/http/http1/test_read.py
deleted file mode 100644
index eb96968c..00000000
--- a/test/netlib/http/http1/test_read.py
+++ /dev/null
@@ -1,371 +0,0 @@
-from io import BytesIO
-from mock import Mock
-import pytest
-
-from mitmproxy import exceptions
-from netlib.http import Headers
-from netlib.http.http1.read import (
- read_request, read_response, read_request_head,
- read_response_head, read_body, connection_close, expected_http_body_size, _get_first_line,
- _read_request_line, _parse_authority_form, _read_response_line, _check_http_version,
- _read_headers, _read_chunked, get_header_tokens
-)
-from mitmproxy.test.tutils import treq, tresp, raises
-
-
-def test_get_header_tokens():
- headers = Headers()
- assert get_header_tokens(headers, "foo") == []
- headers["foo"] = "bar"
- assert get_header_tokens(headers, "foo") == ["bar"]
- headers["foo"] = "bar, voing"
- assert get_header_tokens(headers, "foo") == ["bar", "voing"]
- headers.set_all("foo", ["bar, voing", "oink"])
- assert get_header_tokens(headers, "foo") == ["bar", "voing", "oink"]
-
-
-@pytest.mark.parametrize("input", [
- b"GET / HTTP/1.1\r\n\r\nskip",
- b"GET / HTTP/1.1\r\n\r\nskip",
- b"GET / HTTP/1.1\r\n\r\nskip",
- b"GET / HTTP/1.1 \r\n\r\nskip",
-])
-def test_read_request(input):
- rfile = BytesIO(input)
- r = read_request(rfile)
- assert r.method == "GET"
- assert r.content == b""
- assert r.http_version == "HTTP/1.1"
- assert r.timestamp_end
- assert rfile.read() == b"skip"
-
-
-@pytest.mark.parametrize("input", [
- b"CONNECT :0 0",
-])
-def test_read_request_error(input):
- rfile = BytesIO(input)
- raises(exceptions.HttpException, read_request, rfile)
-
-
-def test_read_request_head():
- rfile = BytesIO(
- b"GET / HTTP/1.1\r\n"
- b"Content-Length: 4\r\n"
- b"\r\n"
- b"skip"
- )
- rfile.reset_timestamps = Mock()
- rfile.first_byte_timestamp = 42
- r = read_request_head(rfile)
- assert r.method == "GET"
- assert r.headers["Content-Length"] == "4"
- assert r.content is None
- assert rfile.reset_timestamps.called
- assert r.timestamp_start == 42
- assert rfile.read() == b"skip"
-
-
-@pytest.mark.parametrize("input", [
- b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody",
- b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody",
- b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody",
- b"HTTP/1.1 418 I'm a teapot \r\n\r\nbody",
-])
-def test_read_response(input):
- req = treq()
- rfile = BytesIO(input)
- r = read_response(rfile, req)
- assert r.http_version == "HTTP/1.1"
- assert r.status_code == 418
- assert r.reason == "I'm a teapot"
- assert r.content == b"body"
- assert r.timestamp_end
-
-
-def test_read_response_head():
- rfile = BytesIO(
- b"HTTP/1.1 418 I'm a teapot\r\n"
- b"Content-Length: 4\r\n"
- b"\r\n"
- b"skip"
- )
- rfile.reset_timestamps = Mock()
- rfile.first_byte_timestamp = 42
- r = read_response_head(rfile)
- assert r.status_code == 418
- assert r.headers["Content-Length"] == "4"
- assert r.content is None
- assert rfile.reset_timestamps.called
- assert r.timestamp_start == 42
- assert rfile.read() == b"skip"
-
-
-class TestReadBody:
- def test_chunked(self):
- rfile = BytesIO(b"3\r\nfoo\r\n0\r\n\r\nbar")
- body = b"".join(read_body(rfile, None))
- assert body == b"foo"
- assert rfile.read() == b"bar"
-
- def test_known_size(self):
- rfile = BytesIO(b"foobar")
- body = b"".join(read_body(rfile, 3))
- assert body == b"foo"
- assert rfile.read() == b"bar"
-
- def test_known_size_limit(self):
- rfile = BytesIO(b"foobar")
- with raises(exceptions.HttpException):
- b"".join(read_body(rfile, 3, 2))
-
- def test_known_size_too_short(self):
- rfile = BytesIO(b"foo")
- with raises(exceptions.HttpException):
- b"".join(read_body(rfile, 6))
-
- def test_unknown_size(self):
- rfile = BytesIO(b"foobar")
- body = b"".join(read_body(rfile, -1))
- assert body == b"foobar"
-
- def test_unknown_size_limit(self):
- rfile = BytesIO(b"foobar")
- with raises(exceptions.HttpException):
- b"".join(read_body(rfile, -1, 3))
-
- def test_max_chunk_size(self):
- rfile = BytesIO(b"123456")
- assert list(read_body(rfile, -1, max_chunk_size=None)) == [b"123456"]
- rfile = BytesIO(b"123456")
- assert list(read_body(rfile, -1, max_chunk_size=1)) == [b"1", b"2", b"3", b"4", b"5", b"6"]
-
-
-def test_connection_close():
- headers = Headers()
- assert connection_close(b"HTTP/1.0", headers)
- assert not connection_close(b"HTTP/1.1", headers)
-
- headers["connection"] = "keep-alive"
- assert not connection_close(b"HTTP/1.1", headers)
-
- headers["connection"] = "close"
- assert connection_close(b"HTTP/1.1", headers)
-
- headers["connection"] = "foobar"
- assert connection_close(b"HTTP/1.0", headers)
- assert not connection_close(b"HTTP/1.1", headers)
-
-
-def test_expected_http_body_size():
- # Expect: 100-continue
- assert expected_http_body_size(
- treq(headers=Headers(expect="100-continue", content_length="42"))
- ) == 0
-
- # http://tools.ietf.org/html/rfc7230#section-3.3
- assert expected_http_body_size(
- treq(method=b"HEAD"),
- tresp(headers=Headers(content_length="42"))
- ) == 0
- assert expected_http_body_size(
- treq(method=b"CONNECT"),
- tresp()
- ) == 0
- for code in (100, 204, 304):
- assert expected_http_body_size(
- treq(),
- tresp(status_code=code)
- ) == 0
-
- # chunked
- assert expected_http_body_size(
- treq(headers=Headers(transfer_encoding="chunked")),
- ) is None
-
- # explicit length
- for val in (b"foo", b"-7"):
- with raises(exceptions.HttpSyntaxException):
- expected_http_body_size(
- treq(headers=Headers(content_length=val))
- )
- assert expected_http_body_size(
- treq(headers=Headers(content_length="42"))
- ) == 42
-
- # no length
- assert expected_http_body_size(
- treq(headers=Headers())
- ) == 0
- assert expected_http_body_size(
- treq(headers=Headers()), tresp(headers=Headers())
- ) == -1
-
-
-def test_get_first_line():
- rfile = BytesIO(b"foo\r\nbar")
- assert _get_first_line(rfile) == b"foo"
-
- rfile = BytesIO(b"\r\nfoo\r\nbar")
- assert _get_first_line(rfile) == b"foo"
-
- with raises(exceptions.HttpReadDisconnect):
- rfile = BytesIO(b"")
- _get_first_line(rfile)
-
- with raises(exceptions.HttpReadDisconnect):
- rfile = Mock()
- rfile.readline.side_effect = exceptions.TcpDisconnect
- _get_first_line(rfile)
-
-
-def test_read_request_line():
- def t(b):
- return _read_request_line(BytesIO(b))
-
- assert (t(b"GET / HTTP/1.1") ==
- ("relative", b"GET", None, None, None, b"/", b"HTTP/1.1"))
- assert (t(b"OPTIONS * HTTP/1.1") ==
- ("relative", b"OPTIONS", None, None, None, b"*", b"HTTP/1.1"))
- assert (t(b"CONNECT foo:42 HTTP/1.1") ==
- ("authority", b"CONNECT", None, b"foo", 42, None, b"HTTP/1.1"))
- assert (t(b"GET http://foo:42/bar HTTP/1.1") ==
- ("absolute", b"GET", b"http", b"foo", 42, b"/bar", b"HTTP/1.1"))
-
- with raises(exceptions.HttpSyntaxException):
- t(b"GET / WTF/1.1")
- with raises(exceptions.HttpSyntaxException):
- t(b"this is not http")
- with raises(exceptions.HttpReadDisconnect):
- t(b"")
-
-
-def test_parse_authority_form():
- assert _parse_authority_form(b"foo:42") == (b"foo", 42)
- with raises(exceptions.HttpSyntaxException):
- _parse_authority_form(b"foo")
- with raises(exceptions.HttpSyntaxException):
- _parse_authority_form(b"foo:bar")
- with raises(exceptions.HttpSyntaxException):
- _parse_authority_form(b"foo:99999999")
- with raises(exceptions.HttpSyntaxException):
- _parse_authority_form(b"f\x00oo:80")
-
-
-def test_read_response_line():
- def t(b):
- return _read_response_line(BytesIO(b))
-
- assert t(b"HTTP/1.1 200 OK") == (b"HTTP/1.1", 200, b"OK")
- assert t(b"HTTP/1.1 200") == (b"HTTP/1.1", 200, b"")
-
- # https://github.com/mitmproxy/mitmproxy/issues/784
- assert t(b"HTTP/1.1 200 Non-Autoris\xc3\xa9") == (b"HTTP/1.1", 200, b"Non-Autoris\xc3\xa9")
-
- with raises(exceptions.HttpSyntaxException):
- assert t(b"HTTP/1.1")
-
- with raises(exceptions.HttpSyntaxException):
- t(b"HTTP/1.1 OK OK")
- with raises(exceptions.HttpSyntaxException):
- t(b"WTF/1.1 200 OK")
- with raises(exceptions.HttpReadDisconnect):
- t(b"")
-
-
-def test_check_http_version():
- _check_http_version(b"HTTP/0.9")
- _check_http_version(b"HTTP/1.0")
- _check_http_version(b"HTTP/1.1")
- _check_http_version(b"HTTP/2.0")
- with raises(exceptions.HttpSyntaxException):
- _check_http_version(b"WTF/1.0")
- with raises(exceptions.HttpSyntaxException):
- _check_http_version(b"HTTP/1.10")
- with raises(exceptions.HttpSyntaxException):
- _check_http_version(b"HTTP/1.b")
-
-
-class TestReadHeaders:
- @staticmethod
- def _read(data):
- return _read_headers(BytesIO(data))
-
- def test_read_simple(self):
- data = (
- b"Header: one\r\n"
- b"Header2: two\r\n"
- b"\r\n"
- )
- headers = self._read(data)
- assert headers.fields == ((b"Header", b"one"), (b"Header2", b"two"))
-
- def test_read_multi(self):
- data = (
- b"Header: one\r\n"
- b"Header: two\r\n"
- b"\r\n"
- )
- headers = self._read(data)
- assert headers.fields == ((b"Header", b"one"), (b"Header", b"two"))
-
- def test_read_continued(self):
- data = (
- b"Header: one\r\n"
- b"\ttwo\r\n"
- b"Header2: three\r\n"
- b"\r\n"
- )
- headers = self._read(data)
- assert headers.fields == ((b"Header", b"one\r\n two"), (b"Header2", b"three"))
-
- def test_read_continued_err(self):
- data = b"\tfoo: bar\r\n"
- with raises(exceptions.HttpSyntaxException):
- self._read(data)
-
- def test_read_err(self):
- data = b"foo"
- with raises(exceptions.HttpSyntaxException):
- self._read(data)
-
- def test_read_empty_name(self):
- data = b":foo"
- with raises(exceptions.HttpSyntaxException):
- self._read(data)
-
- def test_read_empty_value(self):
- data = b"bar:"
- headers = self._read(data)
- assert headers.fields == ((b"bar", b""),)
-
-
-def test_read_chunked():
- req = treq(content=None)
- req.headers["Transfer-Encoding"] = "chunked"
-
- data = b"1\r\na\r\n0\r\n"
- with raises(exceptions.HttpSyntaxException):
- b"".join(_read_chunked(BytesIO(data)))
-
- data = b"1\r\na\r\n0\r\n\r\n"
- assert b"".join(_read_chunked(BytesIO(data))) == b"a"
-
- data = b"\r\n\r\n1\r\na\r\n1\r\nb\r\n0\r\n\r\n"
- assert b"".join(_read_chunked(BytesIO(data))) == b"ab"
-
- data = b"\r\n"
- with raises("closed prematurely"):
- b"".join(_read_chunked(BytesIO(data)))
-
- data = b"1\r\nfoo"
- with raises("malformed chunked body"):
- b"".join(_read_chunked(BytesIO(data)))
-
- data = b"foo\r\nfoo"
- with raises(exceptions.HttpSyntaxException):
- b"".join(_read_chunked(BytesIO(data)))
-
- data = b"5\r\naaaaa\r\n0\r\n\r\n"
- with raises("too large"):
- b"".join(_read_chunked(BytesIO(data), limit=2))
diff --git a/test/netlib/http/http2/__init__.py b/test/netlib/http/http2/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/test/netlib/http/http2/__init__.py
+++ /dev/null
diff --git a/test/netlib/http/http2/test_framereader.py b/test/netlib/http/http2/test_framereader.py
deleted file mode 100644
index 41b73189..00000000
--- a/test/netlib/http/http2/test_framereader.py
+++ /dev/null
@@ -1 +0,0 @@
-# foobar
diff --git a/test/netlib/http/test_authentication.py b/test/netlib/http/test_authentication.py
deleted file mode 100644
index 5e04bbc5..00000000
--- a/test/netlib/http/test_authentication.py
+++ /dev/null
@@ -1,122 +0,0 @@
-import binascii
-
-from mitmproxy.test import tutils
-from netlib.http import authentication, Headers
-
-
-def test_parse_http_basic_auth():
- vals = ("basic", "foo", "bar")
- assert authentication.parse_http_basic_auth(
- authentication.assemble_http_basic_auth(*vals)
- ) == vals
- assert not authentication.parse_http_basic_auth("")
- assert not authentication.parse_http_basic_auth("foo bar")
- v = "basic " + binascii.b2a_base64(b"foo").decode("ascii")
- assert not authentication.parse_http_basic_auth(v)
-
-
-class TestPassManNonAnon:
-
- def test_simple(self):
- p = authentication.PassManNonAnon()
- assert not p.test("", "")
- assert p.test("user", "")
-
-
-class TestPassManHtpasswd:
-
- def test_file_errors(self):
- tutils.raises(
- "malformed htpasswd file",
- authentication.PassManHtpasswd,
- tutils.test_data.path("data/server.crt"))
-
- def test_simple(self):
- pm = authentication.PassManHtpasswd(tutils.test_data.path("data/htpasswd"))
-
- vals = ("basic", "test", "test")
- authentication.assemble_http_basic_auth(*vals)
- assert pm.test("test", "test")
- assert not pm.test("test", "foo")
- assert not pm.test("foo", "test")
- assert not pm.test("test", "")
- assert not pm.test("", "")
-
-
-class TestPassManSingleUser:
-
- def test_simple(self):
- pm = authentication.PassManSingleUser("test", "test")
- assert pm.test("test", "test")
- assert not pm.test("test", "foo")
- assert not pm.test("foo", "test")
-
-
-class TestNullProxyAuth:
-
- def test_simple(self):
- na = authentication.NullProxyAuth(authentication.PassManNonAnon())
- assert not na.auth_challenge_headers()
- assert na.authenticate("foo")
- na.clean({})
-
-
-class TestBasicProxyAuth:
-
- def test_simple(self):
- ba = authentication.BasicProxyAuth(authentication.PassManNonAnon(), "test")
- headers = Headers()
- assert ba.auth_challenge_headers()
- assert not ba.authenticate(headers)
-
- def test_authenticate_clean(self):
- ba = authentication.BasicProxyAuth(authentication.PassManNonAnon(), "test")
-
- headers = Headers()
- vals = ("basic", "foo", "bar")
- headers[ba.AUTH_HEADER] = authentication.assemble_http_basic_auth(*vals)
- assert ba.authenticate(headers)
-
- ba.clean(headers)
- assert ba.AUTH_HEADER not in headers
-
- headers[ba.AUTH_HEADER] = ""
- assert not ba.authenticate(headers)
-
- headers[ba.AUTH_HEADER] = "foo"
- assert not ba.authenticate(headers)
-
- vals = ("foo", "foo", "bar")
- headers[ba.AUTH_HEADER] = authentication.assemble_http_basic_auth(*vals)
- assert not ba.authenticate(headers)
-
- ba = authentication.BasicProxyAuth(authentication.PassMan(), "test")
- vals = ("basic", "foo", "bar")
- headers[ba.AUTH_HEADER] = authentication.assemble_http_basic_auth(*vals)
- assert not ba.authenticate(headers)
-
-
-class Bunch:
- pass
-
-
-class TestAuthAction:
-
- def test_nonanonymous(self):
- m = Bunch()
- aa = authentication.NonanonymousAuthAction(None, "authenticator")
- aa(None, m, None, None)
- assert m.authenticator
-
- def test_singleuser(self):
- m = Bunch()
- aa = authentication.SingleuserAuthAction(None, "authenticator")
- aa(None, m, "foo:bar", None)
- assert m.authenticator
- tutils.raises("invalid", aa, None, m, "foo", None)
-
- def test_httppasswd(self):
- m = Bunch()
- aa = authentication.HtpasswdAuthAction(None, "authenticator")
- aa(None, m, tutils.test_data.path("data/htpasswd"), None)
- assert m.authenticator
diff --git a/test/netlib/http/test_cookies.py b/test/netlib/http/test_cookies.py
deleted file mode 100644
index ca10a69c..00000000
--- a/test/netlib/http/test_cookies.py
+++ /dev/null
@@ -1,365 +0,0 @@
-import time
-
-from netlib.http import cookies
-from mitmproxy.test.tutils import raises
-
-import mock
-
-cookie_pairs = [
- [
- "",
- []
- ],
- [
- "one=uno",
- [["one", "uno"]]
- ],
- [
- "one",
- [["one", None]]
- ],
- [
- "one=uno; two=due",
- [["one", "uno"], ["two", "due"]]
- ],
- [
- 'one="uno"; two="\due"',
- [["one", "uno"], ["two", "due"]]
- ],
- [
- 'one="un\\"o"',
- [["one", 'un"o']]
- ],
- [
- 'one="uno,due"',
- [["one", 'uno,due']]
- ],
- [
- "one=uno; two; three=tre",
- [["one", "uno"], ["two", None], ["three", "tre"]]
- ],
- [
- "_lvs2=zHai1+Hq+Tc2vmc2r4GAbdOI5Jopg3EwsdUT9g=; "
- "_rcc2=53VdltWl+Ov6ordflA==;",
- [
- ["_lvs2", "zHai1+Hq+Tc2vmc2r4GAbdOI5Jopg3EwsdUT9g="],
- ["_rcc2", "53VdltWl+Ov6ordflA=="]
- ]
- ]
-]
-
-
-def test_read_key():
- tokens = [
- [("foo", 0), ("foo", 3)],
- [("foo", 1), ("oo", 3)],
- [(" foo", 0), (" foo", 4)],
- [(" foo", 1), ("foo", 4)],
- [(" foo;", 1), ("foo", 4)],
- [(" foo=", 1), ("foo", 4)],
- [(" foo=bar", 1), ("foo", 4)],
- ]
- for q, a in tokens:
- assert cookies._read_key(*q) == a
-
-
-def test_read_quoted_string():
- tokens = [
- [('"foo" x', 0), ("foo", 5)],
- [('"f\oo" x', 0), ("foo", 6)],
- [(r'"f\\o" x', 0), (r"f\o", 6)],
- [(r'"f\\" x', 0), (r"f" + '\\', 5)],
- [('"fo\\\"" x', 0), ("fo\"", 6)],
- [('"foo" x', 7), ("", 8)],
- ]
- for q, a in tokens:
- assert cookies._read_quoted_string(*q) == a
-
-
-def test_read_cookie_pairs():
- vals = [
- [
- "one",
- [["one", None]]
- ],
- [
- "one=two",
- [["one", "two"]]
- ],
- [
- "one=",
- [["one", ""]]
- ],
- [
- 'one="two"',
- [["one", "two"]]
- ],
- [
- 'one="two"; three=four',
- [["one", "two"], ["three", "four"]]
- ],
- [
- 'one="two"; three=four; five',
- [["one", "two"], ["three", "four"], ["five", None]]
- ],
- [
- 'one="\\"two"; three=four',
- [["one", '"two'], ["three", "four"]]
- ],
- ]
- for s, lst in vals:
- ret, off = cookies._read_cookie_pairs(s)
- assert ret == lst
-
-
-def test_pairs_roundtrips():
- for s, expected in cookie_pairs:
- ret, off = cookies._read_cookie_pairs(s)
- assert ret == expected
-
- s2 = cookies._format_pairs(expected)
- ret, off = cookies._read_cookie_pairs(s2)
- assert ret == expected
-
-
-def test_cookie_roundtrips():
- for s, expected in cookie_pairs:
- ret = cookies.parse_cookie_header(s)
- assert ret == expected
-
- s2 = cookies.format_cookie_header(expected)
- ret = cookies.parse_cookie_header(s2)
- assert ret == expected
-
-
-def test_parse_set_cookie_pairs():
- pairs = [
- [
- "one=uno",
- [[
- ["one", "uno"]
- ]]
- ],
- [
- "one=un\x20",
- [[
- ["one", "un\x20"]
- ]]
- ],
- [
- "one=uno; foo",
- [[
- ["one", "uno"],
- ["foo", None]
- ]]
- ],
- [
- "mun=1.390.f60; "
- "expires=sun, 11-oct-2015 12:38:31 gmt; path=/; "
- "domain=b.aol.com",
- [[
- ["mun", "1.390.f60"],
- ["expires", "sun, 11-oct-2015 12:38:31 gmt"],
- ["path", "/"],
- ["domain", "b.aol.com"]
- ]]
- ],
- [
- r'rpb=190%3d1%2616726%3d1%2634832%3d1%2634874%3d1; '
- 'domain=.rubiconproject.com; '
- 'expires=mon, 11-may-2015 21:54:57 gmt; '
- 'path=/',
- [[
- ['rpb', r'190%3d1%2616726%3d1%2634832%3d1%2634874%3d1'],
- ['domain', '.rubiconproject.com'],
- ['expires', 'mon, 11-may-2015 21:54:57 gmt'],
- ['path', '/']
- ]]
- ],
- ]
- for s, expected in pairs:
- ret, off = cookies._read_set_cookie_pairs(s)
- assert ret == expected
-
- s2 = cookies._format_set_cookie_pairs(expected[0])
- ret2, off = cookies._read_set_cookie_pairs(s2)
- assert ret2 == expected
-
-
-def test_parse_set_cookie_header():
- def set_cookie_equal(obs, exp):
- assert obs[0] == exp[0]
- assert obs[1] == exp[1]
- assert obs[2].items(multi=True) == exp[2]
-
- vals = [
- [
- "", []
- ],
- [
- ";", []
- ],
- [
- "one=uno",
- [
- ("one", "uno", ())
- ]
- ],
- [
- "one=uno; foo=bar",
- [
- ("one", "uno", (("foo", "bar"),))
- ]
- ],
- [
- "one=uno; foo=bar; foo=baz",
- [
- ("one", "uno", (("foo", "bar"), ("foo", "baz")))
- ]
- ],
- # Comma Separated Variant of Set-Cookie Headers
- [
- "foo=bar, doo=dar",
- [
- ("foo", "bar", ()),
- ("doo", "dar", ()),
- ]
- ],
- [
- "foo=bar; path=/, doo=dar; roo=rar; zoo=zar",
- [
- ("foo", "bar", (("path", "/"),)),
- ("doo", "dar", (("roo", "rar"), ("zoo", "zar"))),
- ]
- ],
- [
- "foo=bar; expires=Mon, 24 Aug 2037",
- [
- ("foo", "bar", (("expires", "Mon, 24 Aug 2037"),)),
- ]
- ],
- [
- "foo=bar; expires=Mon, 24 Aug 2037 00:00:00 GMT, doo=dar",
- [
- ("foo", "bar", (("expires", "Mon, 24 Aug 2037 00:00:00 GMT"),)),
- ("doo", "dar", ()),
- ]
- ],
- ]
- for s, expected in vals:
- ret = cookies.parse_set_cookie_header(s)
- if expected:
- for i in range(len(expected)):
- set_cookie_equal(ret[i], expected[i])
-
- s2 = cookies.format_set_cookie_header(ret)
- ret2 = cookies.parse_set_cookie_header(s2)
- for i in range(len(expected)):
- set_cookie_equal(ret2[i], expected[i])
- else:
- assert not ret
-
-
-def test_refresh_cookie():
-
- # Invalid expires format, sent to us by Reddit.
- c = "rfoo=bar; Domain=reddit.com; expires=Thu, 31 Dec 2037 23:59:59 GMT; Path=/"
- assert cookies.refresh_set_cookie_header(c, 60)
-
- c = "MOO=BAR; Expires=Tue, 08-Mar-2011 00:20:38 GMT; Path=foo.com; Secure"
- assert "00:21:38" in cookies.refresh_set_cookie_header(c, 60)
-
- c = "foo,bar"
- with raises(ValueError):
- cookies.refresh_set_cookie_header(c, 60)
-
- # https://github.com/mitmproxy/mitmproxy/issues/773
- c = ">=A"
- assert cookies.refresh_set_cookie_header(c, 60)
-
- # https://github.com/mitmproxy/mitmproxy/issues/1118
- c = "foo:bar=bla"
- assert cookies.refresh_set_cookie_header(c, 0)
- c = "foo/bar=bla"
- assert cookies.refresh_set_cookie_header(c, 0)
-
-
-@mock.patch('time.time')
-def test_get_expiration_ts(*args):
- # Freeze time
- now_ts = 17
- time.time.return_value = now_ts
-
- CA = cookies.CookieAttrs
- F = cookies.get_expiration_ts
-
- assert F(CA([("Expires", "Thu, 01-Jan-1970 00:00:00 GMT")])) == 0
- assert F(CA([("Expires", "Mon, 24-Aug-2037 00:00:00 GMT")])) == 2134684800
-
- assert F(CA([("Max-Age", "0")])) == now_ts
- assert F(CA([("Max-Age", "31")])) == now_ts + 31
-
-
-def test_is_expired():
- CA = cookies.CookieAttrs
-
- # A cookie can be expired
- # by setting the expire time in the past
- assert cookies.is_expired(CA([("Expires", "Thu, 01-Jan-1970 00:00:00 GMT")]))
-
- # or by setting Max-Age to 0
- assert cookies.is_expired(CA([("Max-Age", "0")]))
-
- # or both
- assert cookies.is_expired(CA([("Expires", "Thu, 01-Jan-1970 00:00:00 GMT"), ("Max-Age", "0")]))
-
- assert not cookies.is_expired(CA([("Expires", "Mon, 24-Aug-2037 00:00:00 GMT")]))
- assert not cookies.is_expired(CA([("Max-Age", "1")]))
- assert not cookies.is_expired(CA([("Expires", "Wed, 15-Jul-2037 00:00:00 GMT"), ("Max-Age", "1")]))
-
- assert not cookies.is_expired(CA([("Max-Age", "nan")]))
- assert not cookies.is_expired(CA([("Expires", "false")]))
-
-
-def test_group_cookies():
- CA = cookies.CookieAttrs
- groups = [
- [
- "one=uno; foo=bar; foo=baz",
- [
- ('one', 'uno', CA([])),
- ('foo', 'bar', CA([])),
- ('foo', 'baz', CA([]))
- ]
- ],
- [
- "one=uno; Path=/; foo=bar; Max-Age=0; foo=baz; expires=24-08-1993",
- [
- ('one', 'uno', CA([('Path', '/')])),
- ('foo', 'bar', CA([('Max-Age', '0')])),
- ('foo', 'baz', CA([('expires', '24-08-1993')]))
- ]
- ],
- [
- "one=uno;",
- [
- ('one', 'uno', CA([]))
- ]
- ],
- [
- "one=uno; Path=/; Max-Age=0; Expires=24-08-1993",
- [
- ('one', 'uno', CA([('Path', '/'), ('Max-Age', '0'), ('Expires', '24-08-1993')]))
- ]
- ],
- [
- "path=val; Path=/",
- [
- ('path', 'val', CA([('Path', '/')]))
- ]
- ]
- ]
-
- for c, expected in groups:
- observed = cookies.group_cookies(cookies.parse_cookie_header(c))
- assert observed == expected
diff --git a/test/netlib/http/test_encoding.py b/test/netlib/http/test_encoding.py
deleted file mode 100644
index 89600709..00000000
--- a/test/netlib/http/test_encoding.py
+++ /dev/null
@@ -1,73 +0,0 @@
-import mock
-import pytest
-
-from netlib.http import encoding
-from mitmproxy.test import tutils
-
-
-@pytest.mark.parametrize("encoder", [
- 'identity',
- 'none',
-])
-def test_identity(encoder):
- assert b"string" == encoding.decode(b"string", encoder)
- assert b"string" == encoding.encode(b"string", encoder)
- with tutils.raises(ValueError):
- encoding.encode(b"string", "nonexistent encoding")
-
-
-@pytest.mark.parametrize("encoder", [
- 'gzip',
- 'br',
- 'deflate',
-])
-def test_encoders(encoder):
- assert "" == encoding.decode("", encoder)
- assert b"" == encoding.decode(b"", encoder)
-
- assert "string" == encoding.decode(
- encoding.encode(
- "string",
- encoder
- ),
- encoder
- )
- assert b"string" == encoding.decode(
- encoding.encode(
- b"string",
- encoder
- ),
- encoder
- )
-
- with tutils.raises(ValueError):
- encoding.decode(b"foobar", encoder)
-
-
-def test_cache():
- decode_gzip = mock.MagicMock()
- decode_gzip.return_value = b"decoded"
- encode_gzip = mock.MagicMock()
- encode_gzip.return_value = b"encoded"
-
- with mock.patch.dict(encoding.custom_decode, gzip=decode_gzip):
- with mock.patch.dict(encoding.custom_encode, gzip=encode_gzip):
- assert encoding.decode(b"encoded", "gzip") == b"decoded"
- assert decode_gzip.call_count == 1
-
- # should be cached
- assert encoding.decode(b"encoded", "gzip") == b"decoded"
- assert decode_gzip.call_count == 1
-
- # the other way around as well
- assert encoding.encode(b"decoded", "gzip") == b"encoded"
- assert encode_gzip.call_count == 0
-
- # different encoding
- decode_gzip.return_value = b"bar"
- assert encoding.encode(b"decoded", "deflate") != b"decoded"
- assert encode_gzip.call_count == 0
-
- # This is not in the cache anymore
- assert encoding.encode(b"decoded", "gzip") == b"encoded"
- assert encode_gzip.call_count == 1
diff --git a/test/netlib/http/test_headers.py b/test/netlib/http/test_headers.py
deleted file mode 100644
index cac77d57..00000000
--- a/test/netlib/http/test_headers.py
+++ /dev/null
@@ -1,106 +0,0 @@
-import collections
-
-from netlib.http.headers import Headers, parse_content_type, assemble_content_type
-from mitmproxy.test.tutils import raises
-
-
-class TestHeaders:
- def _2host(self):
- return Headers(
- (
- (b"Host", b"example.com"),
- (b"host", b"example.org")
- )
- )
-
- def test_init(self):
- headers = Headers()
- assert len(headers) == 0
-
- headers = Headers([[b"Host", b"example.com"]])
- assert len(headers) == 1
- assert headers["Host"] == "example.com"
-
- headers = Headers(Host="example.com")
- assert len(headers) == 1
- assert headers["Host"] == "example.com"
-
- headers = Headers(
- [[b"Host", b"invalid"]],
- Host="example.com"
- )
- assert len(headers) == 1
- assert headers["Host"] == "example.com"
-
- headers = Headers(
- [[b"Host", b"invalid"], [b"Accept", b"text/plain"]],
- Host="example.com"
- )
- assert len(headers) == 2
- assert headers["Host"] == "example.com"
- assert headers["Accept"] == "text/plain"
-
- with raises(TypeError):
- Headers([[b"Host", u"not-bytes"]])
-
- def test_set(self):
- headers = Headers()
- headers[u"foo"] = u"1"
- headers[b"bar"] = b"2"
- headers["baz"] = b"3"
- with raises(TypeError):
- headers["foobar"] = 42
- assert len(headers) == 3
-
- def test_bytes(self):
- headers = Headers(Host="example.com")
- assert bytes(headers) == b"Host: example.com\r\n"
-
- headers = Headers([
- [b"Host", b"example.com"],
- [b"Accept", b"text/plain"]
- ])
- assert bytes(headers) == b"Host: example.com\r\nAccept: text/plain\r\n"
-
- headers = Headers()
- assert bytes(headers) == b""
-
- def test_replace_simple(self):
- headers = Headers(Host="example.com", Accept="text/plain")
- replacements = headers.replace("Host: ", "X-Host: ")
- assert replacements == 1
- assert headers["X-Host"] == "example.com"
- assert "Host" not in headers
- assert headers["Accept"] == "text/plain"
-
- def test_replace_multi(self):
- headers = self._2host()
- headers.replace(r"Host: example\.com", r"Host: example.de")
- assert headers.get_all("Host") == ["example.de", "example.org"]
-
- def test_replace_remove_spacer(self):
- headers = Headers(Host="example.com")
- replacements = headers.replace(r"Host: ", "X-Host ")
- assert replacements == 0
- assert headers["Host"] == "example.com"
-
- def test_replace_with_count(self):
- headers = Headers(Host="foobarfoo.com", Accept="foo/bar")
- replacements = headers.replace("foo", "bar", count=1)
- assert replacements == 1
-
-
-def test_parse_content_type():
- p = parse_content_type
- assert p("text/html") == ("text", "html", {})
- assert p("text") is None
-
- v = p("text/html; charset=UTF-8")
- assert v == ('text', 'html', {'charset': 'UTF-8'})
-
-
-def test_assemble_content_type():
- p = assemble_content_type
- assert p("text", "html", {}) == "text/html"
- assert p("text", "html", {"charset": "utf8"}) == "text/html; charset=utf8"
- assert p("text", "html", collections.OrderedDict([("charset", "utf8"), ("foo", "bar")])) == "text/html; charset=utf8; foo=bar"
diff --git a/test/netlib/http/test_message.py b/test/netlib/http/test_message.py
deleted file mode 100644
index 2bc8824f..00000000
--- a/test/netlib/http/test_message.py
+++ /dev/null
@@ -1,271 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from mitmproxy.test import tutils
-from netlib import http
-
-
-def _test_passthrough_attr(message, attr):
- assert getattr(message, attr) == getattr(message.data, attr)
- setattr(message, attr, b"foo")
- assert getattr(message.data, attr) == b"foo"
-
-
-def _test_decoded_attr(message, attr):
- assert getattr(message, attr) == getattr(message.data, attr).decode("utf8")
- # Set str, get raw bytes
- setattr(message, attr, "foo")
- assert getattr(message.data, attr) == b"foo"
- # Set raw bytes, get decoded
- setattr(message.data, attr, b"BAR") # use uppercase so that we can also cover request.method
- assert getattr(message, attr) == "BAR"
- # Set bytes, get raw bytes
- setattr(message, attr, b"baz")
- assert getattr(message.data, attr) == b"baz"
-
- # Set UTF8
- setattr(message, attr, "Non-Autorisé")
- assert getattr(message.data, attr) == b"Non-Autoris\xc3\xa9"
- # Don't fail on garbage
- setattr(message.data, attr, b"FOO\xBF\x00BAR")
- assert getattr(message, attr).startswith("FOO")
- assert getattr(message, attr).endswith("BAR")
- # foo.bar = foo.bar should not cause any side effects.
- d = getattr(message, attr)
- setattr(message, attr, d)
- assert getattr(message.data, attr) == b"FOO\xBF\x00BAR"
-
-
-class TestMessageData:
- def test_eq_ne(self):
- data = tutils.tresp(timestamp_start=42, timestamp_end=42).data
- same = tutils.tresp(timestamp_start=42, timestamp_end=42).data
- assert data == same
- assert not data != same
-
- other = tutils.tresp(content=b"foo").data
- assert not data == other
- assert data != other
-
- assert data != 0
-
-
-class TestMessage:
-
- def test_init(self):
- resp = tutils.tresp()
- assert resp.data
-
- def test_eq_ne(self):
- resp = tutils.tresp(timestamp_start=42, timestamp_end=42)
- same = tutils.tresp(timestamp_start=42, timestamp_end=42)
- assert resp == same
- assert not resp != same
-
- other = tutils.tresp(timestamp_start=0, timestamp_end=0)
- assert not resp == other
- assert resp != other
-
- assert resp != 0
-
- def test_serializable(self):
- resp = tutils.tresp()
- resp2 = http.Response.from_state(resp.get_state())
- assert resp == resp2
-
- def test_content_length_update(self):
- resp = tutils.tresp()
- resp.content = b"foo"
- assert resp.data.content == b"foo"
- assert resp.headers["content-length"] == "3"
- resp.content = b""
- assert resp.data.content == b""
- assert resp.headers["content-length"] == "0"
- resp.raw_content = b"bar"
- assert resp.data.content == b"bar"
- assert resp.headers["content-length"] == "0"
-
- def test_headers(self):
- _test_passthrough_attr(tutils.tresp(), "headers")
-
- def test_timestamp_start(self):
- _test_passthrough_attr(tutils.tresp(), "timestamp_start")
-
- def test_timestamp_end(self):
- _test_passthrough_attr(tutils.tresp(), "timestamp_end")
-
- def test_http_version(self):
- _test_decoded_attr(tutils.tresp(), "http_version")
-
- def test_replace(self):
- r = tutils.tresp()
- r.content = b"foofootoo"
- r.replace(b"foo", "gg")
- assert r.content == b"ggggtoo"
-
- r.content = b"foofootoo"
- r.replace(b"foo", "gg", count=1)
- assert r.content == b"ggfootoo"
-
-
-class TestMessageContentEncoding:
- def test_simple(self):
- r = tutils.tresp()
- assert r.raw_content == b"message"
- assert "content-encoding" not in r.headers
- r.encode("gzip")
-
- assert r.headers["content-encoding"]
- assert r.raw_content != b"message"
- assert r.content == b"message"
- assert r.raw_content != b"message"
-
- def test_modify(self):
- r = tutils.tresp()
- assert "content-encoding" not in r.headers
- r.encode("gzip")
-
- r.content = b"foo"
- assert r.raw_content != b"foo"
- r.decode()
- assert r.raw_content == b"foo"
-
- with tutils.raises(TypeError):
- r.content = u"foo"
-
- def test_unknown_ce(self):
- r = tutils.tresp()
- r.headers["content-encoding"] = "zopfli"
- r.raw_content = b"foo"
- with tutils.raises(ValueError):
- assert r.content
- assert r.headers["content-encoding"]
- assert r.get_content(strict=False) == b"foo"
-
- def test_cannot_decode(self):
- r = tutils.tresp()
- r.encode("gzip")
- r.raw_content = b"foo"
- with tutils.raises(ValueError):
- assert r.content
- assert r.headers["content-encoding"]
- assert r.get_content(strict=False) == b"foo"
-
- with tutils.raises(ValueError):
- r.decode()
- assert r.raw_content == b"foo"
- assert "content-encoding" in r.headers
-
- r.decode(strict=False)
- assert r.content == b"foo"
- assert "content-encoding" not in r.headers
-
- def test_none(self):
- r = tutils.tresp(content=None)
- assert r.content is None
- r.content = b"foo"
- assert r.content is not None
- r.content = None
- assert r.content is None
-
- def test_cannot_encode(self):
- r = tutils.tresp()
- r.encode("gzip")
- r.content = None
- assert r.headers["content-encoding"]
- assert r.raw_content is None
-
- r.headers["content-encoding"] = "zopfli"
- r.content = b"foo"
- assert "content-encoding" not in r.headers
- assert r.raw_content == b"foo"
-
- with tutils.raises(ValueError):
- r.encode("zopfli")
- assert r.raw_content == b"foo"
- assert "content-encoding" not in r.headers
-
-
-class TestMessageText:
- def test_simple(self):
- r = tutils.tresp(content=b'\xfc')
- assert r.raw_content == b"\xfc"
- assert r.content == b"\xfc"
- assert r.text == u"ü"
-
- r.encode("gzip")
- assert r.text == u"ü"
- r.decode()
- assert r.text == u"ü"
-
- r.headers["content-type"] = "text/html; charset=latin1"
- r.content = b"\xc3\xbc"
- assert r.text == u"ü"
- r.headers["content-type"] = "text/html; charset=utf8"
- assert r.text == u"ü"
-
- def test_guess_json(self):
- r = tutils.tresp(content=b'"\xc3\xbc"')
- r.headers["content-type"] = "application/json"
- assert r.text == u'"ü"'
-
- def test_none(self):
- r = tutils.tresp(content=None)
- assert r.text is None
- r.text = u"foo"
- assert r.text is not None
- r.text = None
- assert r.text is None
-
- def test_modify(self):
- r = tutils.tresp()
-
- r.text = u"ü"
- assert r.raw_content == b"\xfc"
-
- r.headers["content-type"] = "text/html; charset=utf8"
- r.text = u"ü"
- assert r.raw_content == b"\xc3\xbc"
- assert r.headers["content-length"] == "2"
-
- def test_unknown_ce(self):
- r = tutils.tresp()
- r.headers["content-type"] = "text/html; charset=wtf"
- r.raw_content = b"foo"
- with tutils.raises(ValueError):
- assert r.text == u"foo"
- assert r.get_text(strict=False) == u"foo"
-
- def test_cannot_decode(self):
- r = tutils.tresp()
- r.headers["content-type"] = "text/html; charset=utf8"
- r.raw_content = b"\xFF"
- with tutils.raises(ValueError):
- assert r.text
-
- assert r.get_text(strict=False) == '\udcff'
-
- def test_cannot_encode(self):
- r = tutils.tresp()
- r.content = None
- assert "content-type" not in r.headers
- assert r.raw_content is None
-
- r.headers["content-type"] = "text/html; charset=latin1; foo=bar"
- r.text = u"☃"
- assert r.headers["content-type"] == "text/html; charset=utf-8; foo=bar"
- assert r.raw_content == b'\xe2\x98\x83'
-
- r.headers["content-type"] = "gibberish"
- r.text = u"☃"
- assert r.headers["content-type"] == "text/plain; charset=utf-8"
- assert r.raw_content == b'\xe2\x98\x83'
-
- del r.headers["content-type"]
- r.text = u"☃"
- assert r.headers["content-type"] == "text/plain; charset=utf-8"
- assert r.raw_content == b'\xe2\x98\x83'
-
- r.headers["content-type"] = "text/html; charset=latin1"
- r.text = u'\udcff'
- assert r.headers["content-type"] == "text/html; charset=utf-8"
- assert r.raw_content == b"\xFF"
diff --git a/test/netlib/http/test_multipart.py b/test/netlib/http/test_multipart.py
deleted file mode 100644
index 1d7e0062..00000000
--- a/test/netlib/http/test_multipart.py
+++ /dev/null
@@ -1,24 +0,0 @@
-from netlib.http import Headers
-from netlib.http import multipart
-
-
-def test_decode():
- boundary = 'somefancyboundary'
- headers = Headers(
- content_type='multipart/form-data; boundary=' + boundary
- )
- content = (
- "--{0}\n"
- "Content-Disposition: form-data; name=\"field1\"\n\n"
- "value1\n"
- "--{0}\n"
- "Content-Disposition: form-data; name=\"field2\"\n\n"
- "value2\n"
- "--{0}--".format(boundary).encode()
- )
-
- form = multipart.decode(headers, content)
-
- assert len(form) == 2
- assert form[0] == (b"field1", b"value1")
- assert form[1] == (b"field2", b"value2")
diff --git a/test/netlib/http/test_request.py b/test/netlib/http/test_request.py
deleted file mode 100644
index ecfc1ba6..00000000
--- a/test/netlib/http/test_request.py
+++ /dev/null
@@ -1,271 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from netlib.http import Headers
-from mitmproxy.test.tutils import treq, raises
-from .test_message import _test_decoded_attr, _test_passthrough_attr
-
-
-class TestRequestData:
- def test_init(self):
- with raises(ValueError):
- treq(headers="foobar")
-
- assert isinstance(treq(headers=()).headers, Headers)
-
-
-class TestRequestCore:
- """
- Tests for addons and the attributes that are directly proxied from the data structure
- """
- def test_repr(self):
- request = treq()
- assert repr(request) == "Request(GET address:22/path)"
- request.host = None
- assert repr(request) == "Request(GET /path)"
-
- def replace(self):
- r = treq()
- r.path = b"foobarfoo"
- r.replace(b"foo", "bar")
- assert r.path == b"barbarbar"
-
- r.path = b"foobarfoo"
- r.replace(b"foo", "bar", count=1)
- assert r.path == b"barbarfoo"
-
- def test_first_line_format(self):
- _test_passthrough_attr(treq(), "first_line_format")
-
- def test_method(self):
- _test_decoded_attr(treq(), "method")
-
- def test_scheme(self):
- _test_decoded_attr(treq(), "scheme")
-
- def test_port(self):
- _test_passthrough_attr(treq(), "port")
-
- def test_path(self):
- req = treq()
- _test_decoded_attr(req, "path")
- # path can also be None.
- req.path = None
- assert req.path is None
- assert req.data.path is None
-
- def test_host(self):
- request = treq()
- assert request.host == request.data.host.decode("idna")
-
- # Test IDNA encoding
- # Set str, get raw bytes
- request.host = "ídna.example"
- assert request.data.host == b"xn--dna-qma.example"
- # Set raw bytes, get decoded
- request.data.host = b"xn--idn-gla.example"
- assert request.host == "idná.example"
- # Set bytes, get raw bytes
- request.host = b"xn--dn-qia9b.example"
- assert request.data.host == b"xn--dn-qia9b.example"
- # IDNA encoding is not bijective
- request.host = "fußball"
- assert request.host == "fussball"
-
- # Don't fail on garbage
- request.data.host = b"foo\xFF\x00bar"
- assert request.host.startswith("foo")
- assert request.host.endswith("bar")
- # foo.bar = foo.bar should not cause any side effects.
- d = request.host
- request.host = d
- assert request.data.host == b"foo\xFF\x00bar"
-
- def test_host_header_update(self):
- request = treq()
- assert "host" not in request.headers
- request.host = "example.com"
- assert "host" not in request.headers
-
- request.headers["Host"] = "foo"
- request.host = "example.org"
- assert request.headers["Host"] == "example.org"
-
-
-class TestRequestUtils:
- """
- Tests for additional convenience methods.
- """
- def test_url(self):
- request = treq()
- assert request.url == "http://address:22/path"
-
- request.url = "https://otheraddress:42/foo"
- assert request.scheme == "https"
- assert request.host == "otheraddress"
- assert request.port == 42
- assert request.path == "/foo"
-
- with raises(ValueError):
- request.url = "not-a-url"
-
- def test_url_options(self):
- request = treq(method=b"OPTIONS", path=b"*")
- assert request.url == "http://address:22"
-
- def test_url_authority(self):
- request = treq(first_line_format="authority")
- assert request.url == "address:22"
-
- def test_pretty_host(self):
- request = treq()
- # Without host header
- assert request.pretty_host == "address"
- assert request.host == "address"
- # Same port as self.port (22)
- request.headers["host"] = "other:22"
- assert request.pretty_host == "other"
- # Different ports
- request.headers["host"] = "other"
- assert request.pretty_host == "address"
- assert request.host == "address"
- # Empty host
- request.host = None
- assert request.pretty_host is None
- assert request.host is None
-
- # Invalid IDNA
- request.headers["host"] = ".disqus.com:22"
- assert request.pretty_host == ".disqus.com"
-
- def test_pretty_url(self):
- request = treq()
- # Without host header
- assert request.url == "http://address:22/path"
- assert request.pretty_url == "http://address:22/path"
- # Same port as self.port (22)
- request.headers["host"] = "other:22"
- assert request.pretty_url == "http://other:22/path"
- # Different ports
- request.headers["host"] = "other"
- assert request.pretty_url == "http://address:22/path"
-
- def test_pretty_url_options(self):
- request = treq(method=b"OPTIONS", path=b"*")
- assert request.pretty_url == "http://address:22"
-
- def test_pretty_url_authority(self):
- request = treq(first_line_format="authority")
- assert request.pretty_url == "address:22"
-
- def test_get_query(self):
- request = treq()
- assert not request.query
-
- request.url = "http://localhost:80/foo?bar=42"
- assert dict(request.query) == {"bar": "42"}
-
- def test_set_query(self):
- request = treq()
- assert not request.query
- request.query["foo"] = "bar"
- assert request.query["foo"] == "bar"
- assert request.path == "/path?foo=bar"
-
- def test_get_cookies_none(self):
- request = treq()
- request.headers = Headers()
- assert not request.cookies
-
- def test_get_cookies_single(self):
- request = treq()
- request.headers = Headers(cookie="cookiename=cookievalue")
- assert len(request.cookies) == 1
- assert request.cookies['cookiename'] == 'cookievalue'
-
- def test_get_cookies_double(self):
- request = treq()
- request.headers = Headers(cookie="cookiename=cookievalue;othercookiename=othercookievalue")
- result = request.cookies
- assert len(result) == 2
- assert result['cookiename'] == 'cookievalue'
- assert result['othercookiename'] == 'othercookievalue'
-
- def test_get_cookies_withequalsign(self):
- request = treq()
- request.headers = Headers(cookie="cookiename=coo=kievalue;othercookiename=othercookievalue")
- result = request.cookies
- assert len(result) == 2
- assert result['cookiename'] == 'coo=kievalue'
- assert result['othercookiename'] == 'othercookievalue'
-
- def test_set_cookies(self):
- request = treq()
- request.headers = Headers(cookie="cookiename=cookievalue")
- result = request.cookies
- result["cookiename"] = "foo"
- assert request.cookies["cookiename"] == "foo"
-
- def test_get_path_components(self):
- request = treq(path=b"/foo/bar")
- assert request.path_components == ("foo", "bar")
-
- def test_set_path_components(self):
- request = treq()
- request.path_components = ["foo", "baz"]
- assert request.path == "/foo/baz"
-
- request.path_components = []
- assert request.path == "/"
-
- request.path_components = ["foo", "baz"]
- request.query["hello"] = "hello"
- assert request.path_components == ("foo", "baz")
-
- request.path_components = ["abc"]
- assert request.path == "/abc?hello=hello"
-
- def test_anticache(self):
- request = treq()
- request.headers["If-Modified-Since"] = "foo"
- request.headers["If-None-Match"] = "bar"
- request.anticache()
- assert "If-Modified-Since" not in request.headers
- assert "If-None-Match" not in request.headers
-
- def test_anticomp(self):
- request = treq()
- request.headers["Accept-Encoding"] = "foobar"
- request.anticomp()
- assert request.headers["Accept-Encoding"] == "identity"
-
- def test_constrain_encoding(self):
- request = treq()
-
- h = request.headers.copy()
- request.constrain_encoding() # no-op if there is no accept_encoding header.
- assert request.headers == h
-
- request.headers["Accept-Encoding"] = "identity, gzip, foo"
- request.constrain_encoding()
- assert "foo" not in request.headers["Accept-Encoding"]
- assert "gzip" in request.headers["Accept-Encoding"]
-
- def test_get_urlencoded_form(self):
- request = treq(content=b"foobar=baz")
- assert not request.urlencoded_form
-
- request.headers["Content-Type"] = "application/x-www-form-urlencoded"
- assert list(request.urlencoded_form.items()) == [(b"foobar", b"baz")]
-
- def test_set_urlencoded_form(self):
- request = treq()
- request.urlencoded_form = [(b'foo', b'bar'), (b'rab', b'oof')]
- assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"
- assert request.content
-
- def test_get_multipart_form(self):
- request = treq(content=b"foobar")
- assert not request.multipart_form
-
- request.headers["Content-Type"] = "multipart/form-data"
- assert list(request.multipart_form.items()) == []
diff --git a/test/netlib/http/test_response.py b/test/netlib/http/test_response.py
deleted file mode 100644
index 4a6fac62..00000000
--- a/test/netlib/http/test_response.py
+++ /dev/null
@@ -1,145 +0,0 @@
-import email
-
-import time
-
-from netlib.http import Headers
-from netlib.http import Response
-from netlib.http.cookies import CookieAttrs
-from mitmproxy.test.tutils import raises, tresp
-from .test_message import _test_passthrough_attr, _test_decoded_attr
-
-
-class TestResponseData:
- def test_init(self):
- with raises(ValueError):
- tresp(headers="foobar")
-
- assert isinstance(tresp(headers=()).headers, Headers)
-
-
-class TestResponseCore:
- """
- Tests for addons and the attributes that are directly proxied from the data structure
- """
- def test_repr(self):
- response = tresp()
- assert repr(response) == "Response(200 OK, unknown content type, 7b)"
- response.content = None
- assert repr(response) == "Response(200 OK, no content)"
-
- def test_make(self):
- r = Response.make()
- assert r.status_code == 200
- assert r.content == b""
-
- r = Response.make(418, "teatime")
- assert r.status_code == 418
- assert r.content == b"teatime"
- assert r.headers["content-length"] == "7"
-
- Response.make(content=b"foo")
- Response.make(content="foo")
- with raises(TypeError):
- Response.make(content=42)
-
- r = Response.make(headers=[(b"foo", b"bar")])
- assert r.headers["foo"] == "bar"
-
- r = Response.make(headers=({"foo": "baz"}))
- assert r.headers["foo"] == "baz"
-
- with raises(TypeError):
- Response.make(headers=42)
-
- def test_status_code(self):
- _test_passthrough_attr(tresp(), "status_code")
-
- def test_reason(self):
- _test_decoded_attr(tresp(), "reason")
-
-
-class TestResponseUtils:
- """
- Tests for additional convenience methods.
- """
- def test_get_cookies_none(self):
- resp = tresp()
- resp.headers = Headers()
- assert not resp.cookies
-
- def test_get_cookies_empty(self):
- resp = tresp()
- resp.headers = Headers(set_cookie="")
- assert not resp.cookies
-
- def test_get_cookies_simple(self):
- resp = tresp()
- resp.headers = Headers(set_cookie="cookiename=cookievalue")
- result = resp.cookies
- assert len(result) == 1
- assert "cookiename" in result
- assert result["cookiename"] == ("cookievalue", CookieAttrs())
-
- def test_get_cookies_with_parameters(self):
- resp = tresp()
- cookie = "cookiename=cookievalue;domain=example.com;expires=Wed Oct 21 16:29:41 2015;path=/; HttpOnly"
- resp.headers = Headers(set_cookie=cookie)
- result = resp.cookies
- assert len(result) == 1
- assert "cookiename" in result
- assert result["cookiename"][0] == "cookievalue"
- attrs = result["cookiename"][1]
- assert len(attrs) == 4
- assert attrs["domain"] == "example.com"
- assert attrs["expires"] == "Wed Oct 21 16:29:41 2015"
- assert attrs["path"] == "/"
- assert attrs["httponly"] is None
-
- def test_get_cookies_no_value(self):
- resp = tresp()
- resp.headers = Headers(set_cookie="cookiename=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/")
- result = resp.cookies
- assert len(result) == 1
- assert "cookiename" in result
- assert result["cookiename"][0] == ""
- assert len(result["cookiename"][1]) == 2
-
- def test_get_cookies_twocookies(self):
- resp = tresp()
- resp.headers = Headers([
- [b"Set-Cookie", b"cookiename=cookievalue"],
- [b"Set-Cookie", b"othercookie=othervalue"]
- ])
- result = resp.cookies
- assert len(result) == 2
- assert "cookiename" in result
- assert result["cookiename"] == ("cookievalue", CookieAttrs())
- assert "othercookie" in result
- assert result["othercookie"] == ("othervalue", CookieAttrs())
-
- def test_set_cookies(self):
- resp = tresp()
- resp.cookies["foo"] = ("bar", {})
-
- assert len(resp.cookies) == 1
- assert resp.cookies["foo"] == ("bar", CookieAttrs())
-
- def test_refresh(self):
- r = tresp()
- n = time.time()
- r.headers["date"] = email.utils.formatdate(n)
- pre = r.headers["date"]
- r.refresh(n)
- assert pre == r.headers["date"]
- r.refresh(n + 60)
-
- d = email.utils.parsedate_tz(r.headers["date"])
- d = email.utils.mktime_tz(d)
- # Weird that this is not exact...
- assert abs(60 - (d - n)) <= 1
-
- cookie = "MOO=BAR; Expires=Tue, 08-Mar-2011 00:20:38 GMT; Path=foo.com; Secure"
- r.headers["set-cookie"] = cookie
- r.refresh()
- # Cookie refreshing is tested in test_cookies, we just make sure that it's triggered here.
- assert cookie != r.headers["set-cookie"]
diff --git a/test/netlib/http/test_status_codes.py b/test/netlib/http/test_status_codes.py
deleted file mode 100644
index 9fea6b70..00000000
--- a/test/netlib/http/test_status_codes.py
+++ /dev/null
@@ -1,6 +0,0 @@
-from netlib.http import status_codes
-
-
-def test_simple():
- assert status_codes.IM_A_TEAPOT == 418
- assert status_codes.RESPONSES[418] == "I'm a teapot"
diff --git a/test/netlib/http/test_url.py b/test/netlib/http/test_url.py
deleted file mode 100644
index 7cea6c58..00000000
--- a/test/netlib/http/test_url.py
+++ /dev/null
@@ -1,102 +0,0 @@
-from mitmproxy.test import tutils
-from netlib.http import url
-
-
-def test_parse():
- with tutils.raises(ValueError):
- url.parse("")
-
- s, h, po, pa = url.parse(b"http://foo.com:8888/test")
- assert s == b"http"
- assert h == b"foo.com"
- assert po == 8888
- assert pa == b"/test"
-
- s, h, po, pa = url.parse("http://foo/bar")
- assert s == b"http"
- assert h == b"foo"
- assert po == 80
- assert pa == b"/bar"
-
- s, h, po, pa = url.parse(b"http://user:pass@foo/bar")
- assert s == b"http"
- assert h == b"foo"
- assert po == 80
- assert pa == b"/bar"
-
- s, h, po, pa = url.parse(b"http://foo")
- assert pa == b"/"
-
- s, h, po, pa = url.parse(b"https://foo")
- assert po == 443
-
- with tutils.raises(ValueError):
- url.parse(b"https://foo:bar")
-
- # Invalid IDNA
- with tutils.raises(ValueError):
- url.parse("http://\xfafoo")
- # Invalid PATH
- with tutils.raises(ValueError):
- url.parse("http:/\xc6/localhost:56121")
- # Null byte in host
- with tutils.raises(ValueError):
- url.parse("http://foo\0")
- # Port out of range
- _, _, port, _ = url.parse("http://foo:999999")
- assert port == 80
- # Invalid IPv6 URL - see http://www.ietf.org/rfc/rfc2732.txt
- with tutils.raises(ValueError):
- url.parse('http://lo[calhost')
-
-
-def test_unparse():
- assert url.unparse("http", "foo.com", 99, "") == "http://foo.com:99"
- assert url.unparse("http", "foo.com", 80, "/bar") == "http://foo.com/bar"
- assert url.unparse("https", "foo.com", 80, "") == "https://foo.com:80"
- assert url.unparse("https", "foo.com", 443, "") == "https://foo.com"
-
-
-surrogates = bytes(range(256)).decode("utf8", "surrogateescape")
-
-surrogates_quoted = (
- '%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F'
- '%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F'
- '%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-./'
- '0123456789%3A%3B%3C%3D%3E%3F'
- '%40ABCDEFGHIJKLMNO'
- 'PQRSTUVWXYZ%5B%5C%5D%5E_'
- '%60abcdefghijklmno'
- 'pqrstuvwxyz%7B%7C%7D%7E%7F'
- '%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F'
- '%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F'
- '%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF'
- '%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF'
- '%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF'
- '%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF'
- '%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF'
- '%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF'
-)
-
-
-def test_encode():
- assert url.encode([('foo', 'bar')])
- assert url.encode([('foo', surrogates)])
-
-
-def test_decode():
- s = "one=two&three=four"
- assert len(url.decode(s)) == 2
- assert url.decode(surrogates)
-
-
-def test_quote():
- assert url.quote("foo") == "foo"
- assert url.quote("foo bar") == "foo%20bar"
- assert url.quote(surrogates) == surrogates_quoted
-
-
-def test_unquote():
- assert url.unquote("foo") == "foo"
- assert url.unquote("foo%20bar") == "foo bar"
- assert url.unquote(surrogates_quoted) == surrogates
diff --git a/test/netlib/http/test_user_agents.py b/test/netlib/http/test_user_agents.py
deleted file mode 100644
index 0bf1bba7..00000000
--- a/test/netlib/http/test_user_agents.py
+++ /dev/null
@@ -1,6 +0,0 @@
-from netlib.http import user_agents
-
-
-def test_get_shortcut():
- assert user_agents.get_by_shortcut("c")[0] == "chrome"
- assert not user_agents.get_by_shortcut("_")
diff --git a/test/netlib/test_check.py b/test/netlib/test_check.py
deleted file mode 100644
index 6a1388f4..00000000
--- a/test/netlib/test_check.py
+++ /dev/null
@@ -1,10 +0,0 @@
-# coding=utf-8
-
-from netlib import check
-
-
-def test_is_valid_host():
- assert not check.is_valid_host(b"")
- assert check.is_valid_host(b"one.two")
- assert not check.is_valid_host(b"one" * 255)
- assert check.is_valid_host(b"one.two.")
diff --git a/test/netlib/test_imports.py b/test/netlib/test_imports.py
deleted file mode 100644
index b88ef26d..00000000
--- a/test/netlib/test_imports.py
+++ /dev/null
@@ -1 +0,0 @@
-# These are actually tests!
diff --git a/test/netlib/test_socks.py b/test/netlib/test_socks.py
deleted file mode 100644
index 0603f34b..00000000
--- a/test/netlib/test_socks.py
+++ /dev/null
@@ -1,189 +0,0 @@
-import ipaddress
-from io import BytesIO
-from netlib import socks
-from netlib import tcp
-from mitmproxy.test import tutils
-
-
-def test_client_greeting():
- raw = tutils.treader(b"\x05\x02\x00\xBE\xEF")
- out = BytesIO()
- msg = socks.ClientGreeting.from_file(raw)
- msg.assert_socks5()
- msg.to_file(out)
-
- assert out.getvalue() == raw.getvalue()[:-1]
- assert msg.ver == 5
- assert len(msg.methods) == 2
- assert 0xBE in msg.methods
- assert 0xEF not in msg.methods
-
-
-def test_client_greeting_assert_socks5():
- raw = tutils.treader(b"\x00\x00")
- msg = socks.ClientGreeting.from_file(raw)
- tutils.raises(socks.SocksError, msg.assert_socks5)
-
- raw = tutils.treader(b"HTTP/1.1 200 OK" + b" " * 100)
- msg = socks.ClientGreeting.from_file(raw)
- try:
- msg.assert_socks5()
- except socks.SocksError as e:
- assert "Invalid SOCKS version" in str(e)
- assert "HTTP" not in str(e)
- else:
- assert False
-
- raw = tutils.treader(b"GET / HTTP/1.1" + b" " * 100)
- msg = socks.ClientGreeting.from_file(raw)
- try:
- msg.assert_socks5()
- except socks.SocksError as e:
- assert "Invalid SOCKS version" in str(e)
- assert "HTTP" in str(e)
- else:
- assert False
-
- raw = tutils.treader(b"XX")
- tutils.raises(
- socks.SocksError,
- socks.ClientGreeting.from_file,
- raw,
- fail_early=True)
-
-
-def test_server_greeting():
- raw = tutils.treader(b"\x05\x02")
- out = BytesIO()
- msg = socks.ServerGreeting.from_file(raw)
- msg.assert_socks5()
- msg.to_file(out)
-
- assert out.getvalue() == raw.getvalue()
- assert msg.ver == 5
- assert msg.method == 0x02
-
-
-def test_server_greeting_assert_socks5():
- raw = tutils.treader(b"HTTP/1.1 200 OK" + b" " * 100)
- msg = socks.ServerGreeting.from_file(raw)
- try:
- msg.assert_socks5()
- except socks.SocksError as e:
- assert "Invalid SOCKS version" in str(e)
- assert "HTTP" in str(e)
- else:
- assert False
-
- raw = tutils.treader(b"GET / HTTP/1.1" + b" " * 100)
- msg = socks.ServerGreeting.from_file(raw)
- try:
- msg.assert_socks5()
- except socks.SocksError as e:
- assert "Invalid SOCKS version" in str(e)
- assert "HTTP" not in str(e)
- else:
- assert False
-
-
-def test_username_password_auth():
- raw = tutils.treader(b"\x01\x03usr\x03psd\xBE\xEF")
- out = BytesIO()
- auth = socks.UsernamePasswordAuth.from_file(raw)
- auth.assert_authver1()
- assert raw.read(2) == b"\xBE\xEF"
- auth.to_file(out)
-
- assert out.getvalue() == raw.getvalue()[:-2]
- assert auth.ver == socks.USERNAME_PASSWORD_VERSION.DEFAULT
- assert auth.username == "usr"
- assert auth.password == "psd"
-
-
-def test_username_password_auth_assert_ver1():
- raw = tutils.treader(b"\x02\x03usr\x03psd\xBE\xEF")
- auth = socks.UsernamePasswordAuth.from_file(raw)
- tutils.raises(socks.SocksError, auth.assert_authver1)
-
-
-def test_username_password_auth_response():
- raw = tutils.treader(b"\x01\x00\xBE\xEF")
- out = BytesIO()
- auth = socks.UsernamePasswordAuthResponse.from_file(raw)
- auth.assert_authver1()
- assert raw.read(2) == b"\xBE\xEF"
- auth.to_file(out)
-
- assert out.getvalue() == raw.getvalue()[:-2]
- assert auth.ver == socks.USERNAME_PASSWORD_VERSION.DEFAULT
- assert auth.status == 0
-
-
-def test_username_password_auth_response_auth_assert_ver1():
- raw = tutils.treader(b"\x02\x00\xBE\xEF")
- auth = socks.UsernamePasswordAuthResponse.from_file(raw)
- tutils.raises(socks.SocksError, auth.assert_authver1)
-
-
-def test_message():
- raw = tutils.treader(b"\x05\x01\x00\x03\x0bexample.com\xDE\xAD\xBE\xEF")
- out = BytesIO()
- msg = socks.Message.from_file(raw)
- msg.assert_socks5()
- assert raw.read(2) == b"\xBE\xEF"
- msg.to_file(out)
-
- assert out.getvalue() == raw.getvalue()[:-2]
- assert msg.ver == 5
- assert msg.msg == 0x01
- assert msg.atyp == 0x03
- assert msg.addr == ("example.com", 0xDEAD)
-
-
-def test_message_assert_socks5():
- raw = tutils.treader(b"\xEE\x01\x00\x03\x0bexample.com\xDE\xAD\xBE\xEF")
- msg = socks.Message.from_file(raw)
- tutils.raises(socks.SocksError, msg.assert_socks5)
-
-
-def test_message_ipv4():
- # Test ATYP=0x01 (IPV4)
- raw = tutils.treader(b"\x05\x01\x00\x01\x7f\x00\x00\x01\xDE\xAD\xBE\xEF")
- out = BytesIO()
- msg = socks.Message.from_file(raw)
- left = raw.read(2)
- assert left == b"\xBE\xEF"
- msg.to_file(out)
-
- assert out.getvalue() == raw.getvalue()[:-2]
- assert msg.addr == ("127.0.0.1", 0xDEAD)
-
-
-def test_message_ipv6():
- # Test ATYP=0x04 (IPV6)
- ipv6_addr = u"2001:db8:85a3:8d3:1319:8a2e:370:7344"
-
- raw = tutils.treader(
- b"\x05\x01\x00\x04" +
- ipaddress.IPv6Address(ipv6_addr).packed +
- b"\xDE\xAD\xBE\xEF")
- out = BytesIO()
- msg = socks.Message.from_file(raw)
- assert raw.read(2) == b"\xBE\xEF"
- msg.to_file(out)
-
- assert out.getvalue() == raw.getvalue()[:-2]
- assert msg.addr.host == ipv6_addr
-
-
-def test_message_invalid_rsv():
- raw = tutils.treader(b"\x05\x01\xFF\x01\x7f\x00\x00\x01\xDE\xAD\xBE\xEF")
- tutils.raises(socks.SocksError, socks.Message.from_file, raw)
-
-
-def test_message_unknown_atyp():
- raw = tutils.treader(b"\x05\x02\x00\x02\x7f\x00\x00\x01\xDE\xAD\xBE\xEF")
- tutils.raises(socks.SocksError, socks.Message.from_file, raw)
-
- m = socks.Message(5, 1, 0x02, tcp.Address(("example.com", 5050)))
- tutils.raises(socks.SocksError, m.to_file, BytesIO())
diff --git a/test/netlib/test_tcp.py b/test/netlib/test_tcp.py
deleted file mode 100644
index 594ee21c..00000000
--- a/test/netlib/test_tcp.py
+++ /dev/null
@@ -1,802 +0,0 @@
-from io import BytesIO
-import queue
-import time
-import socket
-import random
-import os
-import threading
-import mock
-
-from OpenSSL import SSL
-
-from mitmproxy import certs
-from netlib import tcp
-from mitmproxy.test import tutils
-from mitmproxy import exceptions
-
-from . import tservers
-
-
-class EchoHandler(tcp.BaseHandler):
- sni = None
-
- def handle_sni(self, connection):
- self.sni = connection.get_servername()
-
- def handle(self):
- v = self.rfile.readline()
- self.wfile.write(v)
- self.wfile.flush()
-
-
-class ClientCipherListHandler(tcp.BaseHandler):
- sni = None
-
- def handle(self):
- self.wfile.write("%s" % self.connection.get_cipher_list())
- self.wfile.flush()
-
-
-class HangHandler(tcp.BaseHandler):
-
- def handle(self):
- # Hang as long as the client connection is alive
- while True:
- try:
- self.connection.setblocking(0)
- ret = self.connection.recv(1)
- # Client connection is dead...
- if ret == "" or ret == b"":
- return
- except socket.error:
- pass
- except SSL.WantReadError:
- pass
- except Exception:
- return
- time.sleep(0.1)
-
-
-class ALPNHandler(tcp.BaseHandler):
- sni = None
-
- def handle(self):
- alp = self.get_alpn_proto_negotiated()
- if alp:
- self.wfile.write(alp)
- else:
- self.wfile.write(b"NONE")
- self.wfile.flush()
-
-
-class TestServer(tservers.ServerTestBase):
- handler = EchoHandler
-
- def test_echo(self):
- testval = b"echo!\n"
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.wfile.write(testval)
- c.wfile.flush()
- assert c.rfile.readline() == testval
-
- def test_thread_start_error(self):
- with mock.patch.object(threading.Thread, "start", side_effect=threading.ThreadError("nonewthread")) as m:
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- assert not c.rfile.read(1)
- assert m.called
- assert "nonewthread" in self.q.get_nowait()
- self.test_echo()
-
-
-class TestServerBind(tservers.ServerTestBase):
-
- class handler(tcp.BaseHandler):
-
- def handle(self):
- self.wfile.write(str(self.connection.getpeername()).encode())
- self.wfile.flush()
-
- def test_bind(self):
- """ Test to bind to a given random port. Try again if the random port turned out to be blocked. """
- for i in range(20):
- random_port = random.randrange(1024, 65535)
- try:
- c = tcp.TCPClient(
- ("127.0.0.1", self.port), source_address=(
- "127.0.0.1", random_port))
- with c.connect():
- assert c.rfile.readline() == str(("127.0.0.1", random_port)).encode()
- return
- except exceptions.TcpException: # port probably already in use
- pass
-
-
-class TestServerIPv6(tservers.ServerTestBase):
- handler = EchoHandler
- addr = tcp.Address(("localhost", 0), use_ipv6=True)
-
- def test_echo(self):
- testval = b"echo!\n"
- c = tcp.TCPClient(tcp.Address(("::1", self.port), use_ipv6=True))
- with c.connect():
- c.wfile.write(testval)
- c.wfile.flush()
- assert c.rfile.readline() == testval
-
-
-class TestEcho(tservers.ServerTestBase):
- handler = EchoHandler
-
- def test_echo(self):
- testval = b"echo!\n"
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.wfile.write(testval)
- c.wfile.flush()
- assert c.rfile.readline() == testval
-
-
-class HardDisconnectHandler(tcp.BaseHandler):
-
- def handle(self):
- self.connection.close()
-
-
-class TestFinishFail(tservers.ServerTestBase):
-
- """
- This tests a difficult-to-trigger exception in the .finish() method of
- the handler.
- """
- handler = EchoHandler
-
- def test_disconnect_in_finish(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.wfile.write(b"foo\n")
- c.wfile.flush = mock.Mock(side_effect=exceptions.TcpDisconnect)
- c.finish()
-
-
-class TestServerSSL(tservers.ServerTestBase):
- handler = EchoHandler
- ssl = dict(
- cipher_list="AES256-SHA",
- chain_file=tutils.test_data.path("data/server.crt")
- )
-
- def test_echo(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(sni="foo.com", options=SSL.OP_ALL)
- testval = b"echo!\n"
- c.wfile.write(testval)
- c.wfile.flush()
- assert c.rfile.readline() == testval
-
- def test_get_current_cipher(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- assert not c.get_current_cipher()
- c.convert_to_ssl(sni="foo.com")
- ret = c.get_current_cipher()
- assert ret
- assert "AES" in ret[0]
-
-
-class TestSSLv3Only(tservers.ServerTestBase):
- handler = EchoHandler
- ssl = dict(
- request_client_cert=False,
- v3_only=True
- )
-
- def test_failure(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- tutils.raises(exceptions.TlsException, c.convert_to_ssl, sni="foo.com")
-
-
-class TestSSLUpstreamCertVerificationWBadServerCert(tservers.ServerTestBase):
- handler = EchoHandler
-
- ssl = dict(
- cert=tutils.test_data.path("data/verificationcerts/self-signed.crt"),
- key=tutils.test_data.path("data/verificationcerts/self-signed.key")
- )
-
- def test_mode_default_should_pass(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl()
-
- # Verification errors should be saved even if connection isn't aborted
- # aborted
- assert c.ssl_verification_error
-
- testval = b"echo!\n"
- c.wfile.write(testval)
- c.wfile.flush()
- assert c.rfile.readline() == testval
-
- def test_mode_none_should_pass(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(verify_options=SSL.VERIFY_NONE)
-
- # Verification errors should be saved even if connection isn't aborted
- assert c.ssl_verification_error
-
- testval = b"echo!\n"
- c.wfile.write(testval)
- c.wfile.flush()
- assert c.rfile.readline() == testval
-
- def test_mode_strict_should_fail(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- with tutils.raises(exceptions.InvalidCertificateException):
- c.convert_to_ssl(
- sni="example.mitmproxy.org",
- verify_options=SSL.VERIFY_PEER,
- ca_pemfile=tutils.test_data.path("data/verificationcerts/trusted-root.crt")
- )
-
- assert c.ssl_verification_error
-
- # Unknown issuing certificate authority for first certificate
- assert "errno: 18" in str(c.ssl_verification_error)
- assert "depth: 0" in str(c.ssl_verification_error)
-
-
-class TestSSLUpstreamCertVerificationWBadHostname(tservers.ServerTestBase):
- handler = EchoHandler
-
- ssl = dict(
- cert=tutils.test_data.path("data/verificationcerts/trusted-leaf.crt"),
- key=tutils.test_data.path("data/verificationcerts/trusted-leaf.key")
- )
-
- def test_should_fail_without_sni(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- with tutils.raises(exceptions.TlsException):
- c.convert_to_ssl(
- verify_options=SSL.VERIFY_PEER,
- ca_pemfile=tutils.test_data.path("data/verificationcerts/trusted-root.crt")
- )
-
- def test_should_fail(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- with tutils.raises(exceptions.InvalidCertificateException):
- c.convert_to_ssl(
- sni="mitmproxy.org",
- verify_options=SSL.VERIFY_PEER,
- ca_pemfile=tutils.test_data.path("data/verificationcerts/trusted-root.crt")
- )
- assert c.ssl_verification_error
-
-
-class TestSSLUpstreamCertVerificationWValidCertChain(tservers.ServerTestBase):
- handler = EchoHandler
-
- ssl = dict(
- cert=tutils.test_data.path("data/verificationcerts/trusted-leaf.crt"),
- key=tutils.test_data.path("data/verificationcerts/trusted-leaf.key")
- )
-
- def test_mode_strict_w_pemfile_should_pass(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(
- sni="example.mitmproxy.org",
- verify_options=SSL.VERIFY_PEER,
- ca_pemfile=tutils.test_data.path("data/verificationcerts/trusted-root.crt")
- )
-
- assert c.ssl_verification_error is None
-
- testval = b"echo!\n"
- c.wfile.write(testval)
- c.wfile.flush()
- assert c.rfile.readline() == testval
-
- def test_mode_strict_w_cadir_should_pass(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(
- sni="example.mitmproxy.org",
- verify_options=SSL.VERIFY_PEER,
- ca_path=tutils.test_data.path("data/verificationcerts/")
- )
-
- assert c.ssl_verification_error is None
-
- testval = b"echo!\n"
- c.wfile.write(testval)
- c.wfile.flush()
- assert c.rfile.readline() == testval
-
-
-class TestSSLClientCert(tservers.ServerTestBase):
-
- class handler(tcp.BaseHandler):
- sni = None
-
- def handle_sni(self, connection):
- self.sni = connection.get_servername()
-
- def handle(self):
- self.wfile.write(b"%d\n" % self.clientcert.serial)
- self.wfile.flush()
-
- ssl = dict(
- request_client_cert=True,
- v3_only=False
- )
-
- def test_clientcert(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(
- cert=tutils.test_data.path("data/clientcert/client.pem"))
- assert c.rfile.readline().strip() == b"1"
-
- def test_clientcert_err(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- tutils.raises(
- exceptions.TlsException,
- c.convert_to_ssl,
- cert=tutils.test_data.path("data/clientcert/make")
- )
-
-
-class TestSNI(tservers.ServerTestBase):
-
- class handler(tcp.BaseHandler):
- sni = None
-
- def handle_sni(self, connection):
- self.sni = connection.get_servername()
-
- def handle(self):
- self.wfile.write(self.sni)
- self.wfile.flush()
-
- ssl = True
-
- def test_echo(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(sni="foo.com")
- assert c.sni == "foo.com"
- assert c.rfile.readline() == b"foo.com"
-
-
-class TestServerCipherList(tservers.ServerTestBase):
- handler = ClientCipherListHandler
- ssl = dict(
- cipher_list='RC4-SHA'
- )
-
- def test_echo(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(sni="foo.com")
- assert c.rfile.readline() == b"['RC4-SHA']"
-
-
-class TestServerCurrentCipher(tservers.ServerTestBase):
-
- class handler(tcp.BaseHandler):
- sni = None
-
- def handle(self):
- self.wfile.write(str(self.get_current_cipher()).encode())
- self.wfile.flush()
-
- ssl = dict(
- cipher_list='RC4-SHA'
- )
-
- def test_echo(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(sni="foo.com")
- assert b"RC4-SHA" in c.rfile.readline()
-
-
-class TestServerCipherListError(tservers.ServerTestBase):
- handler = ClientCipherListHandler
- ssl = dict(
- cipher_list='bogus'
- )
-
- def test_echo(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- tutils.raises("handshake error", c.convert_to_ssl, sni="foo.com")
-
-
-class TestClientCipherListError(tservers.ServerTestBase):
- handler = ClientCipherListHandler
- ssl = dict(
- cipher_list='RC4-SHA'
- )
-
- def test_echo(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- tutils.raises(
- "cipher specification",
- c.convert_to_ssl,
- sni="foo.com",
- cipher_list="bogus"
- )
-
-
-class TestSSLDisconnect(tservers.ServerTestBase):
-
- class handler(tcp.BaseHandler):
-
- def handle(self):
- self.finish()
-
- ssl = True
-
- def test_echo(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl()
- # Excercise SSL.ZeroReturnError
- c.rfile.read(10)
- c.close()
- tutils.raises(exceptions.TcpDisconnect, c.wfile.write, b"foo")
- tutils.raises(queue.Empty, self.q.get_nowait)
-
-
-class TestSSLHardDisconnect(tservers.ServerTestBase):
- handler = HardDisconnectHandler
- ssl = True
-
- def test_echo(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl()
- # Exercise SSL.SysCallError
- c.rfile.read(10)
- c.close()
- tutils.raises(exceptions.TcpDisconnect, c.wfile.write, b"foo")
-
-
-class TestDisconnect(tservers.ServerTestBase):
-
- def test_echo(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.rfile.read(10)
- c.wfile.write(b"foo")
- c.close()
- c.close()
-
-
-class TestServerTimeOut(tservers.ServerTestBase):
-
- class handler(tcp.BaseHandler):
-
- def handle(self):
- self.timeout = False
- self.settimeout(0.01)
- try:
- self.rfile.read(10)
- except exceptions.TcpTimeout:
- self.timeout = True
-
- def test_timeout(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- time.sleep(0.3)
- assert self.last_handler.timeout
-
-
-class TestTimeOut(tservers.ServerTestBase):
- handler = HangHandler
-
- def test_timeout(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.settimeout(0.1)
- assert c.gettimeout() == 0.1
- tutils.raises(exceptions.TcpTimeout, c.rfile.read, 10)
-
-
-class TestALPNClient(tservers.ServerTestBase):
- handler = ALPNHandler
- ssl = dict(
- alpn_select=b"bar"
- )
-
- if tcp.HAS_ALPN:
- def test_alpn(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(alpn_protos=[b"foo", b"bar", b"fasel"])
- assert c.get_alpn_proto_negotiated() == b"bar"
- assert c.rfile.readline().strip() == b"bar"
-
- def test_no_alpn(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl()
- assert c.get_alpn_proto_negotiated() == b""
- assert c.rfile.readline().strip() == b"NONE"
-
- else:
- def test_none_alpn(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl(alpn_protos=[b"foo", b"bar", b"fasel"])
- assert c.get_alpn_proto_negotiated() == b""
- assert c.rfile.readline() == b"NONE"
-
-
-class TestNoSSLNoALPNClient(tservers.ServerTestBase):
- handler = ALPNHandler
-
- def test_no_ssl_no_alpn(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- assert c.get_alpn_proto_negotiated() == b""
- assert c.rfile.readline().strip() == b"NONE"
-
-
-class TestSSLTimeOut(tservers.ServerTestBase):
- handler = HangHandler
- ssl = True
-
- def test_timeout_client(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl()
- c.settimeout(0.1)
- tutils.raises(exceptions.TcpTimeout, c.rfile.read, 10)
-
-
-class TestDHParams(tservers.ServerTestBase):
- handler = HangHandler
- ssl = dict(
- dhparams=certs.CertStore.load_dhparam(
- tutils.test_data.path("data/dhparam.pem"),
- ),
- cipher_list="DHE-RSA-AES256-SHA"
- )
-
- def test_dhparams(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl()
- ret = c.get_current_cipher()
- assert ret[0] == "DHE-RSA-AES256-SHA"
-
- def test_create_dhparams(self):
- with tutils.tmpdir() as d:
- filename = os.path.join(d, "dhparam.pem")
- certs.CertStore.load_dhparam(filename)
- assert os.path.exists(filename)
-
-
-class TestTCPClient:
-
- def test_conerr(self):
- c = tcp.TCPClient(("127.0.0.1", 0))
- tutils.raises(exceptions.TcpException, c.connect)
-
-
-class TestFileLike:
-
- def test_blocksize(self):
- s = BytesIO(b"1234567890abcdefghijklmnopqrstuvwxyz")
- s = tcp.Reader(s)
- s.BLOCKSIZE = 2
- assert s.read(1) == b"1"
- assert s.read(2) == b"23"
- assert s.read(3) == b"456"
- assert s.read(4) == b"7890"
- d = s.read(-1)
- assert d.startswith(b"abc") and d.endswith(b"xyz")
-
- def test_wrap(self):
- s = BytesIO(b"foobar\nfoobar")
- s.flush()
- s = tcp.Reader(s)
- assert s.readline() == b"foobar\n"
- assert s.readline() == b"foobar"
- # Test __getattr__
- assert s.isatty
-
- def test_limit(self):
- s = BytesIO(b"foobar\nfoobar")
- s = tcp.Reader(s)
- assert s.readline(3) == b"foo"
-
- def test_limitless(self):
- s = BytesIO(b"f" * (50 * 1024))
- s = tcp.Reader(s)
- ret = s.read(-1)
- assert len(ret) == 50 * 1024
-
- def test_readlog(self):
- s = BytesIO(b"foobar\nfoobar")
- s = tcp.Reader(s)
- assert not s.is_logging()
- s.start_log()
- assert s.is_logging()
- s.readline()
- assert s.get_log() == b"foobar\n"
- s.read(1)
- assert s.get_log() == b"foobar\nf"
- s.start_log()
- assert s.get_log() == b""
- s.read(1)
- assert s.get_log() == b"o"
- s.stop_log()
- tutils.raises(ValueError, s.get_log)
-
- def test_writelog(self):
- s = BytesIO()
- s = tcp.Writer(s)
- s.start_log()
- assert s.is_logging()
- s.write(b"x")
- assert s.get_log() == b"x"
- s.write(b"x")
- assert s.get_log() == b"xx"
-
- def test_writer_flush_error(self):
- s = BytesIO()
- s = tcp.Writer(s)
- o = mock.MagicMock()
- o.flush = mock.MagicMock(side_effect=socket.error)
- s.o = o
- tutils.raises(exceptions.TcpDisconnect, s.flush)
-
- def test_reader_read_error(self):
- s = BytesIO(b"foobar\nfoobar")
- s = tcp.Reader(s)
- o = mock.MagicMock()
- o.read = mock.MagicMock(side_effect=socket.error)
- s.o = o
- tutils.raises(exceptions.TcpDisconnect, s.read, 10)
-
- def test_reset_timestamps(self):
- s = BytesIO(b"foobar\nfoobar")
- s = tcp.Reader(s)
- s.first_byte_timestamp = 500
- s.reset_timestamps()
- assert not s.first_byte_timestamp
-
- def test_first_byte_timestamp_updated_on_read(self):
- s = BytesIO(b"foobar\nfoobar")
- s = tcp.Reader(s)
- s.read(1)
- assert s.first_byte_timestamp
- expected = s.first_byte_timestamp
- s.read(5)
- assert s.first_byte_timestamp == expected
-
- def test_first_byte_timestamp_updated_on_readline(self):
- s = BytesIO(b"foobar\nfoobar\nfoobar")
- s = tcp.Reader(s)
- s.readline()
- assert s.first_byte_timestamp
- expected = s.first_byte_timestamp
- s.readline()
- assert s.first_byte_timestamp == expected
-
- def test_read_ssl_error(self):
- s = mock.MagicMock()
- s.read = mock.MagicMock(side_effect=SSL.Error())
- s = tcp.Reader(s)
- tutils.raises(exceptions.TlsException, s.read, 1)
-
- def test_read_syscall_ssl_error(self):
- s = mock.MagicMock()
- s.read = mock.MagicMock(side_effect=SSL.SysCallError())
- s = tcp.Reader(s)
- tutils.raises(exceptions.TlsException, s.read, 1)
-
- def test_reader_readline_disconnect(self):
- o = mock.MagicMock()
- o.read = mock.MagicMock(side_effect=socket.error)
- s = tcp.Reader(o)
- tutils.raises(exceptions.TcpDisconnect, s.readline, 10)
-
- def test_reader_incomplete_error(self):
- s = BytesIO(b"foobar")
- s = tcp.Reader(s)
- tutils.raises(exceptions.TcpReadIncomplete, s.safe_read, 10)
-
-
-class TestPeek(tservers.ServerTestBase):
- handler = EchoHandler
-
- def _connect(self, c):
- return c.connect()
-
- def test_peek(self):
- testval = b"peek!\n"
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with self._connect(c):
- c.wfile.write(testval)
- c.wfile.flush()
-
- assert c.rfile.peek(4) == b"peek"
- assert c.rfile.peek(6) == b"peek!\n"
- assert c.rfile.readline() == testval
-
- c.close()
- with tutils.raises(exceptions.NetlibException):
- if c.rfile.peek(1) == b"":
- # Workaround for Python 2 on Unix:
- # Peeking a closed connection does not raise an exception here.
- raise exceptions.NetlibException()
-
-
-class TestPeekSSL(TestPeek):
- ssl = True
-
- def _connect(self, c):
- with c.connect() as conn:
- c.convert_to_ssl()
- return conn.pop()
-
-
-class TestAddress:
- def test_simple(self):
- a = tcp.Address(("localhost", 80), True)
- assert a.use_ipv6
- b = tcp.Address(("foo.com", 80), True)
- assert not a == b
- c = tcp.Address(("localhost", 80), True)
- assert a == c
- assert not a != c
- assert repr(a) == "localhost:80"
-
-
-class TestSSLKeyLogger(tservers.ServerTestBase):
- handler = EchoHandler
- ssl = dict(
- cipher_list="AES256-SHA"
- )
-
- def test_log(self):
- testval = b"echo!\n"
- _logfun = tcp.log_ssl_key
-
- with tutils.tmpdir() as d:
- logfile = os.path.join(d, "foo", "bar", "logfile")
- tcp.log_ssl_key = tcp.SSLKeyLogger(logfile)
-
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- c.convert_to_ssl()
- c.wfile.write(testval)
- c.wfile.flush()
- assert c.rfile.readline() == testval
- c.finish()
-
- tcp.log_ssl_key.close()
- with open(logfile, "rb") as f:
- assert f.read().count(b"CLIENT_RANDOM") == 2
-
- tcp.log_ssl_key = _logfun
-
- def test_create_logfun(self):
- assert isinstance(
- tcp.SSLKeyLogger.create_logfun("test"),
- tcp.SSLKeyLogger)
- assert not tcp.SSLKeyLogger.create_logfun(False)
diff --git a/test/netlib/test_wsgi.py b/test/netlib/test_wsgi.py
deleted file mode 100644
index 5c61f81c..00000000
--- a/test/netlib/test_wsgi.py
+++ /dev/null
@@ -1,106 +0,0 @@
-from io import BytesIO
-import sys
-from netlib import wsgi
-from netlib.http import Headers
-
-
-def tflow():
- headers = Headers(test=b"value")
- req = wsgi.Request("http", "GET", "/", "HTTP/1.1", headers, "")
- return wsgi.Flow(("127.0.0.1", 8888), req)
-
-
-class ExampleApp:
-
- def __init__(self):
- self.called = False
-
- def __call__(self, environ, start_response):
- self.called = True
- status = '200 OK'
- response_headers = [('Content-type', 'text/plain')]
- start_response(status, response_headers)
- return [b'Hello', b' world!\n']
-
-
-class TestWSGI:
-
- def test_make_environ(self):
- w = wsgi.WSGIAdaptor(None, "foo", 80, "version")
- tf = tflow()
- assert w.make_environ(tf, None)
-
- tf.request.path = "/foo?bar=voing"
- r = w.make_environ(tf, None)
- assert r["QUERY_STRING"] == "bar=voing"
-
- def test_serve(self):
- ta = ExampleApp()
- w = wsgi.WSGIAdaptor(ta, "foo", 80, "version")
- f = tflow()
- f.request.host = "foo"
- f.request.port = 80
-
- wfile = BytesIO()
- err = w.serve(f, wfile)
- assert ta.called
- assert not err
-
- val = wfile.getvalue()
- assert b"Hello world" in val
- assert b"Server:" in val
-
- def _serve(self, app):
- w = wsgi.WSGIAdaptor(app, "foo", 80, "version")
- f = tflow()
- f.request.host = "foo"
- f.request.port = 80
- wfile = BytesIO()
- w.serve(f, wfile)
- return wfile.getvalue()
-
- def test_serve_empty_body(self):
- def app(environ, start_response):
- status = '200 OK'
- response_headers = [('Foo', 'bar')]
- start_response(status, response_headers)
- return []
- assert self._serve(app)
-
- def test_serve_double_start(self):
- def app(environ, start_response):
- try:
- raise ValueError("foo")
- except:
- sys.exc_info()
- status = '200 OK'
- response_headers = [('Content-type', 'text/plain')]
- start_response(status, response_headers)
- start_response(status, response_headers)
- assert b"Internal Server Error" in self._serve(app)
-
- def test_serve_single_err(self):
- def app(environ, start_response):
- try:
- raise ValueError("foo")
- except:
- ei = sys.exc_info()
- status = '200 OK'
- response_headers = [('Content-type', 'text/plain')]
- start_response(status, response_headers, ei)
- yield b""
- assert b"Internal Server Error" in self._serve(app)
-
- def test_serve_double_err(self):
- def app(environ, start_response):
- try:
- raise ValueError("foo")
- except:
- ei = sys.exc_info()
- status = '200 OK'
- response_headers = [('Content-type', 'text/plain')]
- start_response(status, response_headers)
- yield b"aaa"
- start_response(status, response_headers, ei)
- yield b"bbb"
- assert b"Internal Server Error" in self._serve(app)
diff --git a/test/netlib/tools/getcertnames b/test/netlib/tools/getcertnames
deleted file mode 100644
index 0882fccd..00000000
--- a/test/netlib/tools/getcertnames
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/env python
-import sys
-sys.path.insert(0, "../../")
-from netlib import tcp
-
-
-def get_remote_cert(host, port, sni):
- c = tcp.TCPClient((host, port))
- c.connect()
- c.convert_to_ssl(sni=sni)
- return c.cert
-
-if len(sys.argv) > 2:
- port = int(sys.argv[2])
-else:
- port = 443
-if len(sys.argv) > 3:
- sni = sys.argv[3]
-else:
- sni = None
-
-cert = get_remote_cert(sys.argv[1], port, sni)
-print("CN:", cert.cn)
-if cert.altnames:
- print("SANs:")
- for i in cert.altnames:
- print("\t", i)
diff --git a/test/netlib/tservers.py b/test/netlib/tservers.py
deleted file mode 100644
index 2fae8ba6..00000000
--- a/test/netlib/tservers.py
+++ /dev/null
@@ -1,113 +0,0 @@
-import threading
-import queue
-import io
-import OpenSSL
-
-from netlib import tcp
-from mitmproxy.test import tutils
-
-
-class _ServerThread(threading.Thread):
-
- def __init__(self, server):
- self.server = server
- threading.Thread.__init__(self)
-
- def run(self):
- self.server.serve_forever()
-
- def shutdown(self):
- self.server.shutdown()
-
-
-class _TServer(tcp.TCPServer):
-
- def __init__(self, ssl, q, handler_klass, addr, **kwargs):
- """
- ssl: A dictionary of SSL parameters:
-
- cert, key, request_client_cert, cipher_list,
- dhparams, v3_only
- """
- tcp.TCPServer.__init__(self, addr)
-
- if ssl is True:
- self.ssl = dict()
- elif isinstance(ssl, dict):
- self.ssl = ssl
- else:
- self.ssl = None
-
- self.q = q
- self.handler_klass = handler_klass
- if self.handler_klass is not None:
- self.handler_klass.kwargs = kwargs
- self.last_handler = None
-
- def handle_client_connection(self, request, client_address):
- h = self.handler_klass(request, client_address, self)
- self.last_handler = h
- if self.ssl is not None:
- cert = self.ssl.get(
- "cert",
- tutils.test_data.path("data/server.crt"))
- raw_key = self.ssl.get(
- "key",
- tutils.test_data.path("data/server.key"))
- key = OpenSSL.crypto.load_privatekey(
- OpenSSL.crypto.FILETYPE_PEM,
- open(raw_key, "rb").read())
- if self.ssl.get("v3_only", False):
- method = OpenSSL.SSL.SSLv3_METHOD
- options = OpenSSL.SSL.OP_NO_SSLv2 | OpenSSL.SSL.OP_NO_TLSv1
- else:
- method = OpenSSL.SSL.SSLv23_METHOD
- options = None
- h.convert_to_ssl(
- cert, key,
- method=method,
- options=options,
- handle_sni=getattr(h, "handle_sni", None),
- request_client_cert=self.ssl.get("request_client_cert", None),
- cipher_list=self.ssl.get("cipher_list", None),
- dhparams=self.ssl.get("dhparams", None),
- chain_file=self.ssl.get("chain_file", None),
- alpn_select=self.ssl.get("alpn_select", None)
- )
- h.handle()
- h.finish()
-
- def handle_error(self, connection, client_address, fp=None):
- s = io.StringIO()
- tcp.TCPServer.handle_error(self, connection, client_address, s)
- self.q.put(s.getvalue())
-
-
-class ServerTestBase:
- ssl = None
- handler = None
- addr = ("localhost", 0)
-
- @classmethod
- def setup_class(cls, **kwargs):
- cls.q = queue.Queue()
- s = cls.makeserver(**kwargs)
- cls.port = s.address.port
- cls.server = _ServerThread(s)
- cls.server.start()
-
- @classmethod
- def makeserver(cls, **kwargs):
- ssl = kwargs.pop('ssl', cls.ssl)
- return _TServer(ssl, cls.q, cls.handler, cls.addr, **kwargs)
-
- @classmethod
- def teardown_class(cls):
- cls.server.shutdown()
-
- def teardown(self):
- self.server.server.wait_for_silence()
-
- @property
- def last_handler(self):
- return self.server.server.last_handler
diff --git a/test/netlib/websockets/__init__.py b/test/netlib/websockets/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/test/netlib/websockets/__init__.py
+++ /dev/null
diff --git a/test/netlib/websockets/test_frame.py b/test/netlib/websockets/test_frame.py
deleted file mode 100644
index 3b7c9ed4..00000000
--- a/test/netlib/websockets/test_frame.py
+++ /dev/null
@@ -1,164 +0,0 @@
-import os
-import codecs
-import pytest
-
-from netlib import websockets
-from mitmproxy.test import tutils
-
-
-class TestFrameHeader:
-
- @pytest.mark.parametrize("input,expected", [
- (0, '0100'),
- (125, '017D'),
- (126, '017E007E'),
- (127, '017E007F'),
- (142, '017E008E'),
- (65534, '017EFFFE'),
- (65535, '017EFFFF'),
- (65536, '017F0000000000010000'),
- (8589934591, '017F00000001FFFFFFFF'),
- (2 ** 64 - 1, '017FFFFFFFFFFFFFFFFF'),
- ])
- def test_serialization_length(self, input, expected):
- h = websockets.FrameHeader(
- opcode=websockets.OPCODE.TEXT,
- payload_length=input,
- )
- assert bytes(h) == codecs.decode(expected, 'hex')
-
- def test_serialization_too_large(self):
- h = websockets.FrameHeader(
- payload_length=2 ** 64 + 1,
- )
- with pytest.raises(ValueError):
- bytes(h)
-
- @pytest.mark.parametrize("input,expected", [
- ('0100', 0),
- ('017D', 125),
- ('017E007E', 126),
- ('017E007F', 127),
- ('017E008E', 142),
- ('017EFFFE', 65534),
- ('017EFFFF', 65535),
- ('017F0000000000010000', 65536),
- ('017F00000001FFFFFFFF', 8589934591),
- ('017FFFFFFFFFFFFFFFFF', 2 ** 64 - 1),
- ])
- def test_deserialization_length(self, input, expected):
- h = websockets.FrameHeader.from_file(tutils.treader(codecs.decode(input, 'hex')))
- assert h.payload_length == expected
-
- @pytest.mark.parametrize("input,expected", [
- ('0100', (False, None)),
- ('018000000000', (True, '00000000')),
- ('018012345678', (True, '12345678')),
- ])
- def test_deserialization_masking(self, input, expected):
- h = websockets.FrameHeader.from_file(tutils.treader(codecs.decode(input, 'hex')))
- assert h.mask == expected[0]
- if h.mask:
- assert h.masking_key == codecs.decode(expected[1], 'hex')
-
- def test_equality(self):
- h = websockets.FrameHeader(mask=True, masking_key=b'1234')
- h2 = websockets.FrameHeader(mask=True, masking_key=b'1234')
- assert h == h2
-
- h = websockets.FrameHeader(fin=True)
- h2 = websockets.FrameHeader(fin=False)
- assert h != h2
-
- assert h != 'foobar'
-
- def test_roundtrip(self):
- def round(*args, **kwargs):
- h = websockets.FrameHeader(*args, **kwargs)
- h2 = websockets.FrameHeader.from_file(tutils.treader(bytes(h)))
- assert h == h2
-
- round()
- round(fin=True)
- round(rsv1=True)
- round(rsv2=True)
- round(rsv3=True)
- round(payload_length=1)
- round(payload_length=100)
- round(payload_length=1000)
- round(payload_length=10000)
- round(opcode=websockets.OPCODE.PING)
- round(masking_key=b"test")
-
- def test_human_readable(self):
- f = websockets.FrameHeader(
- masking_key=b"test",
- fin=True,
- payload_length=10
- )
- assert repr(f)
-
- f = websockets.FrameHeader()
- assert repr(f)
-
- def test_funky(self):
- f = websockets.FrameHeader(masking_key=b"test", mask=False)
- raw = bytes(f)
- f2 = websockets.FrameHeader.from_file(tutils.treader(raw))
- assert not f2.mask
-
- def test_violations(self):
- tutils.raises("opcode", websockets.FrameHeader, opcode=17)
- tutils.raises("masking key", websockets.FrameHeader, masking_key=b"x")
-
- def test_automask(self):
- f = websockets.FrameHeader(mask=True)
- assert f.masking_key
-
- f = websockets.FrameHeader(masking_key=b"foob")
- assert f.mask
-
- f = websockets.FrameHeader(masking_key=b"foob", mask=0)
- assert not f.mask
- assert f.masking_key
-
-
-class TestFrame:
- def test_equality(self):
- f = websockets.Frame(payload=b'1234')
- f2 = websockets.Frame(payload=b'1234')
- assert f == f2
-
- assert f != b'1234'
-
- def test_roundtrip(self):
- def round(*args, **kwargs):
- f = websockets.Frame(*args, **kwargs)
- raw = bytes(f)
- f2 = websockets.Frame.from_file(tutils.treader(raw))
- assert f == f2
- round(b"test")
- round(b"test", fin=1)
- round(b"test", rsv1=1)
- round(b"test", opcode=websockets.OPCODE.PING)
- round(b"test", masking_key=b"test")
-
- def test_human_readable(self):
- f = websockets.Frame()
- assert repr(f)
-
- f = websockets.Frame(b"foobar")
- assert "foobar" in repr(f)
-
- @pytest.mark.parametrize("masked", [True, False])
- @pytest.mark.parametrize("length", [100, 50000, 150000])
- def test_serialization_bijection(self, masked, length):
- frame = websockets.Frame(
- os.urandom(length),
- fin=True,
- opcode=websockets.OPCODE.TEXT,
- mask=int(masked),
- masking_key=(os.urandom(4) if masked else None)
- )
- serialized = bytes(frame)
- assert frame == websockets.Frame.from_bytes(serialized)
diff --git a/test/netlib/websockets/test_masker.py b/test/netlib/websockets/test_masker.py
deleted file mode 100644
index 23a9b876..00000000
--- a/test/netlib/websockets/test_masker.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import codecs
-import pytest
-
-from netlib import websockets
-
-
-class TestMasker:
-
- @pytest.mark.parametrize("input,expected", [
- ([b"a"], '00'),
- ([b"four"], '070d1616'),
- ([b"fourf"], '070d161607'),
- ([b"fourfive"], '070d1616070b1501'),
- ([b"a", b"aasdfasdfa", b"asdf"], '000302170504021705040205120605'),
- ([b"a" * 50, b"aasdfasdfa", b"asdf"], '00030205000302050003020500030205000302050003020500030205000302050003020500030205000302050003020500030205120605051206050500110702'), # noqa
- ])
- def test_masker(self, input, expected):
- m = websockets.Masker(b"abcd")
- data = b"".join([m(t) for t in input])
- assert data == codecs.decode(expected, 'hex')
-
- data = websockets.Masker(b"abcd")(data)
- assert data == b"".join(input)
diff --git a/test/netlib/websockets/test_utils.py b/test/netlib/websockets/test_utils.py
deleted file mode 100644
index f6f1e40a..00000000
--- a/test/netlib/websockets/test_utils.py
+++ /dev/null
@@ -1,105 +0,0 @@
-import pytest
-
-from netlib import http
-from netlib import websockets
-
-
-class TestUtils:
-
- def test_client_handshake_headers(self):
- h = websockets.client_handshake_headers(version='42')
- assert h['sec-websocket-version'] == '42'
-
- h = websockets.client_handshake_headers(key='some-key')
- assert h['sec-websocket-key'] == 'some-key'
-
- h = websockets.client_handshake_headers(protocol='foobar')
- assert h['sec-websocket-protocol'] == 'foobar'
-
- h = websockets.client_handshake_headers(extensions='foo; bar')
- assert h['sec-websocket-extensions'] == 'foo; bar'
-
- def test_server_handshake_headers(self):
- h = websockets.server_handshake_headers('some-key')
- assert h['sec-websocket-accept'] == '8iILEZtcVdtFD7MDlPKip9ec9nw='
- assert 'sec-websocket-protocol' not in h
- assert 'sec-websocket-extensions' not in h
-
- h = websockets.server_handshake_headers('some-key', 'foobar', 'foo; bar')
- assert h['sec-websocket-accept'] == '8iILEZtcVdtFD7MDlPKip9ec9nw='
- assert h['sec-websocket-protocol'] == 'foobar'
- assert h['sec-websocket-extensions'] == 'foo; bar'
-
- @pytest.mark.parametrize("input,expected", [
- ([(b'connection', b'upgrade'), (b'upgrade', b'websocket'), (b'sec-websocket-key', b'foobar')], True),
- ([(b'connection', b'upgrade'), (b'upgrade', b'websocket'), (b'sec-websocket-accept', b'foobar')], True),
- ([(b'Connection', b'UpgRaDe'), (b'Upgrade', b'WebSocKeT'), (b'Sec-WebSockeT-KeY', b'foobar')], True),
- ([(b'Connection', b'UpgRaDe'), (b'Upgrade', b'WebSocKeT'), (b'Sec-WebSockeT-AccePt', b'foobar')], True),
- ([(b'connection', b'foo'), (b'upgrade', b'bar'), (b'sec-websocket-key', b'foobar')], False),
- ([(b'connection', b'upgrade'), (b'upgrade', b'websocket')], False),
- ([(b'connection', b'upgrade'), (b'sec-websocket-key', b'foobar')], False),
- ([(b'upgrade', b'websocket'), (b'sec-websocket-key', b'foobar')], False),
- ([], False),
- ])
- def test_check_handshake(self, input, expected):
- h = http.Headers(input)
- assert websockets.check_handshake(h) == expected
-
- @pytest.mark.parametrize("input,expected", [
- ([(b'sec-websocket-version', b'13')], True),
- ([(b'Sec-WebSockeT-VerSion', b'13')], True),
- ([(b'sec-websocket-version', b'9')], False),
- ([(b'sec-websocket-version', b'42')], False),
- ([(b'sec-websocket-version', b'')], False),
- ([], False),
- ])
- def test_check_client_version(self, input, expected):
- h = http.Headers(input)
- assert websockets.check_client_version(h) == expected
-
- @pytest.mark.parametrize("input,expected", [
- ('foobar', b'AzhRPA4TNwR6I/riJheN0TfR7+I='),
- (b'foobar', b'AzhRPA4TNwR6I/riJheN0TfR7+I='),
- ])
- def test_create_server_nonce(self, input, expected):
- assert websockets.create_server_nonce(input) == expected
-
- @pytest.mark.parametrize("input,expected", [
- ([(b'sec-websocket-extensions', b'foo; bar')], 'foo; bar'),
- ([(b'Sec-WebSockeT-ExteNsionS', b'foo; bar')], 'foo; bar'),
- ([(b'sec-websocket-extensions', b'')], ''),
- ([], None),
- ])
- def test_get_extensions(self, input, expected):
- h = http.Headers(input)
- assert websockets.get_extensions(h) == expected
-
- @pytest.mark.parametrize("input,expected", [
- ([(b'sec-websocket-protocol', b'foobar')], 'foobar'),
- ([(b'Sec-WebSockeT-ProTocoL', b'foobar')], 'foobar'),
- ([(b'sec-websocket-protocol', b'')], ''),
- ([], None),
- ])
- def test_get_protocol(self, input, expected):
- h = http.Headers(input)
- assert websockets.get_protocol(h) == expected
-
- @pytest.mark.parametrize("input,expected", [
- ([(b'sec-websocket-key', b'foobar')], 'foobar'),
- ([(b'Sec-WebSockeT-KeY', b'foobar')], 'foobar'),
- ([(b'sec-websocket-key', b'')], ''),
- ([], None),
- ])
- def test_get_client_key(self, input, expected):
- h = http.Headers(input)
- assert websockets.get_client_key(h) == expected
-
- @pytest.mark.parametrize("input,expected", [
- ([(b'sec-websocket-accept', b'foobar')], 'foobar'),
- ([(b'Sec-WebSockeT-AccepT', b'foobar')], 'foobar'),
- ([(b'sec-websocket-accept', b'')], ''),
- ([], None),
- ])
- def test_get_server_accept(self, input, expected):
- h = http.Headers(input)
- assert websockets.get_server_accept(h) == expected