mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Improve type hints in http tests (#121294)
This commit is contained in:
parent
641d6382fd
commit
7332bc5faf
@ -63,7 +63,7 @@ PRIVATE_ADDRESSES = [
|
||||
]
|
||||
|
||||
|
||||
async def mock_handler(request):
|
||||
async def mock_handler(request: web.Request) -> web.Response:
|
||||
"""Return if request was authenticated."""
|
||||
if not request[KEY_AUTHENTICATED]:
|
||||
raise HTTPUnauthorized
|
||||
@ -75,7 +75,7 @@ async def mock_handler(request):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(hass):
|
||||
def app(hass: HomeAssistant) -> web.Application:
|
||||
"""Fixture to set up a web.Application."""
|
||||
app = web.Application()
|
||||
app[KEY_HASS] = hass
|
||||
@ -85,7 +85,7 @@ def app(hass):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app2(hass):
|
||||
def app2(hass: HomeAssistant) -> web.Application:
|
||||
"""Fixture to set up a web.Application without real_ip middleware."""
|
||||
app = web.Application()
|
||||
app[KEY_HASS] = hass
|
||||
@ -94,7 +94,9 @@ def app2(hass):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def trusted_networks_auth(hass):
|
||||
def trusted_networks_auth(
|
||||
hass: HomeAssistant,
|
||||
) -> trusted_networks.TrustedNetworksAuthProvider:
|
||||
"""Load trusted networks auth provider."""
|
||||
prv = trusted_networks.TrustedNetworksAuthProvider(
|
||||
hass,
|
||||
@ -114,7 +116,7 @@ async def test_auth_middleware_loaded_by_default(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
async def test_cant_access_with_password_in_header(
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
local_auth: HassAuthProvider,
|
||||
hass: HomeAssistant,
|
||||
@ -131,7 +133,7 @@ async def test_cant_access_with_password_in_header(
|
||||
|
||||
|
||||
async def test_cant_access_with_password_in_query(
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
local_auth: HassAuthProvider,
|
||||
hass: HomeAssistant,
|
||||
@ -151,7 +153,7 @@ async def test_cant_access_with_password_in_query(
|
||||
|
||||
|
||||
async def test_basic_auth_does_not_work(
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass: HomeAssistant,
|
||||
local_auth: HassAuthProvider,
|
||||
@ -175,8 +177,8 @@ async def test_basic_auth_does_not_work(
|
||||
|
||||
async def test_cannot_access_with_trusted_ip(
|
||||
hass: HomeAssistant,
|
||||
app2,
|
||||
trusted_networks_auth,
|
||||
app2: web.Application,
|
||||
trusted_networks_auth: trusted_networks.TrustedNetworksAuthProvider,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_owner_user: MockUser,
|
||||
) -> None:
|
||||
@ -203,7 +205,7 @@ async def test_cannot_access_with_trusted_ip(
|
||||
|
||||
async def test_auth_active_access_with_access_token_in_header(
|
||||
hass: HomeAssistant,
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_access_token: str,
|
||||
) -> None:
|
||||
@ -239,8 +241,8 @@ async def test_auth_active_access_with_access_token_in_header(
|
||||
|
||||
async def test_auth_active_access_with_trusted_ip(
|
||||
hass: HomeAssistant,
|
||||
app2,
|
||||
trusted_networks_auth,
|
||||
app2: web.Application,
|
||||
trusted_networks_auth: trusted_networks.TrustedNetworksAuthProvider,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_owner_user: MockUser,
|
||||
) -> None:
|
||||
@ -266,7 +268,7 @@ async def test_auth_active_access_with_trusted_ip(
|
||||
|
||||
|
||||
async def test_auth_legacy_support_api_password_cannot_access(
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
local_auth: HassAuthProvider,
|
||||
hass: HomeAssistant,
|
||||
@ -287,7 +289,7 @@ async def test_auth_legacy_support_api_password_cannot_access(
|
||||
|
||||
async def test_auth_access_signed_path_with_refresh_token(
|
||||
hass: HomeAssistant,
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_access_token: str,
|
||||
) -> None:
|
||||
@ -332,7 +334,7 @@ async def test_auth_access_signed_path_with_refresh_token(
|
||||
|
||||
async def test_auth_access_signed_path_with_query_param(
|
||||
hass: HomeAssistant,
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_access_token: str,
|
||||
) -> None:
|
||||
@ -362,7 +364,7 @@ async def test_auth_access_signed_path_with_query_param(
|
||||
|
||||
async def test_auth_access_signed_path_with_query_param_order(
|
||||
hass: HomeAssistant,
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_access_token: str,
|
||||
) -> None:
|
||||
@ -403,7 +405,7 @@ async def test_auth_access_signed_path_with_query_param_order(
|
||||
|
||||
async def test_auth_access_signed_path_with_query_param_safe_param(
|
||||
hass: HomeAssistant,
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_access_token: str,
|
||||
) -> None:
|
||||
@ -440,7 +442,7 @@ async def test_auth_access_signed_path_with_query_param_safe_param(
|
||||
)
|
||||
async def test_auth_access_signed_path_with_query_param_tamper(
|
||||
hass: HomeAssistant,
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_access_token: str,
|
||||
base_url: str,
|
||||
@ -466,7 +468,7 @@ async def test_auth_access_signed_path_with_query_param_tamper(
|
||||
|
||||
async def test_auth_access_signed_path_via_websocket(
|
||||
hass: HomeAssistant,
|
||||
app,
|
||||
app: web.Application,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_read_only_access_token: str,
|
||||
) -> None:
|
||||
@ -504,7 +506,7 @@ async def test_auth_access_signed_path_via_websocket(
|
||||
|
||||
async def test_auth_access_signed_path_with_http(
|
||||
hass: HomeAssistant,
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_access_token: str,
|
||||
) -> None:
|
||||
@ -539,7 +541,7 @@ async def test_auth_access_signed_path_with_http(
|
||||
|
||||
|
||||
async def test_auth_access_signed_path_with_content_user(
|
||||
hass: HomeAssistant, app, aiohttp_client: ClientSessionGenerator
|
||||
hass: HomeAssistant, app: web.Application, aiohttp_client: ClientSessionGenerator
|
||||
) -> None:
|
||||
"""Test access signed url uses content user."""
|
||||
await async_setup_auth(hass, app)
|
||||
@ -556,7 +558,7 @@ async def test_auth_access_signed_path_with_content_user(
|
||||
|
||||
async def test_local_only_user_rejected(
|
||||
hass: HomeAssistant,
|
||||
app,
|
||||
app: web.Application,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
hass_access_token: str,
|
||||
) -> None:
|
||||
@ -579,7 +581,9 @@ async def test_local_only_user_rejected(
|
||||
assert req.status == HTTPStatus.UNAUTHORIZED
|
||||
|
||||
|
||||
async def test_async_user_not_allowed_do_auth(hass: HomeAssistant, app) -> None:
|
||||
async def test_async_user_not_allowed_do_auth(
|
||||
hass: HomeAssistant, app: web.Application
|
||||
) -> None:
|
||||
"""Test for not allowing auth."""
|
||||
user = await hass.auth.async_create_user("Hello")
|
||||
user.is_active = False
|
||||
|
Loading…
x
Reference in New Issue
Block a user