|
1 |
| -// Copyright (c) 2020 Tulir Asokan |
| 1 | +// Copyright (c) 2022 Tulir Asokan |
2 | 2 | //
|
3 | 3 | // This Source Code Form is subject to the terms of the Mozilla Public
|
4 | 4 | // License, v. 2.0. If a copy of the MPL was not distributed with this
|
@@ -31,6 +31,87 @@ func TestPushRule_Match_Conditions(t *testing.T) {
|
31 | 31 | assert.True(t, rule.Match(blankTestRoom, evt))
|
32 | 32 | }
|
33 | 33 |
|
| 34 | +func TestPushRule_Match_Conditions_NestedKey(t *testing.T) { |
| 35 | + cond1 := newMatchPushCondition("content.m.relates_to.rel_type", "m.replace") |
| 36 | + rule := &pushrules.PushRule{ |
| 37 | + Type: pushrules.OverrideRule, |
| 38 | + Enabled: true, |
| 39 | + Conditions: []*pushrules.PushCondition{cond1}, |
| 40 | + } |
| 41 | + |
| 42 | + evt := newFakeEvent(event.EventMessage, &event.MessageEventContent{ |
| 43 | + MsgType: event.MsgEmote, |
| 44 | + Body: "is testing pushrules", |
| 45 | + RelatesTo: &event.RelatesTo{ |
| 46 | + Type: event.RelReplace, |
| 47 | + EventID: "$meow", |
| 48 | + }, |
| 49 | + }) |
| 50 | + assert.True(t, rule.Match(blankTestRoom, evt)) |
| 51 | + |
| 52 | + evt = newFakeEvent(event.EventMessage, &event.MessageEventContent{ |
| 53 | + MsgType: event.MsgEmote, |
| 54 | + Body: "is testing pushrules", |
| 55 | + }) |
| 56 | + assert.False(t, rule.Match(blankTestRoom, evt)) |
| 57 | +} |
| 58 | + |
| 59 | +func TestPushRule_Match_Conditions_NestedKey_Boolean(t *testing.T) { |
| 60 | + cond1 := newMatchPushCondition("content.fi.mau.will_auto_accept", "true") |
| 61 | + rule := &pushrules.PushRule{ |
| 62 | + Type: pushrules.OverrideRule, |
| 63 | + Enabled: true, |
| 64 | + Conditions: []*pushrules.PushCondition{cond1}, |
| 65 | + } |
| 66 | + |
| 67 | + evt := newFakeEvent(event.EventMessage, &event.MemberEventContent{ |
| 68 | + Membership: "invite", |
| 69 | + }) |
| 70 | + assert.False(t, rule.Match(blankTestRoom, evt)) |
| 71 | + evt.Content.Raw["fi.mau.will_auto_accept"] = true |
| 72 | + assert.True(t, rule.Match(blankTestRoom, evt)) |
| 73 | + delete(evt.Content.Raw, "fi.mau.will_auto_accept") |
| 74 | + assert.False(t, rule.Match(blankTestRoom, evt)) |
| 75 | + evt.Content.Raw["fi.mau"] = map[string]interface{}{ |
| 76 | + "will_auto_accept": true, |
| 77 | + } |
| 78 | + assert.True(t, rule.Match(blankTestRoom, evt)) |
| 79 | +} |
| 80 | + |
| 81 | +func TestPushRule_Match_Conditions_EscapedKey(t *testing.T) { |
| 82 | + cond1 := newMatchPushCondition("content.fi\\.mau\\.will_auto_accept", "true") |
| 83 | + rule := &pushrules.PushRule{ |
| 84 | + Type: pushrules.OverrideRule, |
| 85 | + Enabled: true, |
| 86 | + Conditions: []*pushrules.PushCondition{cond1}, |
| 87 | + } |
| 88 | + |
| 89 | + evt := newFakeEvent(event.EventMessage, &event.MemberEventContent{ |
| 90 | + Membership: "invite", |
| 91 | + }) |
| 92 | + assert.False(t, rule.Match(blankTestRoom, evt)) |
| 93 | + evt.Content.Raw["fi.mau.will_auto_accept"] = true |
| 94 | + assert.True(t, rule.Match(blankTestRoom, evt)) |
| 95 | +} |
| 96 | + |
| 97 | +func TestPushRule_Match_Conditions_EscapedKey_NoNesting(t *testing.T) { |
| 98 | + cond1 := newMatchPushCondition("content.fi\\.mau\\.will_auto_accept", "true") |
| 99 | + rule := &pushrules.PushRule{ |
| 100 | + Type: pushrules.OverrideRule, |
| 101 | + Enabled: true, |
| 102 | + Conditions: []*pushrules.PushCondition{cond1}, |
| 103 | + } |
| 104 | + |
| 105 | + evt := newFakeEvent(event.EventMessage, &event.MemberEventContent{ |
| 106 | + Membership: "invite", |
| 107 | + }) |
| 108 | + assert.False(t, rule.Match(blankTestRoom, evt)) |
| 109 | + evt.Content.Raw["fi.mau"] = map[string]interface{}{ |
| 110 | + "will_auto_accept": true, |
| 111 | + } |
| 112 | + assert.False(t, rule.Match(blankTestRoom, evt)) |
| 113 | +} |
| 114 | + |
34 | 115 | func TestPushRule_Match_Conditions_Disabled(t *testing.T) {
|
35 | 116 | cond1 := newMatchPushCondition("content.msgtype", "m.emote")
|
36 | 117 | cond2 := newMatchPushCondition("content.body", "*pushrules")
|
|
0 commit comments