@@ -12,6 +12,17 @@ import (
1212	"github.com/tidwall/gjson" 
1313)
1414
15+ var  (
16+ 	spaceChildEventType   =  "org.matrix.msc1772.space.child" 
17+ 	spaceParentEventType  =  "org.matrix.msc1772.space.parent" 
18+ )
19+ 
20+ // the API doesn't return event IDs so we need to key off the 
21+ // 3-uple of room ID, event type and state key 
22+ func  eventKey (srcRoomID , dstRoomID , evType  string ) string  {
23+ 	return  srcRoomID  +  "|"  +  dstRoomID  +  "|"  +  evType 
24+ }
25+ 
1526// Tests that the CS API for MSC2946 works correctly. Creates a space directory like: 
1627//     Root 
1728//      | 
@@ -39,8 +50,6 @@ import (
3950// - Events are returned correctly. 
4051// - Redacting links works correctly. 
4152func  TestClientSpacesSummary (t  * testing.T ) {
42- 	spaceChildEventType  :=  "org.matrix.msc1772.space.child" 
43- 	spaceParentEventType  :=  "org.matrix.msc1772.space.parent" 
4453	deployment  :=  Deploy (t , "msc2946" , b .BlueprintOneToOneRoom )
4554	defer  deployment .Destroy (t )
4655
@@ -91,12 +100,6 @@ func TestClientSpacesSummary(t *testing.T) {
91100		},
92101	})
93102
94- 	// the API doesn't return event IDs so we need to key off the 
95- 	// 3-uple of room ID, event type and state key 
96- 	eventKey  :=  func (srcRoomID , dstRoomID , evType  string ) string  {
97- 		return  srcRoomID  +  "|"  +  dstRoomID  +  "|"  +  evType 
98- 	}
99- 
100103	// create the links 
101104	rootToR1  :=  eventKey (root , r1 , spaceChildEventType )
102105	alice .SendEventSynced (t , root , b.Event {
@@ -281,3 +284,113 @@ func TestClientSpacesSummary(t *testing.T) {
281284		})
282285	})
283286}
287+ 
288+ // Tests that MSC2946 works over federation. Creates a space directory like: 
289+ //     ROOT 
290+ //      | 
291+ // _____|________ 
292+ // |    |       | 
293+ // R1  SS1      r2 
294+ //      |________ 
295+ //      |        | 
296+ //     ss2      r3 
297+ //      | 
298+ //      R4 
299+ // 
300+ // Where R/SS = on hs1, and r/ss = on hs2. Links are space children state events only. 
301+ // Tests that: 
302+ // - Querying from root returns the entire graph 
303+ func  TestFederatedClientSpaces (t  * testing.T ) {
304+ 	deployment  :=  Deploy (t , "msc2946" , b .BlueprintFederationOneToOneRoom )
305+ 	defer  deployment .Destroy (t )
306+ 
307+ 	worldReadable  :=  map [string ]interface {}{
308+ 		"preset" : "public_chat" ,
309+ 		"initial_state" : []map [string ]interface {}{
310+ 			{
311+ 				"type" :      "m.room.history_visibility" ,
312+ 				"state_key" : "" ,
313+ 				"content" : map [string ]string {
314+ 					"history_visibility" : "world_readable" ,
315+ 				},
316+ 			},
317+ 		},
318+ 	}
319+ 	// create the rooms 
320+ 	alice  :=  deployment .Client (t , "hs1" , "@alice:hs1" )
321+ 	root  :=  alice .CreateRoom (t , worldReadable )
322+ 	r1  :=  alice .CreateRoom (t , worldReadable )
323+ 	ss1  :=  alice .CreateRoom (t , worldReadable )
324+ 	r4  :=  alice .CreateRoom (t , worldReadable )
325+ 	bob  :=  deployment .Client (t , "hs2" , "@bob:hs2" )
326+ 	r2  :=  bob .CreateRoom (t , worldReadable )
327+ 	ss2  :=  bob .CreateRoom (t , worldReadable )
328+ 	r3  :=  bob .CreateRoom (t , worldReadable )
329+ 
330+ 	// create the links 
331+ 	rootToR1  :=  eventKey (root , r1 , spaceChildEventType )
332+ 	alice .SendEventSynced (t , root , b.Event {
333+ 		Type :     spaceChildEventType ,
334+ 		StateKey : & r1 ,
335+ 		Content : map [string ]interface {}{
336+ 			"via" : []string {"hs1" },
337+ 		},
338+ 	})
339+ 	rootToSS1  :=  eventKey (root , ss1 , spaceChildEventType )
340+ 	alice .SendEventSynced (t , root , b.Event {
341+ 		Type :     spaceChildEventType ,
342+ 		StateKey : & ss1 ,
343+ 		Content : map [string ]interface {}{
344+ 			"via" : []string {"hs1" },
345+ 		},
346+ 	})
347+ 	rootToR2  :=  eventKey (root , r2 , spaceChildEventType )
348+ 	alice .SendEventSynced (t , root , b.Event {
349+ 		Type :     spaceChildEventType ,
350+ 		StateKey : & r2 ,
351+ 		Content : map [string ]interface {}{
352+ 			"via" : []string {"hs2" },
353+ 		},
354+ 	})
355+ 	ss1ToSS2  :=  eventKey (ss1 , ss2 , spaceChildEventType )
356+ 	alice .SendEventSynced (t , ss1 , b.Event {
357+ 		Type :     spaceChildEventType ,
358+ 		StateKey : & ss2 ,
359+ 		Content : map [string ]interface {}{
360+ 			"via" : []string {"hs2" },
361+ 		},
362+ 	})
363+ 	ss1ToR3  :=  eventKey (ss1 , r3 , spaceChildEventType )
364+ 	alice .SendEventSynced (t , ss1 , b.Event {
365+ 		Type :     spaceChildEventType ,
366+ 		StateKey : & r3 ,
367+ 		Content : map [string ]interface {}{
368+ 			"via" : []string {"hs2" },
369+ 		},
370+ 	})
371+ 	ss2ToR4  :=  eventKey (ss2 , r4 , spaceChildEventType )
372+ 	bob .SendEventSynced (t , ss2 , b.Event {
373+ 		Type :     spaceChildEventType ,
374+ 		StateKey : & r4 ,
375+ 		Content : map [string ]interface {}{
376+ 			"via" : []string {"hs1" },
377+ 		},
378+ 	})
379+ 	allEvents  :=  []string {
380+ 		rootToR1 , rootToR2 , rootToSS1 ,
381+ 		ss1ToR3 , ss1ToSS2 ,
382+ 		ss2ToR4 ,
383+ 	}
384+ 	t .Logf ("rooms: %v" , allEvents )
385+ 
386+ 	res  :=  alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "rooms" , root , "spaces" }, map [string ]interface {}{})
387+ 	must .MatchResponse (t , res , match.HTTPResponse {
388+ 		JSON : []match.JSON {
389+ 			match .JSONCheckOff ("rooms" , []interface {}{
390+ 				root , r1 , r2 , r3 , r4 , ss1 , ss2 ,
391+ 			}, func (r  gjson.Result ) interface {} {
392+ 				return  r .Get ("room_id" ).Str 
393+ 			}, nil ),
394+ 		},
395+ 	})
396+ }
0 commit comments