@@ -372,6 +372,32 @@ func TestTaskRouterGrant(t *testing.T) {
372372 assert .Equal (t , "worker" , taskRouterGrantDecoded ["role" ])
373373}
374374
375+ func TestPlaybackGrant (t * testing.T ) {
376+ accessToken := CreateAccessToken (Params )
377+ accessToken .AddGrant (& PlaybackGrant {
378+ "requestCredentials" : nil ,
379+ "playbackUrl" : "https://000.us-east-1.playback.live-video.net/api/video/v1/us-east-000.channel.000?token=xxxxx" ,
380+ "playerStreamerSid" : "VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
381+ })
382+
383+ token , err := accessToken .ToJwt ()
384+ assert .Nil (t , err )
385+ assert .NotNil (t , token )
386+
387+ decodedToken , err := accessToken .FromJwt (token , "secret" )
388+ assert .Nil (t , err )
389+ assert .NotNil (t , decodedToken )
390+ assert .Len (t , decodedToken .Grants , 1 )
391+ payload := decodedToken .Payload ()
392+ assert .Len (t , payload ["grants" ], 1 )
393+
394+ playbackGrantDecoded := payload ["grants" ].(map [string ]interface {})["player" ].(map [string ]interface {})
395+ assert .NotNil (t , playbackGrantDecoded )
396+ assert .Equal (t , nil , playbackGrantDecoded ["requestCredentials" ])
397+ assert .Equal (t , "https://000.us-east-1.playback.live-video.net/api/video/v1/us-east-000.channel.000?token=xxxxx" , playbackGrantDecoded ["playbackUrl" ])
398+ assert .Equal (t , "VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" , playbackGrantDecoded ["playerStreamerSid" ])
399+ }
400+
375401func TestMultipleGrants (t * testing.T ) {
376402 accessToken := CreateAccessToken (Params )
377403 accessToken .AddGrant (& TaskRouterGrant {
@@ -452,4 +478,7 @@ func TestGrantsToString(t *testing.T) {
452478
453479 videoGrant := & VideoGrant {}
454480 assert .True (t , strings .HasPrefix (videoGrant .ToString (), "<VideoGrant" ))
481+
482+ playbackGrant := & PlaybackGrant {}
483+ assert .True (t , strings .HasPrefix (playbackGrant .ToString (), "<PlaybackGrant" ))
455484}
0 commit comments