Skip to content

Commit e1d78d9

Browse files
committed
fix(advTags): Validated that root of path was correct and present
1 parent c486fe3 commit e1d78d9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

kepconfig/adv_tags/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
specific objects within the Kepware Configuration API
99
"""
1010

11+
from ..error import KepError
1112
from . import adv_tag_group, average_tags, derived_tags, complex_tags, cumulative_tags, min_tags, max_tags, link_tags
1213
ADV_TAGS_ROOT = '/project/_advancedtags'
1314

@@ -28,6 +29,9 @@ def _adv_tag_path_split(path: str, *, isItem=False) -> dict:
2829
return = {'adv_tag_root': '_advancedtags', 'tag_path': ['ch1','dev1']}
2930
'''
3031
path_list = path.split('.', 2)
32+
if path_list[0] != '_advancedtags':
33+
raise KepError('Error: Invalid advanced tag path - Must start with "_advancedtags"')
34+
3135
path_obj = {}
3236
for x in range(0, len(path_list)):
3337
if x == 0:

tests/adv_tags_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def test_adv_tag_group_get(server):
222222
assert type(adv_tags.adv_tag_group.get_tag_group(server, adv_tag_child_group_path)) == dict
223223

224224
# Get all advanced tag groups at root
225-
assert type(adv_tags.adv_tag_group.get_all_tag_groups(server, '')) == list
225+
assert type(adv_tags.adv_tag_group.get_all_tag_groups(server, '_advancedtags')) == list
226226

227227
# Get all advanced tag groups under a parent
228228
result = adv_tags.adv_tag_group.get_all_tag_groups(server, f'_advancedtags.{adv_tag_group_name}')
@@ -232,6 +232,11 @@ def test_adv_tag_group_get(server):
232232
assert type(result) == list
233233
assert len(result) == 0
234234

235+
def test_adv_tag_bad_root_in_path(server):
236+
# Test bad advanced tag path
237+
with pytest.raises(error.KepError):
238+
adv_tags.adv_tag_group.get_tag_group(server, '_wrongroot.AdvTagGroup1')
239+
235240
def test_adv_tag_group_modify(server):
236241
# Modify advanced tag group
237242
tag_group_data = {

0 commit comments

Comments
 (0)