1import pytest 2 3from mitmproxy.addons import onboarding 4from mitmproxy.test import taddons 5 6 7@pytest.fixture 8def client(): 9 with onboarding.app.test_client() as client: 10 yield client 11 12 13class TestApp: 14 def addons(self): 15 return [onboarding.Onboarding()] 16 17 @pytest.mark.asyncio 18 async def test_basic(self, client): 19 ob = onboarding.Onboarding() 20 with taddons.context(ob) as tctx: 21 tctx.configure(ob) 22 assert client.get("/").status_code == 200 23 24 @pytest.mark.parametrize("ext", ["pem", "p12", "cer"]) 25 @pytest.mark.asyncio 26 async def test_cert(self, client, ext, tdata): 27 ob = onboarding.Onboarding() 28 with taddons.context(ob) as tctx: 29 tctx.configure(ob, confdir=tdata.path("mitmproxy/data/confdir")) 30 resp = client.get(f"/cert/{ext}") 31 assert resp.status_code == 200 32 assert resp.data 33 34 @pytest.mark.parametrize("ext", ["pem", "p12", "cer"]) 35 @pytest.mark.asyncio 36 async def test_head(self, client, ext, tdata): 37 ob = onboarding.Onboarding() 38 with taddons.context(ob) as tctx: 39 tctx.configure(ob, confdir=tdata.path("mitmproxy/data/confdir")) 40 resp = client.head(f"http://{tctx.options.onboarding_host}/cert/{ext}") 41 assert resp.status_code == 200 42 assert "Content-Length" in resp.headers 43 assert not resp.data 44