MCPcopy
hub / github.com/livekit/livekit / TestSingleNodeUpdateSubscriptionPermissions

Function TestSingleNodeUpdateSubscriptionPermissions

test/singlenode_test.go:749–823  ·  view source on GitHub ↗

don't give user subscribe permissions initially, and ensure autosubscribe is triggered afterwards

(t *testing.T)

Source from the content-addressed store, hash-verified

747
748// don't give user subscribe permissions initially, and ensure autosubscribe is triggered afterwards
749func TestSingleNodeUpdateSubscriptionPermissions(t *testing.T) {
750 if testing.Short() {
751 t.SkipNow()
752 return
753 }
754 _, finish := setupSingleNodeTest("TestSingleNodeUpdateSubscriptionPermissions")
755 defer finish()
756
757 for _, testRTCServicePath := range testRTCServicePaths {
758 t.Run(fmt.Sprintf("testRTCServicePath=%s", testRTCServicePath.String()), func(t *testing.T) {
759 pub := createRTCClient("pub", defaultServerPort, testRTCServicePath, nil)
760
761 grant := &auth.VideoGrant{RoomJoin: true, Room: testRoom}
762 grant.SetCanSubscribe(false)
763 at := auth.NewAccessToken(testApiKey, testApiSecret).
764 AddGrant(grant).
765 SetIdentity("sub")
766 token, err := at.ToJWT()
767 require.NoError(t, err)
768 sub := createRTCClientWithToken(token, defaultServerPort, testRTCServicePath, &testclient.Options{
769 AutoSubscribe: true,
770 AutoSubscribeDataTrack: true,
771 })
772
773 waitUntilConnected(t, pub, sub)
774
775 writers := publishTracksForClients(t, pub)
776 defer stopWriters(writers...)
777
778 // publish a data track as well
779 dtw, err := pub.PublishDataTrack()
780 require.NoError(t, err)
781 defer dtw.Stop()
782
783 // wait sub receives tracks
784 testutils.WithTimeout(t, func() string {
785 pubRemote := sub.GetRemoteParticipant(pub.ID())
786 if pubRemote == nil {
787 return "could not find remote publisher"
788 }
789 if len(pubRemote.Tracks) != 2 {
790 return "did not receive metadata for published tracks"
791 }
792 return ""
793 })
794
795 // no subscriptions should have been made while canSubscribe is false
796 require.Empty(t, sub.SubscribedTracks()[pub.ID()])
797 require.Empty(t, sub.SubscribedDataTracks()[pub.ID()])
798
799 // set permissions out of band
800 ctx := contextWithToken(adminRoomToken(testRoom))
801 _, err = roomClient.UpdateParticipant(ctx, &livekit.UpdateParticipantRequest{
802 Room: testRoom,
803 Identity: "sub",
804 Permission: &livekit.ParticipantPermission{
805 CanSubscribe: true,
806 CanPublish: true,

Callers

nothing calls this directly

Calls 15

WithTimeoutFunction · 0.92
setupSingleNodeTestFunction · 0.85
createRTCClientFunction · 0.85
createRTCClientWithTokenFunction · 0.85
waitUntilConnectedFunction · 0.85
publishTracksForClientsFunction · 0.85
stopWritersFunction · 0.85
contextWithTokenFunction · 0.85
adminRoomTokenFunction · 0.85
GetRemoteParticipantMethod · 0.80
EmptyMethod · 0.80
SubscribedTracksMethod · 0.80

Tested by

no test coverage detected