Mount names cannot include non-alphanumerics (#4545)

This commit is contained in:
Mike Degatano 2023-09-09 04:54:04 -04:00 committed by GitHub
parent 60604e33b9
commit 0aafda1477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -27,7 +27,7 @@ from .const import (
MountUsage, MountUsage,
) )
RE_MOUNT_NAME = re.compile(r"^\w+$") RE_MOUNT_NAME = re.compile(r"^[A-Za-z0-9_]+$")
RE_PATH_PART = re.compile(r"^[^\\\/]+") RE_PATH_PART = re.compile(r"^[^\\\/]+")
RE_MOUNT_OPTION = re.compile(r"^[^,=]+$") RE_MOUNT_OPTION = re.compile(r"^[^,=]+$")

View File

@ -711,3 +711,27 @@ async def test_options(api_client: TestClient, coresys: CoreSys, mount):
assert coresys.mounts.default_backup_mount is None assert coresys.mounts.default_backup_mount is None
assert coresys.mounts.save_data.call_count == 2 assert coresys.mounts.save_data.call_count == 2
async def test_api_create_mount_fails_special_chars(
api_client: TestClient,
coresys: CoreSys,
tmp_supervisor_data,
path_extern,
mount_propagation,
):
"""Test creating a mount via API fails with special characters."""
resp = await api_client.post(
"/mounts",
json={
"name": "Überwachungskameras",
"type": "cifs",
"usage": "backup",
"server": "backup.local",
"share": "backups",
"version": "2.0",
},
)
result = await resp.json()
assert result["result"] == "error"
assert "does not match regular expression" in result["message"]