From e4aeee9d85d3c093af609921be0eb71caa111470 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 8 Apr 2026 13:22:25 +0200 Subject: [PATCH] Fix ProxmoxVE migration causing reauthentication (#167624) --- .../components/proxmoxve/__init__.py | 8 ++++++ tests/components/proxmoxve/test_init.py | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/homeassistant/components/proxmoxve/__init__.py b/homeassistant/components/proxmoxve/__init__.py index 6512b1761cd9..3e680f212a2d 100644 --- a/homeassistant/components/proxmoxve/__init__.py +++ b/homeassistant/components/proxmoxve/__init__.py @@ -189,6 +189,14 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ProxmoxConfigEntry) -> # Migration for additional configuration options added to support API tokens if entry.version < 3: data = dict(entry.data) + # If CONF_REALM wasn't there yet, extract from username + if CONF_REALM not in data: + data[CONF_REALM] = DEFAULT_REALM + if "@" in data.get(CONF_USERNAME, ""): + username, realm = data[CONF_USERNAME].split("@", 1) + data[CONF_USERNAME] = username + data[CONF_REALM] = realm.lower() + realm = data[CONF_REALM].lower() # If the realm is one of the base providers, set the provider to match the realm. diff --git a/tests/components/proxmoxve/test_init.py b/tests/components/proxmoxve/test_init.py index 205e54f1e334..a3f7b21181ae 100644 --- a/tests/components/proxmoxve/test_init.py +++ b/tests/components/proxmoxve/test_init.py @@ -281,6 +281,33 @@ async def test_migration_v2_to_v3( assert entry.data[CONF_REALM] == AUTH_PAM +async def test_migration_v2_to_v3_without_realm( + hass: HomeAssistant, +) -> None: + """Test migration from version 2 to 3.""" + entry = MockConfigEntry( + domain=DOMAIN, + version=2, + unique_id="1", + data={ + CONF_HOST: "http://test_host", + CONF_PORT: 8006, + CONF_USERNAME: "test_user@pam", + CONF_PASSWORD: "test_password", + CONF_VERIFY_SSL: True, + }, + ) + entry.add_to_hass(hass) + assert entry.version == 2 + + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + assert entry.version == 3 + assert entry.data[CONF_AUTH_METHOD] == AUTH_PAM + assert entry.data[CONF_REALM] == AUTH_PAM + + async def test_new_vm_creates_entity( hass: HomeAssistant, mock_proxmox_client: MagicMock,