Skip to content

Commit ec35877

Browse files
author
David Robertson
authored
Test aliases during a partial join resync (#537)
1 parent ec6e09c commit ec35877

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

tests/federation_room_join_partial_state_test.go

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,6 @@ func TestPartialStateJoin(t *testing.T) {
18131813
t.Errorf("SendKnock: non-HTTPError: %v", err)
18141814
}
18151815
})
1816-
18171816
t.Run("Outgoing device list updates", func(t *testing.T) {
18181817
// setupOutgoingDeviceListUpdateTest sets up two complement homeservers.
18191818
// A room is created on the first complement server, containing only local users.
@@ -3087,6 +3086,97 @@ func TestPartialStateJoin(t *testing.T) {
30873086
mustQueryKeysWithFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
30883087
})
30893088
})
3089+
3090+
// Test that a) you can add a room alias during a resync and that
3091+
// b) querying that alias returns at least the servers we were told
3092+
// about in the /send_join response.
3093+
t.Run("Room aliases can be added and queried during a resync", func(t *testing.T) {
3094+
// Alice begins a partial join to a room.
3095+
alice := deployment.RegisterUser(t, "hs1", "t40alice", "secret", false)
3096+
server := createTestServer(t, deployment)
3097+
cancel := server.Listen()
3098+
defer cancel()
3099+
3100+
serverRoom := createTestRoom(t, server, alice.GetDefaultRoomVersion(t))
3101+
psjResult := beginPartialStateJoin(t, server, serverRoom, alice)
3102+
defer psjResult.Destroy()
3103+
3104+
// Alice creates an alias for the room
3105+
aliasName := "#t40alice-room:hs1"
3106+
alice.MustDoFunc(
3107+
t,
3108+
"PUT",
3109+
[]string{"_matrix", "client", "v3", "directory", "room", aliasName},
3110+
client.WithJSONBody(t, map[string]interface{}{
3111+
"room_id": serverRoom.RoomID,
3112+
}),
3113+
)
3114+
3115+
// Alice then queries that alias
3116+
response := alice.MustDoFunc(
3117+
t,
3118+
"GET",
3119+
[]string{"_matrix", "client", "v3", "directory", "room", aliasName},
3120+
client.WithJSONBody(t, map[string]interface{}{
3121+
"room_id": serverRoom.RoomID,
3122+
}),
3123+
)
3124+
3125+
// The response should be 200 OK, should include the room id and
3126+
// should include both HSes.
3127+
spec := match.HTTPResponse{
3128+
StatusCode: 200,
3129+
JSON: []match.JSON{
3130+
match.JSONKeyEqual("room_id", serverRoom.RoomID),
3131+
match.JSONCheckOff(
3132+
"servers",
3133+
[]interface{}{"hs1", server.ServerName()},
3134+
func(r gjson.Result) interface{} { return r.Str },
3135+
nil,
3136+
),
3137+
},
3138+
}
3139+
must.MatchResponse(t, response, spec)
3140+
})
3141+
3142+
// Test that you can delete a room alias during a resync that you added during
3143+
// the resync.
3144+
t.Run("Room aliases can be added and deleted during a resync", func(t *testing.T) {
3145+
// Alice begins a partial join to a room.
3146+
alice := deployment.RegisterUser(t, "hs1", "t41alice", "secret", false)
3147+
server := createTestServer(t, deployment)
3148+
cancel := server.Listen()
3149+
defer cancel()
3150+
3151+
serverRoom := createTestRoom(t, server, alice.GetDefaultRoomVersion(t))
3152+
psjResult := beginPartialStateJoin(t, server, serverRoom, alice)
3153+
defer psjResult.Destroy()
3154+
3155+
// Alice creates an alias for the room
3156+
aliasName := "#t41alice-room:hs1"
3157+
alice.MustDoFunc(
3158+
t,
3159+
"PUT",
3160+
[]string{"_matrix", "client", "v3", "directory", "room", aliasName},
3161+
client.WithJSONBody(t, map[string]interface{}{
3162+
"room_id": serverRoom.RoomID,
3163+
}),
3164+
)
3165+
3166+
// Alice then deletes that alias
3167+
response := alice.MustDoFunc(
3168+
t,
3169+
"DELETE",
3170+
[]string{"_matrix", "client", "v3", "directory", "room", aliasName},
3171+
)
3172+
3173+
// The response should be 200 OK. (Strictly speaking it should have an
3174+
// empty json object as the response body but that's not important here)
3175+
spec := match.HTTPResponse{
3176+
StatusCode: 200,
3177+
}
3178+
must.MatchResponse(t, response, spec)
3179+
})
30903180
}
30913181

30923182
// test reception of an event over federation during a resync

0 commit comments

Comments
 (0)