mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-01-12 22:48:54 +08:00
tests: pathod/tutils.py -> pathod/tservers.py
And remove all aliases for mitmproxy.test.tutils
This commit is contained in:
@@ -216,7 +216,7 @@ class TokValueFile(Token):
|
||||
os.path.abspath(os.path.join(settings.staticdir, s))
|
||||
)
|
||||
uf = settings.unconstrained_file_access
|
||||
if not uf and not s.startswith(settings.staticdir):
|
||||
if not uf and not s.startswith(os.path.normpath(settings.staticdir)):
|
||||
raise exceptions.FileAccessDenied(
|
||||
"File access outside of configured directory"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
from pathod import language
|
||||
from pathod.language import base, exceptions
|
||||
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
def parse_request(s):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
|
||||
from pathod.language import generators
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
def test_randomgenerator():
|
||||
|
||||
@@ -2,7 +2,8 @@ import io
|
||||
from pathod import language
|
||||
from pathod.language import http, base
|
||||
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
from . import tservers
|
||||
|
||||
|
||||
def parse_request(s):
|
||||
@@ -302,8 +303,8 @@ def test_shortcuts():
|
||||
assert next(language.parse_pathod(
|
||||
"400:l'foo'")).headers[0].key.val == b"Location"
|
||||
|
||||
assert b"Android" in tutils.render(parse_request("get:/:ua"))
|
||||
assert b"User-Agent" in tutils.render(parse_request("get:/:ua"))
|
||||
assert b"Android" in tservers.render(parse_request("get:/:ua"))
|
||||
assert b"User-Agent" in tservers.render(parse_request("get:/:ua"))
|
||||
|
||||
|
||||
def test_user_agent():
|
||||
|
||||
@@ -7,7 +7,7 @@ from pathod import language
|
||||
from pathod.language import http2
|
||||
from pathod.protocols.http2 import HTTP2StateProtocol
|
||||
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
def parse_request(s):
|
||||
|
||||
@@ -2,7 +2,8 @@ from pathod import language
|
||||
from pathod.language import websockets
|
||||
import mitmproxy.net.websockets
|
||||
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
from . import tservers
|
||||
|
||||
|
||||
def parse_request(s):
|
||||
@@ -62,7 +63,7 @@ class TestWebsocketFrame:
|
||||
|
||||
def test_flags(self):
|
||||
wf = parse_request("wf:fin:mask:rsv1:rsv2:rsv3")
|
||||
frm = mitmproxy.net.websockets.Frame.from_bytes(tutils.render(wf))
|
||||
frm = mitmproxy.net.websockets.Frame.from_bytes(tservers.render(wf))
|
||||
assert frm.header.fin
|
||||
assert frm.header.mask
|
||||
assert frm.header.rsv1
|
||||
@@ -70,7 +71,7 @@ class TestWebsocketFrame:
|
||||
assert frm.header.rsv3
|
||||
|
||||
wf = parse_request("wf:-fin:-mask:-rsv1:-rsv2:-rsv3")
|
||||
frm = mitmproxy.net.websockets.Frame.from_bytes(tutils.render(wf))
|
||||
frm = mitmproxy.net.websockets.Frame.from_bytes(tservers.render(wf))
|
||||
assert not frm.header.fin
|
||||
assert not frm.header.mask
|
||||
assert not frm.header.rsv1
|
||||
@@ -80,7 +81,7 @@ class TestWebsocketFrame:
|
||||
def fr(self, spec, **kwargs):
|
||||
settings = language.base.Settings(**kwargs)
|
||||
wf = parse_request(spec)
|
||||
return mitmproxy.net.websockets.Frame.from_bytes(tutils.render(wf, settings))
|
||||
return mitmproxy.net.websockets.Frame.from_bytes(tservers.render(wf, settings))
|
||||
|
||||
def test_construction(self):
|
||||
assert self.fr("wf:c1").header.opcode == 1
|
||||
|
||||
@@ -4,13 +4,13 @@ from mock import Mock
|
||||
from mitmproxy.net import http
|
||||
from mitmproxy.net import tcp
|
||||
from mitmproxy.net.http import http1
|
||||
from mitmproxy.test.tutils import raises
|
||||
from mitmproxy import exceptions
|
||||
|
||||
from pathod import pathoc, language
|
||||
from pathod.protocols.http2 import HTTP2StateProtocol
|
||||
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
from . import tservers
|
||||
|
||||
|
||||
def test_response():
|
||||
@@ -18,7 +18,7 @@ def test_response():
|
||||
assert repr(r)
|
||||
|
||||
|
||||
class PathocTestDaemon(tutils.DaemonTests):
|
||||
class PathocTestDaemon(tservers.DaemonTests):
|
||||
def tval(self, requests, timeout=None, showssl=False, **kwargs):
|
||||
s = io.StringIO()
|
||||
c = pathoc.Pathoc(
|
||||
@@ -64,7 +64,7 @@ class TestDaemonSSL(PathocTestDaemon):
|
||||
def test_clientcert(self):
|
||||
self.tval(
|
||||
["get:/p/200"],
|
||||
clientcert=tutils.test_data.path("data/clientcert/client.pem"),
|
||||
clientcert=tutils.test_data.path("pathod/data/clientcert/client.pem"),
|
||||
)
|
||||
log = self.d.log()
|
||||
assert log[0]["request"]["clientcert"]["keyinfo"]
|
||||
@@ -171,12 +171,12 @@ class TestDaemon(PathocTestDaemon):
|
||||
to = ("foobar", 80)
|
||||
c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
|
||||
c.rfile, c.wfile = io.BytesIO(), io.BytesIO()
|
||||
with raises("connect failed"):
|
||||
with tutils.raises("connect failed"):
|
||||
c.http_connect(to)
|
||||
c.rfile = io.BytesIO(
|
||||
b"HTTP/1.1 500 OK\r\n"
|
||||
)
|
||||
with raises("connect failed"):
|
||||
with tutils.raises("connect failed"):
|
||||
c.http_connect(to)
|
||||
c.rfile = io.BytesIO(
|
||||
b"HTTP/1.1 200 OK\r\n"
|
||||
|
||||
@@ -3,7 +3,7 @@ import mock
|
||||
|
||||
from pathod import pathoc_cmdline as cmdline
|
||||
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
@mock.patch("argparse.ArgumentParser.error")
|
||||
@@ -52,7 +52,7 @@ def test_pathoc(perror):
|
||||
[
|
||||
"pathoc",
|
||||
"foo.com:8888",
|
||||
tutils.test_data.path("data/request")
|
||||
tutils.test_data.path("pathod/data/request")
|
||||
]
|
||||
)
|
||||
assert len(list(a.requests)) == 1
|
||||
|
||||
@@ -3,8 +3,9 @@ import io
|
||||
from pathod import pathod
|
||||
from mitmproxy.net import tcp
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
from . import tutils
|
||||
from . import tservers
|
||||
|
||||
|
||||
class TestPathod:
|
||||
@@ -24,7 +25,7 @@ class TestPathod:
|
||||
assert len(p.get_log()) <= p.LOGBUF
|
||||
|
||||
|
||||
class TestTimeout(tutils.DaemonTests):
|
||||
class TestTimeout(tservers.DaemonTests):
|
||||
timeout = 0.01
|
||||
|
||||
def test_timeout(self):
|
||||
@@ -36,7 +37,7 @@ class TestTimeout(tutils.DaemonTests):
|
||||
assert self.d.last_log()["type"] == "timeout"
|
||||
|
||||
|
||||
class TestNotAfterConnect(tutils.DaemonTests):
|
||||
class TestNotAfterConnect(tservers.DaemonTests):
|
||||
ssl = False
|
||||
ssloptions = dict(
|
||||
not_after_connect=True
|
||||
@@ -50,10 +51,10 @@ class TestNotAfterConnect(tutils.DaemonTests):
|
||||
assert r[0].status_code == 202
|
||||
|
||||
|
||||
class TestCustomCert(tutils.DaemonTests):
|
||||
class TestCustomCert(tservers.DaemonTests):
|
||||
ssl = True
|
||||
ssloptions = dict(
|
||||
certs=[(b"*", tutils.test_data.path("data/testkey.pem"))],
|
||||
certs=[(b"*", tutils.test_data.path("pathod/data/testkey.pem"))],
|
||||
)
|
||||
|
||||
def test_connect(self):
|
||||
@@ -64,7 +65,7 @@ class TestCustomCert(tutils.DaemonTests):
|
||||
assert "test.com" in str(r.sslinfo.certchain[0].get_subject())
|
||||
|
||||
|
||||
class TestSSLCN(tutils.DaemonTests):
|
||||
class TestSSLCN(tservers.DaemonTests):
|
||||
ssl = True
|
||||
ssloptions = dict(
|
||||
cn=b"foo.com"
|
||||
@@ -78,7 +79,7 @@ class TestSSLCN(tutils.DaemonTests):
|
||||
assert r.sslinfo.certchain[0].get_subject().CN == "foo.com"
|
||||
|
||||
|
||||
class TestNohang(tutils.DaemonTests):
|
||||
class TestNohang(tservers.DaemonTests):
|
||||
nohang = True
|
||||
|
||||
def test_nohang(self):
|
||||
@@ -88,14 +89,14 @@ class TestNohang(tutils.DaemonTests):
|
||||
assert "Pauses have been disabled" in l["response"]["msg"]
|
||||
|
||||
|
||||
class TestHexdump(tutils.DaemonTests):
|
||||
class TestHexdump(tservers.DaemonTests):
|
||||
hexdump = True
|
||||
|
||||
def test_hexdump(self):
|
||||
assert self.get(r"200:b'\xf0'")
|
||||
|
||||
|
||||
class TestNocraft(tutils.DaemonTests):
|
||||
class TestNocraft(tservers.DaemonTests):
|
||||
nocraft = True
|
||||
|
||||
def test_nocraft(self):
|
||||
@@ -104,7 +105,7 @@ class TestNocraft(tutils.DaemonTests):
|
||||
assert b"Crafting disabled" in r.content
|
||||
|
||||
|
||||
class CommonTests(tutils.DaemonTests):
|
||||
class CommonTests(tservers.DaemonTests):
|
||||
|
||||
def test_binarydata(self):
|
||||
assert self.get(r"200:b'\xf0'")
|
||||
@@ -252,7 +253,7 @@ class TestDaemonSSL(CommonTests):
|
||||
assert self.d.last_log()["cipher"][1] > 0
|
||||
|
||||
|
||||
class TestHTTP2(tutils.DaemonTests):
|
||||
class TestHTTP2(tservers.DaemonTests):
|
||||
ssl = True
|
||||
nohang = True
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import mock
|
||||
|
||||
from pathod import pathod_cmdline as cmdline
|
||||
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
def test_parse_anchor_spec():
|
||||
@@ -18,7 +18,7 @@ def test_pathod(perror):
|
||||
[
|
||||
"pathod",
|
||||
"--cert",
|
||||
tutils.test_data.path("data/testkey.pem")
|
||||
tutils.test_data.path("pathod/data/testkey.pem")
|
||||
]
|
||||
)
|
||||
assert a.ssl_certs
|
||||
@@ -46,7 +46,7 @@ def test_pathod(perror):
|
||||
[
|
||||
"pathod",
|
||||
"-a",
|
||||
"foo=" + tutils.test_data.path("data/response")
|
||||
"foo=" + tutils.test_data.path("pathod/data/response")
|
||||
]
|
||||
)
|
||||
assert a.anchors
|
||||
|
||||
@@ -2,7 +2,7 @@ import logging
|
||||
import requests
|
||||
from pathod import test
|
||||
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
import requests.packages.urllib3
|
||||
|
||||
@@ -34,8 +34,8 @@ class TestDaemonManual:
|
||||
|
||||
def test_startstop_ssl_explicit(self):
|
||||
ssloptions = dict(
|
||||
certfile=tutils.test_data.path("data/testkey.pem"),
|
||||
cacert=tutils.test_data.path("data/testkey.pem"),
|
||||
certfile=tutils.test_data.path("pathod/data/testkey.pem"),
|
||||
cacert=tutils.test_data.path("pathod/data/testkey.pem"),
|
||||
ssl_after_connect=False
|
||||
)
|
||||
d = test.Daemon(ssl=ssloptions)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from pathod import utils
|
||||
|
||||
from . import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
def test_membool():
|
||||
|
||||
@@ -5,7 +5,6 @@ import requests
|
||||
import io
|
||||
import urllib
|
||||
|
||||
from mitmproxy.utils import data
|
||||
|
||||
from mitmproxy.net import tcp
|
||||
from mitmproxy.test import tutils
|
||||
@@ -40,7 +39,7 @@ class DaemonTests:
|
||||
opts["confdir"] = cls.confdir
|
||||
so = pathod.SSLOptions(**opts)
|
||||
cls.d = test.Daemon(
|
||||
staticdir=test_data.path("data"),
|
||||
staticdir=tutils.test_data.path("pathod/data"),
|
||||
anchors=[
|
||||
(re.compile("/anchor/.*"), "202:da")
|
||||
],
|
||||
@@ -139,13 +138,6 @@ class DaemonTests:
|
||||
return ret, logfp.getvalue()
|
||||
|
||||
|
||||
tmpdir = tutils.tmpdir
|
||||
|
||||
raises = tutils.raises
|
||||
|
||||
test_data = data.Data(__name__)
|
||||
|
||||
|
||||
def render(r, settings=language.Settings()):
|
||||
r = r.resolve(settings)
|
||||
s = io.BytesIO()
|
||||
Reference in New Issue
Block a user