ensure that token accurately reflects out of band updates
(t *testing.T)
| 251 | |
| 252 | // ensure that token accurately reflects out of band updates |
| 253 | func TestMultiNodeUpdateAttributes(t *testing.T) { |
| 254 | if testing.Short() { |
| 255 | t.SkipNow() |
| 256 | return |
| 257 | } |
| 258 | |
| 259 | _, _, finish := setupMultiNodeTest("TestMultiNodeUpdateAttributes") |
| 260 | defer finish() |
| 261 | |
| 262 | for _, testRTCServicePath := range testRTCServicePaths { |
| 263 | t.Run(fmt.Sprintf("testRTCServicePath=%s", testRTCServicePath.String()), func(t *testing.T) { |
| 264 | c1 := createRTCClient("au1", defaultServerPort, testRTCServicePath, &client.Options{ |
| 265 | TokenCustomizer: func(token *auth.AccessToken, grants *auth.VideoGrant) { |
| 266 | token.SetAttributes(map[string]string{ |
| 267 | "mykey": "au1", |
| 268 | }) |
| 269 | }, |
| 270 | }) |
| 271 | c2 := createRTCClient("au2", secondServerPort, testRTCServicePath, &client.Options{ |
| 272 | TokenCustomizer: func(token *auth.AccessToken, grants *auth.VideoGrant) { |
| 273 | token.SetAttributes(map[string]string{ |
| 274 | "mykey": "au2", |
| 275 | }) |
| 276 | grants.SetCanUpdateOwnMetadata(true) |
| 277 | }, |
| 278 | }) |
| 279 | waitUntilConnected(t, c1, c2) |
| 280 | |
| 281 | testutils.WithTimeout(t, func() string { |
| 282 | rc2 := c1.GetRemoteParticipant(c2.ID()) |
| 283 | rc1 := c2.GetRemoteParticipant(c1.ID()) |
| 284 | if rc2 == nil || rc1 == nil { |
| 285 | return "participants could not see each other" |
| 286 | } |
| 287 | if rc1.Attributes == nil || rc1.Attributes["mykey"] != "au1" { |
| 288 | return "rc1's initial attributes are incorrect" |
| 289 | } |
| 290 | if rc2.Attributes == nil || rc2.Attributes["mykey"] != "au2" { |
| 291 | return "rc2's initial attributes are incorrect" |
| 292 | } |
| 293 | return "" |
| 294 | }) |
| 295 | |
| 296 | // this one should not go through |
| 297 | _ = c1.SetAttributes(map[string]string{"mykey": "shouldnotchange"}) |
| 298 | _ = c2.SetAttributes(map[string]string{"secondkey": "au2"}) |
| 299 | |
| 300 | // updates using room API should succeed |
| 301 | _, err := roomClient.UpdateParticipant(contextWithToken(adminRoomToken(testRoom)), &livekit.UpdateParticipantRequest{ |
| 302 | Room: testRoom, |
| 303 | Identity: "au1", |
| 304 | Attributes: map[string]string{ |
| 305 | "secondkey": "au1", |
| 306 | }, |
| 307 | }) |
| 308 | require.NoError(t, err) |
| 309 | |
| 310 | testutils.WithTimeout(t, func() string { |
nothing calls this directly
no test coverage detected