|
1 | | -from datetime import datetime, timedelta, timezone |
2 | 1 | import uuid |
3 | 2 |
|
4 | | -from httpx import Response |
| 3 | +from httpx import AsyncClient, Response |
5 | 4 | import pytest |
6 | 5 |
|
7 | 6 | from tests.common import get_response_json |
8 | 7 |
|
9 | 8 |
|
| 9 | +@pytest.mark.asyncio |
| 10 | +async def test_get_title_endpoints(respx_mock, xal_mgr): |
| 11 | + route = respx_mock.get("https://title.mgt.xboxlive.com").mock( |
| 12 | + return_value=Response(200, json=get_response_json("auth_title_endpoints")) |
| 13 | + ) |
| 14 | + async with AsyncClient() as client: |
| 15 | + await xal_mgr.get_title_endpoints(client) |
| 16 | + assert route.called |
| 17 | + |
| 18 | + |
10 | 19 | @pytest.mark.asyncio |
11 | 20 | async def test_get_device_token(respx_mock, xal_mgr): |
12 | 21 | route = respx_mock.post( |
13 | 22 | "https://device.auth.xboxlive.com/device/authenticate" |
14 | 23 | ).mock(return_value=Response(200, json=get_response_json("auth_device_token"))) |
15 | | - resp = await xal_mgr.request_device_token( |
16 | | - uuid.UUID("9c493431-5462-4a4a-a247-f6420396318d") |
| 24 | + await xal_mgr.request_device_token() |
| 25 | + assert route.called |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.asyncio |
| 29 | +async def test_sisu_authentication(respx_mock, xal_mgr): |
| 30 | + route = respx_mock.post("https://sisu.xboxlive.com/authenticate").mock( |
| 31 | + return_value=Response( |
| 32 | + 200, |
| 33 | + json=get_response_json("xal_authentication_resp"), |
| 34 | + headers={"X-SessionId": "abcsession-id"}, |
| 35 | + ) |
| 36 | + ) |
| 37 | + resp, session_id = await xal_mgr.request_sisu_authentication( |
| 38 | + "eyDeviceToken", "code_challenge_string", "state_string" |
| 39 | + ) |
| 40 | + assert route.called |
| 41 | + assert session_id == "abcsession-id" |
| 42 | + assert resp.msa_oauth_redirect is not None |
| 43 | + |
| 44 | + |
| 45 | +@pytest.mark.asyncio |
| 46 | +async def test_sisu_authorization(respx_mock, xal_mgr): |
| 47 | + route = respx_mock.post("https://sisu.xboxlive.com/authorize").mock( |
| 48 | + return_value=Response(200, json=get_response_json("xal_authorization_resp")) |
| 49 | + ) |
| 50 | + await xal_mgr.do_sisu_authorization( |
| 51 | + "SISU-Session-ID", "eyAccessToken", "eyDeviceToken" |
17 | 52 | ) |
18 | 53 | assert route.called |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.asyncio |
| 57 | +async def test_exchange_code_for_token(respx_mock, xal_mgr): |
| 58 | + route = respx_mock.post("https://login.live.com").mock( |
| 59 | + return_value=Response(200, json=get_response_json("auth_oauth2_token")) |
| 60 | + ) |
| 61 | + await xal_mgr.exchange_code_for_token("abc", "xyz") |
| 62 | + |
| 63 | + assert route.called |
0 commit comments