Skip to content

pytest for missing and obsolete user management topics#3366

Merged
LKuemmel merged 7 commits into
openWB:masterfrom
LKuemmel:pytest
May 18, 2026
Merged

pytest for missing and obsolete user management topics#3366
LKuemmel merged 7 commits into
openWB:masterfrom
LKuemmel:pytest

Conversation

@LKuemmel
Copy link
Copy Markdown
Contributor

pytest, der prüft, ob Topics in der Benutzerverwaltung fehlen oder obsolete Topics in der Benutzerverwaltung enthalten sind

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a pytest that cross-checks the topics in UpdateConfig.valid_topic against the ACLs in default-dynamic-security.json / role-templates.json, to detect missing topics in (or obsolete topics in) the mosquitto user management. Along the way, several obsolete topics are removed from update_config.py, setdata.py, general.py, and the dynsec defaults, and a few currently-used topics that the new test would otherwise flag are added.

Changes:

  • New missing_role_topics_test.py comparing valid topics with role ACLs, with allow-lists for internal/non-persistent topics.
  • Remove obsolete topics (external_buttons_hw, mqtt_bridge, notifications/*, internal_chargepoint/global_config, chargemode_config/pv_charging/phases_to_use) from config/validation/data classes and the dynsec default.
  • Add missing IO/MQTT/EP topics to UpdateConfig.valid_topic and fix the only_local_charge_points regex to be anchored with $; correct two openWB/general/internal_chargepoint/... ACL paths to openWB/internal_chargepoint/....

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/helpermodules/mosquitto_dynsec/missing_role_topics_test.py New pytest comparing UpdateConfig.valid_topic to mosquitto role ACLs.
packages/helpermodules/update_config.py Removes obsolete topics, adds missing IO/MQTT/EP topics, fixes a missing $ anchor.
packages/helpermodules/setdata.py Removes validation branches for the now-obsolete general/notification/external_buttons_hw/mqtt_bridge topics.
packages/control/general.py Drops the obsolete external_buttons_hw field from GeneralData.
data/config/mosquitto/public/default-dynamic-security.json Corrects two internal_chargepoint ACL topics and removes the obsolete pv_charging/phases_to_use ACL.
Comments suppressed due to low confidence (1)

packages/helpermodules/mosquitto_dynsec/missing_role_topics_test.py:141

  • valid_topics = UpdateConfig.valid_topic is a reference to the class-level list, not a copy. The subsequent in-place reassignment valid_topics[i] = valid_topic mutates the shared UpdateConfig.valid_topic (stripping the ^...$ anchors and rewriting character classes), which can affect any other test or code that imports UpdateConfig in the same pytest session. Take a copy (e.g. list(UpdateConfig.valid_topic)) before mutating.
    valid_topics = UpdateConfig.valid_topic
    for i, valid_topic in enumerate(valid_topics):
        if valid_topic.startswith("^"):
            valid_topic = valid_topic[1:]
        if valid_topic.endswith("$"):
            valid_topic = valid_topic[:-1]
        valid_topic = re.sub(r"\[0-9]\+", "+", valid_topic)
        valid_topic = re.sub(r"\[0-1]", "+", valid_topic)
        valid_topic = re.sub(r"\[0-9]", "+", valid_topic)
        valid_topics[i] = valid_topic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3 to +8

from helpermodules.update_config import UpdateConfig


DEFAULT_DYNAMIC_SECURITY_PATH = "/var/www/html/openWB/data/config/mosquitto/public/default-dynamic-security.json"
ROLE_TEMPLATES_PATH = "/var/www/html/openWB/data/config/mosquitto/public/role-templates.json"
Comment on lines +124 to +130
def parse_acl_topic_to_regex(acl_topic):
if "openWB/set" not in acl["topic"] and "#" != acl["topic"] and "openWB/#" != acl["topic"]:
topic = acl["topic"]
# convert mqtt topic pattern to regex pattern
topic_regex = topic.replace("+", "[^/]+").replace("#", ".*").replace("<id>", "[^/]+")
return topic_regex
return None
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

packages/helpermodules/mosquitto_dynsec/missing_role_topics_test.py:168

  • parse_acl_topic_to_regex(acl) is called with the entire ACL dict instead of the topic string. Inside the function, acl_topic.replace(...) will raise an AttributeError because dicts have no replace method. The call should pass acl["topic"] instead of acl. This bug occurs in both loops (around lines 158 and 166).
        for acl in role.get("acls", []):
            if "topic" in acl:
                topic_regex = parse_acl_topic_to_regex(acl)
                if topic_regex:
                    role_topics.append(topic_regex)
    with open(ROLE_TEMPLATES_PATH, "r") as f:
        roles = json.load(f)
    for role in roles:
        for acl in role.get("acls", []):
            if "topic" in acl:
                topic_regex = parse_acl_topic_to_regex(acl)
                if topic_regex:
                    role_topics.append(topic_regex)

Comment on lines +141 to +150
valid_topics = UpdateConfig.valid_topic
for i, valid_topic in enumerate(valid_topics):
if valid_topic.startswith("^"):
valid_topic = valid_topic[1:]
if valid_topic.endswith("$"):
valid_topic = valid_topic[:-1]
valid_topic = re.sub(r"\[0-9]\+", "+", valid_topic)
valid_topic = re.sub(r"\[0-1]", "+", valid_topic)
valid_topic = re.sub(r"\[0-9]", "+", valid_topic)
valid_topics[i] = valid_topic
'openWB/general/grid_protection_active',
'openWB/general/grid_protection_timestamp',
'openWB/general/grid_protection_random_stop',
'openWB/general/price_kwh', # obsolet topic
@LKuemmel LKuemmel changed the title pytest for missing and obsolet user management topics pytest for missing and obsolete user management topics May 18, 2026
@LKuemmel LKuemmel requested a review from Copilot May 18, 2026 10:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@LKuemmel LKuemmel added this to the 2.2.0-Patch.1 milestone May 18, 2026
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bei Änderungen an den default ACLs bitte immer auch die Rolle mit der Versionsnummer hochsetzen.

@LKuemmel LKuemmel marked this pull request as ready for review May 18, 2026 12:48
@LKuemmel LKuemmel merged commit 58fd2b5 into openWB:master May 18, 2026
1 check passed
@LKuemmel LKuemmel deleted the pytest branch May 18, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants