Fix pamd error when inserting a new rule at the end. Fixes #28487 (#28488)

* When inserting a new rule in `insert_after_rule`, check if the old rule is
the last rule, to avoid a list index out of range error when attempting to
access the next rule.
* Add a test for inserting a new rule after the last rule.
This commit is contained in:
David Kretch 2017-12-13 16:31:20 -05:00 committed by Adam Miller
commit 98260f9884
2 changed files with 13 additions and 1 deletions

View file

@ -483,7 +483,10 @@ def insert_after_rule(service, old_rule, new_rule):
if (old_rule.rule_type == rule.rule_type and
old_rule.rule_control == rule.rule_control and
old_rule.rule_module_path == rule.rule_module_path):
if (new_rule.rule_type != service.rules[index + 1].rule_type or
if (index == len(service.rules) - 1):
service.rules.insert(len(service.rules), new_rule)
changed = True
elif (new_rule.rule_type != service.rules[index + 1].rule_type or
new_rule.rule_control !=
service.rules[index + 1].rule_control or
new_rule.rule_module_path !=