mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Mark auth voluptuous schema fields as required (#57003)
This commit is contained in:
parent
79b10c43d8
commit
2d374d65b6
@ -38,12 +38,12 @@ class InsecureExampleModule(MultiFactorAuthModule):
|
|||||||
@property
|
@property
|
||||||
def input_schema(self) -> vol.Schema:
|
def input_schema(self) -> vol.Schema:
|
||||||
"""Validate login flow input data."""
|
"""Validate login flow input data."""
|
||||||
return vol.Schema({"pin": str})
|
return vol.Schema({vol.Required("pin"): str})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def setup_schema(self) -> vol.Schema:
|
def setup_schema(self) -> vol.Schema:
|
||||||
"""Validate async_setup_user input data."""
|
"""Validate async_setup_user input data."""
|
||||||
return vol.Schema({"pin": str})
|
return vol.Schema({vol.Required("pin"): str})
|
||||||
|
|
||||||
async def async_setup_flow(self, user_id: str) -> SetupFlow:
|
async def async_setup_flow(self, user_id: str) -> SetupFlow:
|
||||||
"""Return a data entry flow handler for setup module.
|
"""Return a data entry flow handler for setup module.
|
||||||
|
@ -110,7 +110,7 @@ class NotifyAuthModule(MultiFactorAuthModule):
|
|||||||
@property
|
@property
|
||||||
def input_schema(self) -> vol.Schema:
|
def input_schema(self) -> vol.Schema:
|
||||||
"""Validate login flow input data."""
|
"""Validate login flow input data."""
|
||||||
return vol.Schema({INPUT_FIELD_CODE: str})
|
return vol.Schema({vol.Required(INPUT_FIELD_CODE): str})
|
||||||
|
|
||||||
async def _async_load(self) -> None:
|
async def _async_load(self) -> None:
|
||||||
"""Load stored data."""
|
"""Load stored data."""
|
||||||
|
@ -84,7 +84,7 @@ class TotpAuthModule(MultiFactorAuthModule):
|
|||||||
@property
|
@property
|
||||||
def input_schema(self) -> vol.Schema:
|
def input_schema(self) -> vol.Schema:
|
||||||
"""Validate login flow input data."""
|
"""Validate login flow input data."""
|
||||||
return vol.Schema({INPUT_FIELD_CODE: str})
|
return vol.Schema({vol.Required(INPUT_FIELD_CODE): str})
|
||||||
|
|
||||||
async def _async_load(self) -> None:
|
async def _async_load(self) -> None:
|
||||||
"""Load stored data."""
|
"""Load stored data."""
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import collections
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -148,10 +147,13 @@ class CommandLineLoginFlow(LoginFlow):
|
|||||||
user_input.pop("password")
|
user_input.pop("password")
|
||||||
return await self.async_finish(user_input)
|
return await self.async_finish(user_input)
|
||||||
|
|
||||||
schema: dict[str, type] = collections.OrderedDict()
|
|
||||||
schema["username"] = str
|
|
||||||
schema["password"] = str
|
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init", data_schema=vol.Schema(schema), errors=errors
|
step_id="init",
|
||||||
|
data_schema=vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required("username"): str,
|
||||||
|
vol.Required("password"): str,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
import base64
|
||||||
from collections import OrderedDict
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
@ -335,10 +334,13 @@ class HassLoginFlow(LoginFlow):
|
|||||||
user_input.pop("password")
|
user_input.pop("password")
|
||||||
return await self.async_finish(user_input)
|
return await self.async_finish(user_input)
|
||||||
|
|
||||||
schema: dict[str, type] = OrderedDict()
|
|
||||||
schema["username"] = str
|
|
||||||
schema["password"] = str
|
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init", data_schema=vol.Schema(schema), errors=errors
|
step_id="init",
|
||||||
|
data_schema=vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required("username"): str,
|
||||||
|
vol.Required("password"): str,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Example auth provider."""
|
"""Example auth provider."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections import OrderedDict
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
import hmac
|
import hmac
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
@ -117,10 +116,13 @@ class ExampleLoginFlow(LoginFlow):
|
|||||||
user_input.pop("password")
|
user_input.pop("password")
|
||||||
return await self.async_finish(user_input)
|
return await self.async_finish(user_input)
|
||||||
|
|
||||||
schema: dict[str, type] = OrderedDict()
|
|
||||||
schema["username"] = str
|
|
||||||
schema["password"] = str
|
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init", data_schema=vol.Schema(schema), errors=errors
|
step_id="init",
|
||||||
|
data_schema=vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required("username"): str,
|
||||||
|
vol.Required("password"): str,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
@ -102,5 +102,7 @@ class LegacyLoginFlow(LoginFlow):
|
|||||||
return await self.async_finish({})
|
return await self.async_finish({})
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init", data_schema=vol.Schema({"password": str}), errors=errors
|
step_id="init",
|
||||||
|
data_schema=vol.Schema({vol.Required("password"): str}),
|
||||||
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
@ -244,5 +244,7 @@ class TrustedNetworksLoginFlow(LoginFlow):
|
|||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init",
|
step_id="init",
|
||||||
data_schema=vol.Schema({"user": vol.In(self._available_users)}),
|
data_schema=vol.Schema(
|
||||||
|
{vol.Required("user"): vol.In(self._available_users)}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
@ -67,7 +67,7 @@ async def test_ws_setup_depose_mfa(hass, hass_ws_client):
|
|||||||
assert flow["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert flow["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert flow["handler"] == "example_module"
|
assert flow["handler"] == "example_module"
|
||||||
assert flow["step_id"] == "init"
|
assert flow["step_id"] == "init"
|
||||||
assert flow["data_schema"][0] == {"type": "string", "name": "pin"}
|
assert flow["data_schema"][0] == {"type": "string", "name": "pin", "required": True}
|
||||||
|
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user