Skip to content

Commit 1e6f3f8

Browse files
authored
Test for send_join with unverifiable auth events (#216)
Test the behaviour when we send a send_join response with unverifiable auth events
1 parent 2aa90bb commit 1e6f3f8

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

tests/federation_room_join_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ func TestJoinViaRoomIDAndServerName(t *testing.T) {
8888
// - Events with missing signatures
8989
// - Events with bad signatures
9090
// - Events with correct signatures but the keys cannot be obtained
91+
//
9192
// None of these events will be critical to the integrity of the room: that
92-
// is to say these events are never pointed to as auth_events - therefore the
93-
// room should still be joinable.
93+
// is to say these events are not used as auth_events for the actual join -
94+
// therefore the room should still be joinable.
9495
//
9596
// This test works by creating several federated rooms on Complement which have
9697
// the properties listed above, then asking HS1 to join them and make sure that
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// +build !dendrite_blacklist
2+
3+
package tests
4+
5+
import (
6+
"encoding/json"
7+
"testing"
8+
9+
"github.com/matrix-org/gomatrixserverlib"
10+
"github.com/tidwall/sjson"
11+
12+
"github.com/matrix-org/complement/internal/b"
13+
"github.com/matrix-org/complement/internal/docker"
14+
"github.com/matrix-org/complement/internal/federation"
15+
"github.com/matrix-org/complement/internal/must"
16+
)
17+
18+
// This test is an extension of TestJoinFederatedRoomWithUnverifiableEvents.
19+
// It's currently split out, because it fails on Dendrite
20+
// - see https://github.com/matrix-org/dendrite/issues/2028
21+
func TestJoinFederatedRoomWithUnverifiableAuthEvents(t *testing.T) {
22+
deployment := Deploy(t, b.BlueprintAlice)
23+
defer deployment.Destroy(t)
24+
25+
srv := federation.NewServer(t, deployment,
26+
federation.HandleKeyRequests(),
27+
federation.HandleMakeSendJoinRequests(),
28+
federation.HandleTransactionRequests(nil, nil),
29+
)
30+
srv.UnexpectedRequestsAreErrors = false
31+
cancel := srv.Listen()
32+
defer cancel()
33+
34+
ver := gomatrixserverlib.RoomVersionV6
35+
charlie := srv.UserID("charlie")
36+
37+
t.Run("/send_join response with state with unverifiable auth events shouldn't block room join", func(t *testing.T) {
38+
//t.Parallel()
39+
room := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie))
40+
roomAlias := srv.MakeAliasMapping("UnverifiableAuthEvents", room.RoomID)
41+
42+
// create a normal event then modify the signatures
43+
rawEvent := srv.MustCreateEvent(t, room, b.Event{
44+
Sender: charlie,
45+
StateKey: &charlie,
46+
Type: "m.room.member",
47+
Content: map[string]interface{}{
48+
"membership": "join",
49+
"name": "This event has a bad signature",
50+
},
51+
}).JSON()
52+
rawSig, err := json.Marshal(map[string]interface{}{
53+
docker.HostnameRunningComplement: map[string]string{
54+
string(srv.KeyID): "/3z+pJjiJXWhwfqIEzmNksvBHCoXTktK/y0rRuWJXw6i1+ygRG/suDCKhFuuz6gPapRmEMPVILi2mJqHHXPKAg",
55+
},
56+
})
57+
must.NotError(t, "failed to marshal bad signature block", err)
58+
rawEvent, err = sjson.SetRawBytes(rawEvent, "signatures", rawSig)
59+
must.NotError(t, "failed to modify signatures key from event", err)
60+
badlySignedEvent, err := gomatrixserverlib.NewEventFromTrustedJSON(rawEvent, false, ver)
61+
must.NotError(t, "failed to make Event from badly signed event JSON", err)
62+
room.AddEvent(badlySignedEvent)
63+
t.Logf("Created badly signed auth event %s", badlySignedEvent.EventID())
64+
65+
// and now add another event which will use it as an auth event.
66+
goodEvent := srv.MustCreateEvent(t, room, b.Event{
67+
Sender: charlie,
68+
StateKey: &charlie,
69+
Type: "m.room.member",
70+
Content: map[string]interface{}{
71+
"membership": "leave",
72+
},
73+
})
74+
// double-check that the bad event is in its auth events
75+
containsEvent := false
76+
for _, authEventID := range goodEvent.AuthEventIDs() {
77+
if authEventID == badlySignedEvent.EventID() {
78+
containsEvent = true
79+
break
80+
}
81+
}
82+
if !containsEvent {
83+
t.Fatalf("Bad event didn't appear in auth events of state event")
84+
}
85+
room.AddEvent(goodEvent)
86+
t.Logf("Created state event %s", goodEvent.EventID())
87+
88+
alice := deployment.Client(t, "hs1", "@alice:hs1")
89+
alice.JoinRoom(t, roomAlias, nil)
90+
})
91+
}

0 commit comments

Comments
 (0)