mirror of
https://github.com/home-assistant/core.git
synced 2026-10-25 15:54:13 -04:00
Verify Proxmox permissions when creating snapshots (#166547)
This commit is contained in:
@@ -31,9 +31,20 @@ POWER_PERMISSIONS = {
|
||||
"/vms/101": {"VM.PowerMgmt": 0},
|
||||
}
|
||||
|
||||
SNAPSHOT_PERMISSIONS = {
|
||||
"/vms": {"VM.Snapshot": 1},
|
||||
"/vms/101": {"VM.Snapshot": 0},
|
||||
}
|
||||
|
||||
MERGED_PERMISSIONS = {
|
||||
key: {**AUDIT_PERMISSIONS.get(key, {}), **POWER_PERMISSIONS.get(key, {})}
|
||||
for key in set(AUDIT_PERMISSIONS) | set(POWER_PERMISSIONS)
|
||||
key: {
|
||||
**AUDIT_PERMISSIONS.get(key, {}),
|
||||
**POWER_PERMISSIONS.get(key, {}),
|
||||
**SNAPSHOT_PERMISSIONS.get(key, {}),
|
||||
}
|
||||
for key in set(AUDIT_PERMISSIONS)
|
||||
| set(POWER_PERMISSIONS)
|
||||
| set(SNAPSHOT_PERMISSIONS)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -370,6 +370,7 @@ async def test_container_buttons_exceptions(
|
||||
("button.pve1_start_all", "no_permission_node_power"),
|
||||
("button.ct_nginx_start", "no_permission_vm_lxc_power"),
|
||||
("button.vm_web_start", "no_permission_vm_lxc_power"),
|
||||
("button.vm_web_create_snapshot", "no_permission_snapshot"),
|
||||
],
|
||||
)
|
||||
async def test_node_buttons_permission_denied_for_auditor_role(
|
||||
@@ -394,19 +395,29 @@ async def test_node_buttons_permission_denied_for_auditor_role(
|
||||
assert exc_info.value.translation_key == translation_key
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("entity_id", "translation_key"),
|
||||
[
|
||||
("button.vm_db_start", "no_permission_vm_lxc_power"),
|
||||
("button.vm_db_create_snapshot", "no_permission_snapshot"),
|
||||
],
|
||||
)
|
||||
async def test_vm_buttons_denied_for_specific_vm(
|
||||
hass: HomeAssistant,
|
||||
mock_proxmox_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_id: str,
|
||||
translation_key: str,
|
||||
) -> None:
|
||||
"""Test that button only works on actual permissions."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
mock_proxmox_client._node_mock.qemu(101)
|
||||
|
||||
with pytest.raises(ServiceValidationError):
|
||||
with pytest.raises(ServiceValidationError) as exc_info:
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
{ATTR_ENTITY_ID: "button.vm_db_start"},
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
assert exc_info.value.translation_key == translation_key
|
||||
|
||||
Reference in New Issue
Block a user