Skip to content

Commit

Permalink
Enable strict warning mode, fix all deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Mar 1, 2018
1 parent 40dc272 commit cbaac2c
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 110 deletions.
2 changes: 1 addition & 1 deletion aiohttp_remotes/basic_auth.py
Expand Up @@ -35,7 +35,7 @@ async def middleware(self, request, handler):
try:
secret = auth_header[6:].encode('utf-8')

auth_decoded = base64.decodestring(secret).decode('utf-8')
auth_decoded = base64.decodebytes(secret).decode('utf-8')
except (UnicodeDecodeError, UnicodeEncodeError,
binascii.Error):
await self.raise_error(request)
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
@@ -1,2 +1,3 @@
[pytest]
addopts= --no-cov-on-fail --cov-branch --cov=aiohttp_remotes --cov-report=term --cov-report=html
filterwarnings = error
16 changes: 8 additions & 8 deletions tests/test_allowed_hosts.py
Expand Up @@ -3,49 +3,49 @@
from aiohttp_remotes import setup as _setup


async def test_allowed_hosts_ok(test_client):
async def test_allowed_hosts_ok(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, AllowedHosts({'example.com'}))
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/', headers={'Host': 'example.com'})
assert resp.status == 200


async def test_allowed_hosts_forbidden(test_client):
async def test_allowed_hosts_forbidden(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, AllowedHosts({'example.com'}))
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/', headers={'Host': 'not-allowed.com'})
assert resp.status == 400


async def test_allowed_hosts_star(test_client):
async def test_allowed_hosts_star(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, AllowedHosts({'*'}))
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/', headers={'Host': 'example.com'})
assert resp.status == 200


async def test_allowed_hosts_default(test_client):
async def test_allowed_hosts_default(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, AllowedHosts())
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/', headers={'Host': 'example.com'})
assert resp.status == 200
30 changes: 15 additions & 15 deletions tests/test_basic_auth.py
Expand Up @@ -6,91 +6,91 @@
from aiohttp_remotes import setup as _setup


async def test_basic_auth_ok(test_client):
async def test_basic_auth_ok(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, BasicAuth('user', 'pass', 'realm'))
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/', auth=aiohttp.BasicAuth('user', 'pass'))
assert resp.status == 200


async def test_basic_auth_request_auth(test_client):
async def test_basic_auth_request_auth(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, BasicAuth('user', 'pass', 'realm'))
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/')
assert resp.status == 401
assert resp.headers['WWW-Authenticate'] == 'Basic realm=realm'


async def test_basic_auth_wrong_creds(test_client):
async def test_basic_auth_wrong_creds(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, BasicAuth('user', 'pass', 'realm'))
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/', auth=aiohttp.BasicAuth('user', 'badpass'))
assert resp.status == 401
assert resp.headers['WWW-Authenticate'] == 'Basic realm=realm'


async def test_basic_auth_malformed_req(test_client):
async def test_basic_auth_malformed_req(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, BasicAuth('user', 'pass', 'realm'))
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/', headers={'Authorization': 'Basic nonbase64'})
assert resp.status == 401
assert resp.headers['WWW-Authenticate'] == 'Basic realm=realm'


async def test_basic_auth_malformed_req2(test_client):
async def test_basic_auth_malformed_req2(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, BasicAuth('user', 'pass', 'realm'))
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/', headers={'Authorization': 'Basic nonbase64'})
assert resp.status == 401
assert resp.headers['WWW-Authenticate'] == 'Basic realm=realm'


async def test_basic_auth_malformed_req3(test_client):
async def test_basic_auth_malformed_req3(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, BasicAuth('user', 'pass', 'realm'))
cl = await test_client(app)
creds = base64.encodestring(b'a:b:c').decode('utf-8')
cl = await aiohttp_client(app)
creds = base64.encodebytes(b'a:b:c').decode('utf-8')
resp = await cl.get('/', headers={'Authorization': 'Basic '+creds})
assert resp.status == 401
assert resp.headers['WWW-Authenticate'] == 'Basic realm=realm'


async def test_basic_auth_white_path(test_client):
async def test_basic_auth_white_path(aiohttp_client):
async def handler(request):
return web.Response()

app = web.Application()
app.router.add_get('/', handler)
await _setup(app, BasicAuth('user', 'pass', 'realm', white_paths=['/']))
cl = await test_client(app)
cl = await aiohttp_client(app)
resp = await cl.get('/')
assert resp.status == 200
16 changes: 8 additions & 8 deletions tests/test_cloudfare.py
Expand Up @@ -85,7 +85,7 @@ async def go(**kwargs):
info = await fake.start()
resolver = FakeResolver(info, loop=asyncio.get_event_loop())
connector = aiohttp.TCPConnector(resolver=resolver,
verify_ssl=False)
ssl=False)

session = aiohttp.ClientSession(connector=connector)
sessions.append(session)
Expand All @@ -97,7 +97,7 @@ async def go(**kwargs):
loop.run_until_complete(s.close())


async def test_cloudfare_ok(test_client, cloudfare_session):
async def test_cloudfare_ok(aiohttp_client, cloudfare_session):
async def handler(request):
assert request.remote == '10.10.10.10'

Expand All @@ -108,20 +108,20 @@ async def handler(request):
app = web.Application()
app.router.add_get('/', handler)
await _setup(app, Cloudflare(cf_client))
cl = await test_client(app)
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_no_networks(test_client, cloudfare_session):
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))


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

Expand All @@ -130,12 +130,12 @@ async def handler(request):
app = web.Application()
app.router.add_get('/', handler)
await _setup(app, Cloudflare(cf_client))
cl = await test_client(app)
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(test_client, cloudfare_session):
async def test_cloudfare_garbage_config(aiohttp_client, cloudfare_session):
async def handler(request):
assert request.remote == '10.10.10.10'

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

0 comments on commit cbaac2c

Please sign in to comment.