|
3 | 3 | import pytest |
4 | 4 | from plexapi.exceptions import BadRequest, NotFound, Unauthorized |
5 | 5 | from plexapi.myplex import MyPlexAccount, MyPlexInvite, MyPlexJWTLogin |
| 6 | +from plexapi.utils import createMyPlexDevice |
6 | 7 |
|
7 | 8 | from . import conftest as utils |
8 | 9 | from .payloads import MYPLEX_INVITE |
@@ -369,31 +370,40 @@ def test_myplex_ping(account): |
369 | 370 |
|
370 | 371 |
|
371 | 372 | def test_myplex_jwt_login(account, tmp_path, monkeypatch): |
| 373 | + # Create a new MyPlexDevice for JWT tests |
| 374 | + device = createMyPlexDevice(account=account) |
| 375 | + |
| 376 | + privkey = tmp_path / 'private.key' |
| 377 | + pubkey = tmp_path / 'public.key' |
| 378 | + |
372 | 379 | jwtlogin = MyPlexJWTLogin( |
373 | | - token=account.authToken, |
| 380 | + headers={'X-Plex-Client-Identifier': device.clientIdentifier}, |
| 381 | + token=device.token, |
374 | 382 | scopes=['username', 'email', 'friendly_name'] |
375 | 383 | ) |
376 | | - jwtlogin.generateKeypair(keyfiles=(tmp_path / 'private.key', tmp_path / 'public.key'), overwrite=True) |
| 384 | + jwtlogin.generateKeypair(keyfiles=(privkey, pubkey), overwrite=True) |
377 | 385 | with pytest.raises(FileExistsError): |
378 | | - jwtlogin.generateKeypair(keyfiles=(tmp_path / 'private.key', tmp_path / 'public.key')) |
| 386 | + jwtlogin.generateKeypair(keyfiles=(privkey, pubkey)) |
379 | 387 | jwtlogin.registerDevice() |
380 | 388 | jwtToken = jwtlogin.refreshJWT() |
381 | 389 | assert jwtlogin.decodedJWT['user']['username'] == account.username |
382 | | - assert MyPlexAccount(token=jwtToken) == account |
| 390 | + new_account = MyPlexAccount(token=jwtToken) |
| 391 | + assert new_account.username == account.username |
383 | 392 |
|
384 | 393 | jwtlogin = MyPlexJWTLogin( |
| 394 | + headers={'X-Plex-Client-Identifier': device.clientIdentifier}, |
385 | 395 | jwtToken=jwtToken, |
386 | | - keypair=(tmp_path / 'private.key', tmp_path / 'public.key'), |
| 396 | + keypair=(privkey, pubkey), |
387 | 397 | scopes=['username', 'email', 'friendly_name'] |
388 | 398 | ) |
389 | 399 | assert jwtlogin.verifyJWT() |
390 | 400 | newjwtToken = jwtlogin.refreshJWT() |
391 | 401 | assert newjwtToken != jwtToken |
392 | | - assert MyPlexAccount(token=newjwtToken) == account |
| 402 | + new_account = MyPlexAccount(token=newjwtToken) |
| 403 | + assert new_account.username == account.username |
393 | 404 |
|
394 | 405 | plexPublicJWKs = jwtlogin._getPlexPublicJWK() |
395 | | - invalidJWK = plexPublicJWKs[0].copy() |
396 | | - invalidJWK['x'] += 'invalid' |
| 406 | + invalidJWK = jwtlogin._publicJWK._jwk_data.copy() |
397 | 407 | monkeypatch.setattr(MyPlexJWTLogin, "_getPlexPublicJWK", lambda self: plexPublicJWKs + [invalidJWK]) |
398 | 408 | assert jwtlogin.decodePlexJWT() |
399 | 409 |
|
|
0 commit comments