Use HTTP_BAD_REQUEST constant (#33797)
This commit is contained in:
1 parent
d510384c0d
commit
4c38e6cfa5
24 files changed
+111
-61
No files matched your search
@@ -132,7 +132,7 @@ from homeassistant.components.http.auth import async_sign_path
|
||||
from homeassistant.components.http.ban import log_invalid_auth
|
||||
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||
from homeassistant.components.http.view import HomeAssistantView
|
||||
from homeassistant.const import HTTP_FORBIDDEN, HTTP_OK
|
||||
from homeassistant.const import HTTP_BAD_REQUEST, HTTP_FORBIDDEN, HTTP_OK
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util import dt as dt_util
|
||||
@@ -261,7 +261,9 @@ class TokenView(HomeAssistantView):
|
||||
hass, data, str(request[KEY_REAL_IP])
|
||||
)
|
||||
|
||||
return self.json({"error": "unsupported_grant_type"}, status_code=400)
|
||||
return self.json(
|
||||
{"error": "unsupported_grant_type"}, status_code=HTTP_BAD_REQUEST
|
||||
)
|
||||
|
||||
async def _async_handle_revoke_token(self, hass, data):
|
||||
"""Handle revoke token request."""
|
||||
@@ -288,7 +290,7 @@ class TokenView(HomeAssistantView):
|
||||
if client_id is None or not indieauth.verify_client_id(client_id):
|
||||
return self.json(
|
||||
{"error": "invalid_request", "error_description": "Invalid client id"},
|
||||
status_code=400,
|
||||
status_code=HTTP_BAD_REQUEST,
|
||||
)
|
||||
|
||||
code = data.get("code")
|
||||
@@ -296,7 +298,7 @@ class TokenView(HomeAssistantView):
|
||||
if code is None:
|
||||
return self.json(
|
||||
{"error": "invalid_request", "error_description": "Invalid code"},
|
||||
status_code=400,
|
||||
status_code=HTTP_BAD_REQUEST,
|
||||
)
|
||||
|
||||
user = self._retrieve_user(client_id, RESULT_TYPE_USER, code)
|
||||
@@ -304,7 +306,7 @@ class TokenView(HomeAssistantView):
|
||||
if user is None or not isinstance(user, User):
|
||||
return self.json(
|
||||
{"error": "invalid_request", "error_description": "Invalid code"},
|
||||
status_code=400,
|
||||
status_code=HTTP_BAD_REQUEST,
|
||||
)
|
||||
|
||||
# refresh user
|
||||
@@ -336,21 +338,21 @@ class TokenView(HomeAssistantView):
|
||||
if client_id is not None and not indieauth.verify_client_id(client_id):
|
||||
return self.json(
|
||||
{"error": "invalid_request", "error_description": "Invalid client id"},
|
||||
status_code=400,
|
||||
status_code=HTTP_BAD_REQUEST,
|
||||
)
|
||||
|
||||
token = data.get("refresh_token")
|
||||
|
||||
if token is None:
|
||||
return self.json({"error": "invalid_request"}, status_code=400)
|
||||
return self.json({"error": "invalid_request"}, status_code=HTTP_BAD_REQUEST)
|
||||
|
||||
refresh_token = await hass.auth.async_get_refresh_token_by_token(token)
|
||||
|
||||
if refresh_token is None:
|
||||
return self.json({"error": "invalid_grant"}, status_code=400)
|
||||
return self.json({"error": "invalid_grant"}, status_code=HTTP_BAD_REQUEST)
|
||||
|
||||
if refresh_token.client_id != client_id:
|
||||
return self.json({"error": "invalid_request"}, status_code=400)
|
||||
return self.json({"error": "invalid_request"}, status_code=HTTP_BAD_REQUEST)
|
||||
|
||||
access_token = hass.auth.async_create_access_token(refresh_token, remote_addr)
|
||||
|
||||
@@ -386,7 +388,7 @@ class LinkUserView(HomeAssistantView):
|
||||
)
|
||||
|
||||
if credentials is None:
|
||||
return self.json_message("Invalid code", status_code=400)
|
||||
return self.json_message("Invalid code", status_code=HTTP_BAD_REQUEST)
|
||||
|
||||
await hass.auth.async_link_user(user, credentials)
|
||||
return self.json_message("User linked")
|
||||
|
||||
@@ -79,7 +79,7 @@ from homeassistant.components.http.ban import (
|
||||
)
|
||||
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||
from homeassistant.components.http.view import HomeAssistantView
|
||||
from homeassistant.const import HTTP_NOT_FOUND
|
||||
from homeassistant.const import HTTP_BAD_REQUEST, HTTP_NOT_FOUND
|
||||
|
||||
from . import indieauth
|
||||
|
||||
@@ -104,7 +104,7 @@ class AuthProvidersView(HomeAssistantView):
|
||||
if not hass.components.onboarding.async_is_user_onboarded():
|
||||
return self.json_message(
|
||||
message="Onboarding not finished",
|
||||
status_code=400,
|
||||
status_code=HTTP_BAD_REQUEST,
|
||||
message_code="onboarding_required",
|
||||
)
|
||||
|
||||
@@ -170,7 +170,9 @@ class LoginFlowIndexView(HomeAssistantView):
|
||||
if not await indieauth.verify_redirect_uri(
|
||||
request.app["hass"], data["client_id"], data["redirect_uri"]
|
||||
):
|
||||
return self.json_message("invalid client id or redirect uri", 400)
|
||||
return self.json_message(
|
||||
"invalid client id or redirect uri", HTTP_BAD_REQUEST
|
||||
)
|
||||
|
||||
if isinstance(data["handler"], list):
|
||||
handler = tuple(data["handler"])
|
||||
@@ -188,7 +190,7 @@ class LoginFlowIndexView(HomeAssistantView):
|
||||
except data_entry_flow.UnknownHandler:
|
||||
return self.json_message("Invalid handler specified", HTTP_NOT_FOUND)
|
||||
except data_entry_flow.UnknownStep:
|
||||
return self.json_message("Handler does not support init", 400)
|
||||
return self.json_message("Handler does not support init", HTTP_BAD_REQUEST)
|
||||
|
||||
if result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
|
||||
await process_success_login(request)
|
||||
@@ -222,7 +224,7 @@ class LoginFlowResourceView(HomeAssistantView):
|
||||
client_id = data.pop("client_id")
|
||||
|
||||
if not indieauth.verify_client_id(client_id):
|
||||
return self.json_message("Invalid client id", 400)
|
||||
return self.json_message("Invalid client id", HTTP_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
# do not allow change ip during login flow
|
||||
@@ -230,13 +232,13 @@ class LoginFlowResourceView(HomeAssistantView):
|
||||
if flow["flow_id"] == flow_id and flow["context"][
|
||||
"ip_address"
|
||||
] != request.get(KEY_REAL_IP):
|
||||
return self.json_message("IP address changed", 400)
|
||||
return self.json_message("IP address changed", HTTP_BAD_REQUEST)
|
||||
|
||||
result = await self._flow_mgr.async_configure(flow_id, data)
|
||||
except data_entry_flow.UnknownFlow:
|
||||
return self.json_message("Invalid flow specified", HTTP_NOT_FOUND)
|
||||
except vol.Invalid:
|
||||
return self.json_message("User input malformed", 400)
|
||||
return self.json_message("User input malformed", HTTP_BAD_REQUEST)
|
||||
|
||||
if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
|
||||
# @log_invalid_auth does not work here since it returns HTTP 200
|
||||
|
||||
Reference in new issue
Block a user