async def test_cloudfare_not_cloudfare(aiohttp_client, cloudfare_session):
    async def handler(request):
        return web.Response()

    cf_client = await cloudfare_session(ipv4=['10.0.0.0'], ipv6=['10::'])

    app = web.Application()
    app.router.add_get('/', handler)
    await _setup(app, Cloudflare(cf_client))
    cl = await aiohttp_client(app)
    resp = await cl.get('/', headers={'CF-CONNECTING-IP': '10.10.10.10'})
    assert resp.status == 400
async def test_cloudfare_garbage_config(aiohttp_client, cloudfare_session):
    async def handler(request):
        assert request.remote == '10.10.10.10'

        return web.Response()

    cf_client = await cloudfare_session(ipv4=['127.0.0.0/16', 'garbage'])

    app = web.Application()
    app.router.add_get('/', handler)
    await _setup(app, Cloudflare(cf_client))
    cl = await aiohttp_client(app)
    resp = await cl.get('/', headers={'CF-CONNECTING-IP': '10.10.10.10'})
    assert resp.status == 200
async def test_cloudfare_ok(test_client, cloudfare_session):
    async def handler(request):
        assert request.remote == '10.10.10.10'

        return web.Response()

    cf_client = await cloudfare_session()

    app = web.Application()
    app.router.add_get('/', handler)
    await _setup(app, Cloudflare(cf_client))
    cl = await test_client(app)
    resp = await cl.get('/', headers={'CF-CONNECTING-IP': '10.10.10.10'})
    assert resp.status == 200
async def test_cloudfare_no_networks(aiohttp_client, cloudfare_session):
    cf_client = await cloudfare_session(ipv4=[], ipv6=[])

    app = web.Application()
    with pytest.raises(RuntimeError):
        await _setup(app, Cloudflare(cf_client))