Merge branch 'nico/fix-unknown-push-conditions' into 'main'

fix: Skip rules with unknown conditions

See merge request famedly/company/frontend/famedlysdk!1277
This commit is contained in:
td 2023-04-27 18:05:42 +00:00
commit aa24c0ce66
2 changed files with 25 additions and 0 deletions

View File

@ -186,6 +186,8 @@ class _OptimizedRules {
notificationPermissions.add(key);
}
break;
default:
throw Exception('Unknown push condition: ${condition.kind}');
}
}
actions = EvaluatedPushRuleAction.fromActions(rule.actions);

View File

@ -208,6 +208,29 @@ void main() {
testNotMatch(override_ruleset2, event);
});
test('invalid push condition', () async {
final invalid_ruleset = PushRuleSet(override: [
PushRule(ruleId: 'my.rule', default$: false, enabled: true, actions: [
'notify',
{'set_tweak': 'highlight', 'value': true},
{'set_tweak': 'sound', 'value': 'goose.wav'},
], conditions: [
PushCondition(
kind: 'invalidcondition', pattern: 'fox', key: 'content.body'),
])
]);
expect(() => PushruleEvaluator.fromRuleset(invalid_ruleset),
returnsNormally);
final evaluator = PushruleEvaluator.fromRuleset(invalid_ruleset);
final event = Event.fromJson(jsonObj, room);
final actions = evaluator.match(event);
expect(actions.highlight, false);
expect(actions.sound, null);
expect(actions.notify, false);
});
test('match_display_name rule', () async {
final event = Event.fromJson(jsonObj, room);
(event.room.states[EventTypes.RoomMember] ??= {})[client.userID!] =