| 7 | |
| 8 | |
| 9 | async def test_simple(): |
| 10 | r = intercept.Intercept() |
| 11 | with taddons.context(r) as tctx: |
| 12 | assert not r.filt |
| 13 | tctx.configure(r, intercept="~q") |
| 14 | assert r.filt |
| 15 | assert tctx.options.intercept_active |
| 16 | with pytest.raises(exceptions.OptionsError): |
| 17 | tctx.configure(r, intercept="~~") |
| 18 | tctx.configure(r, intercept=None) |
| 19 | assert not r.filt |
| 20 | assert not tctx.options.intercept_active |
| 21 | |
| 22 | tctx.configure(r, intercept="~s") |
| 23 | |
| 24 | f = tflow.tflow(resp=True) |
| 25 | await tctx.cycle(r, f) |
| 26 | assert f.intercepted |
| 27 | |
| 28 | f = tflow.tflow(resp=False) |
| 29 | await tctx.cycle(r, f) |
| 30 | assert not f.intercepted |
| 31 | |
| 32 | f = tflow.tflow(resp=True) |
| 33 | r.response(f) |
| 34 | assert f.intercepted |
| 35 | |
| 36 | tctx.configure(r, intercept_active=False) |
| 37 | f = tflow.tflow(resp=True) |
| 38 | await tctx.cycle(r, f) |
| 39 | assert not f.intercepted |
| 40 | |
| 41 | tctx.configure(r, intercept_active=True) |
| 42 | f = tflow.tflow(resp=True) |
| 43 | await tctx.cycle(r, f) |
| 44 | assert f.intercepted |
| 45 | |
| 46 | |
| 47 | async def test_dns(): |