-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_volkswagen.py
626 lines (585 loc) · 39.7 KB
/
test_volkswagen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
"""Asynchronous Python client for Volkswagen."""
from __future__ import annotations
import asyncio
from typing import TYPE_CHECKING, Any, AsyncGenerator
from unittest.mock import patch
import aiohttp
from aiohttp.hdrs import METH_GET, METH_POST
from aioresponses import CallbackResult, aioresponses
import pytest
from yarl import URL
from aiovolkswagen.volkswagen import Volkswagen
from aiovolkswagen.exceptions import (
VolkswagenError,
VolkswagenConnectionError,
VolkswagenAuthenticationError,
VolkswagenAccountLockedError,
VolkswagenEULAError,
)
from aiovolkswagen.const import X_APP_NAME, USER_AGENT
from tests import load_fixture
if TYPE_CHECKING:
from syrupy import SnapshotAssertion
async def test_putting_in_own_session(
responses: aioresponses,
) -> None:
"""Test putting in own session."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
async with aiohttp.ClientSession() as session:
vw = Volkswagen(session=session)
await vw.get_openid_configuration()
assert vw.session is not None
assert not vw.session.closed
await vw.close()
assert not vw.session.closed
async def test_creating_own_session(
responses: aioresponses,
) -> None:
"""Test creating own session."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
vw = Volkswagen()
await vw.get_openid_configuration()
assert vw.session is not None
assert not vw.session.closed
await vw.close()
assert vw.session.closed
async def test_unexpected_server_response(
responses: aioresponses,
volkswagen_client: Volkswagen,
) -> None:
"""Test handling unexpected response."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=400,
headers={"Content-Type": "plain/text"},
body="Yes",
)
with pytest.raises(VolkswagenError):
assert await volkswagen_client.get_openid_configuration()
async def test_timeout(
responses: aioresponses,
) -> None:
"""Test request timeout."""
# Faking a timeout by sleeping
async def response_handler(_: str, **_kwargs: Any) -> CallbackResult:
"""Response handler for this test."""
await asyncio.sleep(2)
return CallbackResult(body="Goodmorning!")
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
callback=response_handler,
)
async with Volkswagen(request_timeout=1) as volkswagen_client:
with pytest.raises(VolkswagenConnectionError):
assert await volkswagen_client.get_openid_configuration()
async def test_openid_configuration(
responses: aioresponses,
volkswagen_client: Volkswagen,
snapshot: SnapshotAssertion,
) -> None:
"""Test retrieving openid configuration."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
assert await volkswagen_client.get_openid_configuration() == snapshot
@pytest.fixture
async def _mock_random_string() -> AsyncGenerator[None, None]:
"""Mock get_random_string."""
with patch("aiovolkswagen.volkswagen.get_random_string", return_value="abcd"):
yield
@pytest.mark.usefixtures("_mock_random_string")
async def test_login(
responses: aioresponses,
volkswagen_client: Volkswagen,
snapshot: SnapshotAssertion,
) -> None:
"""Test the login flow."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=301,
headers={
"Location": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate"
},
)
responses.get(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=200,
body=load_fixture("login_page.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
status=200,
body=load_fixture("password_form.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=301,
headers={
"Location": "https://identity.vwgroup.io/oidc/v1/oauth/sso?clientId=30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com&relayState=4b91fadb9ccbde9ae3593dbef397a310fbdc3afb&userId=cbf6462d-4f36-4880-9236-e40c91fcbaba&HMAC=273474c9a27dc73ec7a5389f83102ccae5f40918dd26191204741708b2ddb4cf"
},
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/oauth/sso?clientId=30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com&relayState=4b91fadb9ccbde9ae3593dbef397a310fbdc3afb&userId=cbf6462d-4f36-4880-9236-e40c91fcbaba&HMAC=273474c9a27dc73ec7a5389f83102ccae5f40918dd26191204741708b2ddb4cf",
status=301,
headers={
"Location": "cupraconnect://identity-kit/login#state=bjPCDALBYCXvLf8th9QrsyA5dhfe3o6g4audGhZYQ9k&code=eyJraWQiOiI0ODEyODgzZi05Y2FiLTQwMWMtYTI5OC0wZmEyMTA5Y2ViY2EiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJjYmY2NDYyZC00ZjM2LTQ4ODAtOTIzNi1lNDBjOTFmY2JhYmEiLCJhdWQiOiIzMGUzMzczNi1jNTM3LTRjNzItYWI2MC03NGE3YjkyY2ZlODNAYXBwc192dy1kaWxhYl9jb20iLCJhY3IiOiJodHRwczovL2lkZW50aXR5LnZ3Z3JvdXAuaW8vYXNzdXJhbmNlL2xvYS0yIiwic2NwIjoib3BlbmlkIHByb2Zpb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sInVwZGF0ZWRfYXQiOjE3MjAxNjMwMjkwMTMsImFhdCI6ImlkZW50aXR5a2l0IiwiZXhwIjoxNzIzMjEzMzY4LCJpYXQiOjE3MjMyMDk3NjgsImp0aSI6IjE5ZTA4MTEyLWE0NzktNGVmYi1hMGQzLWRmMWE1YWU1NjMwNyIsImVtYWlsIjoibS50aWpzc2VuQG1lLmNvbSJ9.n9jDJhQYtaeIp5TDPzLfpwuK6kk-f2H8tgVO-g-tgXbrtkNvyjQUJe-tEE02UEkhvFLNY8qCHskq0_MpErqStrtQFEXglr6OuWS0qihTJwMW42oaqoDx4ElyPFf9sgfZ7iF7GSEKJviByY2SmfdYWZ7YqVkzqzTv0wIxV3nkHsChUzTccLvsiVTndcSvZhK1kSKAiLIKrpHoaMoeunLP3Qs8gEHuWoW4lEdkkvhIH46-Ib5WD-391tYehpDFIGqZlBtR_waugX2hV-Jy_t_O_Q2NXaNKo2u8tHg93fIsjNGMjVXt4johQWcVeeAsrXYVIgvyo0A4hiKInPHD2z5tUJh6wsb8B8495GTb7SwKyElKJp_U1oBUKo3jbhznux-WvYY6LqKVJrlJ_FGygLIWbjf7WC_gQdEnyVm75hGGF7gXQeuwZjEy4SRSHYE8Ah8S50WAVpzWGahzs1TXN-TGaPaUmxEB8tbLleBNv-Vne4I60QFt7R6-KRWFkNSXL7nr9HN0Autht3iNY7mP8NANTiwhaqFrFmSOD3-K3Lr2OLgXxziafO2rMoC4_3MqWGypIEBpeAJ9UQG6gpj3YGdISh2FvF1cMGkC77W_S5BLs8cA5Eau9zAGFwAEEj9iQ4osYcwYIe-jwVB6GEPy7EJd7j_2P0NgT6001lZRJdgWxAQ"
},
)
responses.post(
"https://tokenrefreshservice.apps.emea.vwapps.io/exchangeAuthCode",
status=200,
body=load_fixture("tokens.json"),
)
assert snapshot == await volkswagen_client.login("test", "test")
responses.assert_called_with(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
METH_GET,
headers={
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": USER_AGENT,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"x-requested-with": X_APP_NAME,
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
},
allow_redirects=False,
)
responses.assert_called_with(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
METH_GET,
headers={
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": USER_AGENT,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"x-requested-with": X_APP_NAME,
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
},
allow_redirects=False,
)
responses.assert_called_with(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
METH_POST,
headers={
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": USER_AGENT,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"x-requested-with": X_APP_NAME,
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Referer": "https://identity.vwgroup.io/oidc/v1/authorize",
"Origin": "https://identity.vwgroup.io",
},
data={
"_csrf": "IBbkJahuAMzoAilHhdHEU6uuyyo9VbMw1IyxFb2NlSGyX6OVRHeBHJtcZfrFMxlw4_zwZJ_K5ksEZYodtb2HItvvphGLapKt",
"relayState": "85b9b612b1b1012291478066ec8acb3987a6d9a1",
"hmac": "0b85d60ce123cbc18d5a3d0bd62d1ce0fdb4d795b6814c958f719992642e8d8c",
"email": "test",
},
)
responses.assert_called_with(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
METH_POST,
headers={
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": USER_AGENT,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"x-requested-with": X_APP_NAME,
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Referer": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
"Origin": "https://identity.vwgroup.io",
},
data={
"_csrf": "IBbkJahuAMzoAilHhdHEU6uuyyo9VbMw1IyxFb2NlSGyX6OVRHeBHJtcZfrFMxlw4_zwZJ_K5ksEZYodtb2HItvvphGLapKt",
"relayState": "85b9b612b1b1012291478066ec8acb3987a6d9a1",
"hmac": "21b7c194e63694b8571fafcad8f5edd162e33697b58cb4fb003ef8d987b2d2b9",
"email": "test",
"password": "test",
},
allow_redirects=False,
)
responses.assert_called_with(
"https://identity.vwgroup.io/oidc/v1/oauth/sso?clientId=30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com&relayState=4b91fadb9ccbde9ae3593dbef397a310fbdc3afb&userId=cbf6462d-4f36-4880-9236-e40c91fcbaba&HMAC=273474c9a27dc73ec7a5389f83102ccae5f40918dd26191204741708b2ddb4cf",
METH_GET,
headers={
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": USER_AGENT,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"x-requested-with": X_APP_NAME,
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Referer": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
"Origin": "https://identity.vwgroup.io",
},
allow_redirects=False,
)
responses.assert_called_with(
"https://tokenrefreshservice.apps.emea.vwapps.io/exchangeAuthCode",
METH_POST,
headers={
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": USER_AGENT,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"x-requested-with": X_APP_NAME,
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
},
data={
"auth_code": "eyJraWQiOiI0ODEyODgzZi05Y2FiLTQwMWMtYTI5OC0wZmEyMTA5Y2ViY2EiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJjYmY2NDYyZC00ZjM2LTQ4ODAtOTIzNi1lNDBjOTFmY2JhYmEiLCJhdWQiOiIzMGUzMzczNi1jNTM3LTRjNzItYWI2MC03NGE3YjkyY2ZlODNAYXBwc192dy1kaWxhYl9jb20iLCJhY3IiOiJodHRwczovL2lkZW50aXR5LnZ3Z3JvdXAuaW8vYXNzdXJhbmNlL2xvYS0yIiwic2NwIjoib3BlbmlkIHByb2ZpbGUgYWRkcmVzcyBwaG9uZSBlbWFpbCBiaXJ0aGRhdGUgbmF0aW9uYWxJZGVudGlmaWVyIGNhcnMgbWJiIGRlYWxlcnMgYmFkZ2UgbmF0aW9uYWxpdHkiLCJhYXQiOiJpZGVudGl0eWtpdCIsImlzcyI6Imh0dHBzOi8vaWRlbnRpdHkudndncm91cC5pbyIsImp0dCI6ImF1dGhvcml6YXRpb25fY29kZSIsImV4cCI6MTcyMzIxMDA2OCwiaWF0IjoxNzIzMjA5NzY4LCJub25jZSI6ImhHWDMzL2lwd3pNdmhuNnRqOHJvNmNVN253RklqNzZKQTZqQUkvSEJsTjgiLCJqdGkiOiI0OTJjNTYyZS1lMjc0LTRhMjAtOGZmNC0xM2JiMzBmNDFhNWUifQ.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ah8S50WAVpzWGahzs1TXN-TGaPaUmxEB8tbLleBNv-Vne4I60QFt7R6-KRWFkNSXL7nr9HN0Autht3iNY7mP8NANTiwhaqFrFmSOD3-K3Lr2OLgXxziafO2rMoC4_3MqWGypIEBpeAJ9UQG6gpj3YGdISh2FvF1cMGkC77W_S5BLs8cA5Eau9zAGFwAEEj9iQ4osYcwYIe-jwVB6GEPy7EJd7j_2P0NgT6001lZRJdgWxAQ",
"brand": "cupra",
},
)
@pytest.mark.usefixtures("_mock_random_string")
async def test_authorization_no_location(
responses: aioresponses,
volkswagen_client: Volkswagen,
) -> None:
"""Test login with missing location header."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=400,
)
with pytest.raises(
VolkswagenAuthenticationError, match="Missing `location` header"
):
await volkswagen_client.login("test", "test")
@pytest.mark.usefixtures("_mock_random_string")
@pytest.mark.parametrize(
("query"),
[({"error": "invalid_request"}), ({"error_description": "invalid_request"})],
)
async def test_authorization_error(
responses: aioresponses,
volkswagen_client: Volkswagen,
query: dict[str, Any],
) -> None:
"""Test login with authorization error."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
url = URL("https://identity.vwgroup.io/oidc/v1/authorize").with_query(query)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=301,
headers={"Location": str(url)},
)
with pytest.raises(VolkswagenAuthenticationError, match="invalid_request"):
await volkswagen_client.login("test", "test")
@pytest.mark.usefixtures("_mock_random_string")
@pytest.mark.parametrize(
("query", "exception", "message"),
[
(
{"error": "login.error.throttled", "enableNextButtonAfterSeconds": 50},
VolkswagenAccountLockedError,
"Account locked for 50 seconds",
),
(
{"error": "login.errors.password_invalid"},
VolkswagenAuthenticationError,
"Invalid password",
),
({"error": "something.else"}, VolkswagenAuthenticationError, "something.else"),
(
{"terms-and-conditions": "true"},
VolkswagenEULAError,
"Accept terms and conditions",
),
],
)
async def test_redirect_validation(
responses: aioresponses,
volkswagen_client: Volkswagen,
query: dict[str, Any],
exception: type[Exception],
message: str,
) -> None:
"""Test we raise the right exceptions."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=301,
headers={
"Location": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate"
},
)
responses.get(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=200,
body=load_fixture("login_page.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
status=200,
body=load_fixture("password_form.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=301,
headers={
"Location": "https://identity.vwgroup.io/oidc/v1/oauth/sso?clientId=30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com&relayState=4b91fadb9ccbde9ae3593dbef397a310fbdc3afb&userId=cbf6462d-4f36-4880-9236-e40c91fcbaba&HMAC=273474c9a27dc73ec7a5389f83102ccae5f40918dd26191204741708b2ddb4cf"
},
)
url = URL(
"https://identity.vwgroup.io/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate"
).with_query(query)
responses.get(
"https://identity.vwgroup.io/oidc/v1/oauth/sso?clientId=30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com&relayState=4b91fadb9ccbde9ae3593dbef397a310fbdc3afb&userId=cbf6462d-4f36-4880-9236-e40c91fcbaba&HMAC=273474c9a27dc73ec7a5389f83102ccae5f40918dd26191204741708b2ddb4cf",
status=301,
headers={"Location": str(url)},
)
with pytest.raises(exception, match=message):
await volkswagen_client.login("test", "test")
@pytest.mark.usefixtures("_mock_random_string")
async def test_no_redirect(
responses: aioresponses,
volkswagen_client: Volkswagen,
) -> None:
"""Test we handle no redirect."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=301,
headers={
"Location": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate"
},
)
responses.get(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=200,
body=load_fixture("login_page.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
status=200,
body=load_fixture("password_form.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=301,
headers={
"Location": "https://identity.vwgroup.io/oidc/v1/oauth/sso?clientId=30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com&relayState=4b91fadb9ccbde9ae3593dbef397a310fbdc3afb&userId=cbf6462d-4f36-4880-9236-e40c91fcbaba&HMAC=273474c9a27dc73ec7a5389f83102ccae5f40918dd26191204741708b2ddb4cf"
},
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/oauth/sso?clientId=30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com&relayState=4b91fadb9ccbde9ae3593dbef397a310fbdc3afb&userId=cbf6462d-4f36-4880-9236-e40c91fcbaba&HMAC=273474c9a27dc73ec7a5389f83102ccae5f40918dd26191204741708b2ddb4cf",
status=400,
)
with pytest.raises(
VolkswagenAuthenticationError, match="Missing `location` header"
):
await volkswagen_client.login("test", "test")
@pytest.mark.usefixtures("_mock_random_string")
async def test_max_loop(
responses: aioresponses,
volkswagen_client: Volkswagen,
) -> None:
"""Test we handle max loop."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=301,
headers={
"Location": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate"
},
)
responses.get(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=200,
body=load_fixture("login_page.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
status=200,
body=load_fixture("password_form.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=301,
headers={"Location": "https://identity.vwgroup.io/oidc/v1/"},
)
for i in range(0, 11):
responses.get(
f"https://identity.vwgroup.io/oidc/v{i}/",
status=301,
headers={"Location": f"https://identity.vwgroup.io/oidc/v{i + 1}/"},
)
with pytest.raises(
VolkswagenAuthenticationError, match="Max redirect depth reached"
):
await volkswagen_client.login("test", "test")
@pytest.mark.usefixtures("_mock_random_string")
async def test_exchange_auth_code_failure(
responses: aioresponses,
volkswagen_client: Volkswagen,
) -> None:
"""Test exchange auth code failure."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=301,
headers={
"Location": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate"
},
)
responses.get(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=200,
body=load_fixture("login_page.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
status=200,
body=load_fixture("password_form.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=301,
headers={
"Location": "https://identity.vwgroup.io/oidc/v1/oauth/sso?clientId=30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com&relayState=4b91fadb9ccbde9ae3593dbef397a310fbdc3afb&userId=cbf6462d-4f36-4880-9236-e40c91fcbaba&HMAC=273474c9a27dc73ec7a5389f83102ccae5f40918dd26191204741708b2ddb4cf"
},
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/oauth/sso?clientId=30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com&relayState=4b91fadb9ccbde9ae3593dbef397a310fbdc3afb&userId=cbf6462d-4f36-4880-9236-e40c91fcbaba&HMAC=273474c9a27dc73ec7a5389f83102ccae5f40918dd26191204741708b2ddb4cf",
status=301,
headers={
"Location": "cupraconnect://identity-kit/login#state=bjPCDALBYCXvLf8th9QrsyA5dhfe3o6g4audGhZYQ9k&code=eyJraWQiOiI0ODEyODgzZi05Y2FiLTQwMWMtYTI5OC0wZmEyMTA5Y2ViY2EiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJjYmY2NDYyZC00ZjM2LTQ4ODAtOTIzNi1lNDBjOTFmY2JhYmEiLCJhdWQiOiIzMGUzMzczNi1jNTM3LTRjNzItYWI2MC03NGE3YjkyY2ZlODNAYXBwc192dy1kaWxhYl9jb20iLCJhY3IiOiJodHRwczovL2lkZW50aXR5LnZ3Z3JvdXAuaW8vYXNzdXJhbmNlL2xvYS0yIiwic2NwIjoib3BlbmlkIHByb2ZpbGUgYWRkcmVzcyBwaG9uZSBlbWFpbCBiaXJ0aGRhdGUgbmF0aW9uYWxJZGVudGlmaWVyIGNhcnMgbWJiIGRlYWxlcnMgYmFkZ2UgbmF0aW9uYWxpdHkiLCJhYXQiOiJpZGVudGl0eWtpdCIsImlzcyI6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WE1YWU1NjMwNyIsImVtYWlsIjoibS50aWpzc2VuQG1lLmNvbSJ9.n9jDJhQYtaeIp5TDPzLfpwuK6kk-f2H8tgVO-g-tgXbrtkNvyjQUJe-tEE02UEkhvFLNY8qCHskq0_MpErqStrtQFEXglr6OuWS0qihTJwMW42oaqoDx4ElyPFf9sgfZ7iF7GSEKJviByY2SmfdYWZ7YqVkzqzTv0wIxV3nkHsChUzTccLvsiVTndcSvZhK1kSKAiLIKrpHoaMoeunLP3Qs8gEHuWoW4lEdkkvhIH46-Ib5WD-391tYehpDFIGqZlBtR_waugX2hV-Jy_t_O_Q2NXaNKo2u8tHg93fIsjNGMjVXt4johQWcVeeAsrXYVIgvyo0A4hiKInPHD2z5tUJh6wsb8B8495GTb7SwKyElKJp_U1oBUKo3jbhznux-WvYY6LqKVJrlJ_FGygLIWbjf7WC_gQdEnyVm75hGGF7gXQeuwZjEy4SRSHYE8Ah8S50WAVpzWGahzs1TXN-TGaPaUmxEB8tbLleBNv-Vne4I60QFt7R6-KRWFkNSXL7nr9HN0Autht3iNY7mP8NANTiwhaqFrFmSOD3-K3Lr2OLgXxziafO2rMoC4_3MqWGypIEBpeAJ9UQG6gpj3YGdISh2FvF1cMGkC77W_S5BLs8cA5Eau9zAGFwAEEj9iQ4osYcwYIe-jwVB6GEPy7EJd7j_2P0NgT6001lZRJdgWxAQ"
},
)
responses.post(
"https://tokenrefreshservice.apps.emea.vwapps.io/exchangeAuthCode",
status=400,
)
with pytest.raises(VolkswagenAuthenticationError, match="Invalid request"):
await volkswagen_client.login("test", "test")
@pytest.mark.usefixtures("_mock_random_string")
async def test_no_action_found_in_username_form(
responses: aioresponses,
volkswagen_client: Volkswagen,
) -> None:
"""Test no action found in username form."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=301,
headers={
"Location": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate"
},
)
responses.get(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=200,
body=load_fixture("login_page_without_action.html"),
)
with pytest.raises(VolkswagenAuthenticationError, match="No action found in form"):
await volkswagen_client.login("test", "test")
@pytest.mark.usefixtures("_mock_random_string")
async def test_username_form_incorrect_response(
responses: aioresponses,
volkswagen_client: Volkswagen,
) -> None:
"""Test username form incorrect response."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=301,
headers={
"Location": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate"
},
)
responses.get(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=200,
body=load_fixture("login_page.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
status=400,
)
with pytest.raises(VolkswagenAuthenticationError, match="Invalid request"):
await volkswagen_client.login("test", "test")
@pytest.mark.usefixtures("_mock_random_string")
async def test_password_invalid(
responses: aioresponses,
volkswagen_client: Volkswagen,
snapshot: SnapshotAssertion,
) -> None:
"""Test password invalid."""
responses.get(
"https://identity.vwgroup.io/.well-known/openid-configuration",
status=200,
body=load_fixture("openid-configuration.json"),
)
responses.get(
"https://identity.vwgroup.io/oidc/v1/authorize?client_id=30e33736-c537-4c72-ab60-74a7b92cfe83%2540apps_vw-dilab_com&nonce=abcd&redirect_uri=cupraconnect%253A%252F%252Fidentity-kit%252Flogin&response_type=code+id_token+token&scope=openid+profile+address+phone+email+birthdate+nationalIdentifier+cars+mbb+dealers+badge+nationality&state=abcd",
status=301,
headers={
"Location": "https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate"
},
)
responses.get(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=200,
body=load_fixture("login_page.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/identifier",
status=200,
body=load_fixture("password_form.html"),
)
responses.post(
"https://identity.vwgroup.io/signin-service/v1/30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com/login/authenticate",
status=400,
)
with pytest.raises(
VolkswagenAuthenticationError, match="Missing `location` header"
):
assert snapshot == await volkswagen_client.login("test", "test")