func TestFederationRejectInvite(t *testing.T) {
	deployment := Deploy(t, b.BlueprintFederationTwoLocalOneRemote)
	defer deployment.Destroy(t)
	alice := deployment.Client(t, "hs1", "@alice:hs1")
	charlie := deployment.Client(t, "hs2", "@charlie:hs2")

	// we'll awaken this Waiter when we receive a membership event for Charlie
	var waiter *Waiter

	srv := federation.NewServer(t, deployment,
		federation.HandleKeyRequests(),
		federation.HandleTransactionRequests(func(ev *gomatrixserverlib.Event) {
			sk := "<nil>"
			if ev.StateKey() != nil {
				sk = *ev.StateKey()
			}
			t.Logf("Received PDU %s/%s", ev.Type(), sk)
			if waiter != nil && ev.Type() == "m.room.member" && ev.StateKeyEquals(charlie.UserID) {
				waiter.Finish()
			}
		}, nil),
	)
	srv.UnexpectedRequestsAreErrors = false
	cancel := srv.Listen()
	defer cancel()
	delia := srv.UserID("delia")

	// Alice creates the room, and delia joins
	roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})
	room := srv.MustJoinRoom(t, deployment, "hs1", roomID, delia)

	// Alice invites Charlie; Delia should see the invite
	waiter = NewWaiter()
	alice.InviteRoom(t, roomID, charlie.UserID)
	waiter.Wait(t, 5*time.Second)
	if err := checkMembershipForUser(room, charlie.UserID, "invite"); err != nil {
		t.Errorf("Membership state for charlie after invite: %v", err)
	}

	// Charlie rejects the invite; Delia should see the rejection.
	waiter = NewWaiter()
	charlie.LeaveRoom(t, roomID)
	waiter.Wait(t, 5*time.Second)
	if err := checkMembershipForUser(room, charlie.UserID, "leave"); err != nil {
		t.Errorf("Membership state for charlie after reject: %v", err)
	}
}
// This test ensures that invite rejections are correctly sent out over federation.
//
// We start with two users in a room - alice@hs1, and 'delia' on the Complement test server.
// alice sends an invite to charlie@hs2, which he rejects.
// We check that delia sees the rejection.
//
This test ensures that invite rejections are correctly sent out over federation.

We start with two users in a room - alice@hs1, and 'delia' on the Complement test server.
alice sends an invite to charlie@hs2, which he rejects.
We check that delia sees the rejection.
// This test ensures that invite rejections are correctly sent out over federation . // // We start with two users in a room - alice@hs1 and ' delia ' on the Complement test server . // alice sends an invite to charlie@hs2 which he rejects . // We check that delia sees the rejection . //
func TestFederationRejectInvite(t *testing.T) {
	deployment := Deploy(t, b.BlueprintFederationTwoLocalOneRemote)
	defer deployment.Destroy(t)
	alice := deployment.Client(t, "hs1", "@alice:hs1")
	charlie := deployment.Client(t, "hs2", "@charlie:hs2")
	var waiter *Waiter
	srv := federation.NewServer(t, deployment,
		federation.HandleKeyRequests(),
		federation.HandleTransactionRequests(func(ev *gomatrixserverlib.Event) {
			sk := "<nil>"
			if ev.StateKey() != nil {
				sk = *ev.StateKey()
			}
			t.Logf("Received PDU %s/%s", ev.Type(), sk)
			if waiter != nil && ev.Type() == "m.room.member" && ev.StateKeyEquals(charlie.UserID) {
				waiter.Finish()
			}
		}, nil),
	)
	srv.UnexpectedRequestsAreErrors = false
	cancel := srv.Listen()
	defer cancel()
	delia := srv.UserID("delia")
	roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})
	room := srv.MustJoinRoom(t, deployment, "hs1", roomID, delia)
	waiter = NewWaiter()
	alice.InviteRoom(t, roomID, charlie.UserID)
	waiter.Wait(t, 5*time.Second)
	if err := checkMembershipForUser(room, charlie.UserID, "invite"); err != nil {
		t.Errorf("Membership state for charlie after invite: %v", err)
	}
	waiter = NewWaiter()
	charlie.LeaveRoom(t, roomID)
	waiter.Wait(t, 5*time.Second)
	if err := checkMembershipForUser(room, charlie.UserID, "leave"); err != nil {
		t.Errorf("Membership state for charlie after reject: %v", err)
	}
}
func TestFederationRejectInvite ( t * testing . T ) { deployment := Deploy ( t , b . BlueprintFederationTwoLocalOneRemote ) defer deployment . Destroy ( t ) alice := deployment . Client ( t , " " , " " ) charlie := deployment . Client ( t , " " , " " ) var waiter * Waiter srv := federation . NewServer ( t , deployment , federation . HandleKeyRequests ( ) , federation . HandleTransactionRequests ( func ( ev * gomatrixserverlib . Event ) { sk := " " if ev . StateKey ( ) != nil { sk = * ev . StateKey ( ) } t . Logf ( " " , ev . Type ( ) , sk ) if waiter != nil && ev . Type ( ) == " " && ev . StateKeyEquals ( charlie . UserID ) { waiter . Finish ( ) } } , nil ) , ) srv . UnexpectedRequestsAreErrors = false cancel := srv . Listen ( ) defer cancel ( ) delia := srv . UserID ( " " ) roomID := alice . CreateRoom ( t , map [ string ] interface { } { " " : " " } ) room := srv . MustJoinRoom ( t , deployment , " " , roomID , delia ) waiter = NewWaiter ( ) alice . InviteRoom ( t , roomID , charlie . UserID ) waiter . Wait ( t , 5 * time . Second ) if err := checkMembershipForUser ( room , charlie . UserID , " " ) ; err != nil { t . Errorf ( " " , err ) } waiter = NewWaiter ( ) charlie . LeaveRoom ( t , roomID ) waiter . Wait ( t , 5 * time . Second ) if err := checkMembershipForUser ( room , charlie . UserID , " " ) ; err != nil { t . Errorf ( " " , err ) } }
This test ensures that invite rejections are correctly sent out over federation.
This test ensures that invite rejections are correctly sent out over federation .
// we'll awaken this Waiter when we receive a membership event for Charlie // Alice creates the room, and delia joins // Alice invites Charlie; Delia should see the invite // Charlie rejects the invite; Delia should see the rejection.