Strip whitespace from application credentials (#84461)

fixes undefined
This commit is contained in:
Allen Porter 2022-12-22 11:12:17 -08:00 committed by GitHub
parent 20b5e92656
commit 12e7ea3a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -50,8 +50,8 @@ DEFAULT_IMPORT_NAME = "Import from configuration.yaml"
CREATE_FIELDS = {
vol.Required(CONF_DOMAIN): cv.string,
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CLIENT_SECRET): cv.string,
vol.Required(CONF_CLIENT_ID): vol.All(cv.string, vol.Strip),
vol.Required(CONF_CLIENT_SECRET): vol.All(cv.string, vol.Strip),
vol.Optional(CONF_AUTH_DOMAIN): cv.string,
vol.Optional(CONF_NAME): cv.string,
}

View File

@ -795,3 +795,32 @@ async def test_remove_config_entry_without_app_credentials(
"config_entry", {"config_entry_id": entries[0].entry_id}
)
assert "application_credential_id" not in result
async def test_websocket_create_strips_whitespace(ws_client: ClientFixture):
"""Test websocket create command with whitespace in the credentials."""
client = await ws_client()
result = await client.cmd_result(
"create",
{
CONF_DOMAIN: TEST_DOMAIN,
CONF_CLIENT_ID: f" {CLIENT_ID} ",
CONF_CLIENT_SECRET: f" {CLIENT_SECRET} ",
},
)
assert result == {
CONF_DOMAIN: TEST_DOMAIN,
CONF_CLIENT_ID: CLIENT_ID,
CONF_CLIENT_SECRET: CLIENT_SECRET,
"id": ID,
}
result = await client.cmd_result("list")
assert result == [
{
CONF_DOMAIN: TEST_DOMAIN,
CONF_CLIENT_ID: CLIENT_ID,
CONF_CLIENT_SECRET: CLIENT_SECRET,
"id": ID,
}
]