File: test_passport.py

package info (click to toggle)
python-telegram-bot 22.3-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 11,060 kB
  • sloc: python: 90,298; makefile: 176; sh: 4
file content (543 lines) | stat: -rw-r--r-- 27,162 bytes parent folder | download
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
#!/usr/bin/env python
# flake8: noqa: E501
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2025
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program.  If not, see [http://www.gnu.org/licenses/].
from copy import deepcopy

import pytest

from telegram import (
    Bot,
    Credentials,
    File,
    PassportData,
    PassportElementErrorDataField,
    PassportElementErrorSelfie,
    PassportFile,
)
from telegram.error import PassportDecryptionError

# Note: All classes in telegram.credentials (except EncryptedCredentials) aren't directly tested
# here, although they are implicitly tested. Testing for those classes was too much work and not
# worth it.
from telegram.request import RequestData
from tests.auxil.pytest_classes import make_bot
from tests.auxil.slots import mro_slots

RAW_PASSPORT_DATA = {
    "credentials": {
        "hash": "qB4hz2LMcXYhglwz6EvXMMyI3PURisWLXl/iCmCXcSk=",
        "secret": "O6x3X2JrLO1lUIhw48os1gaenDuZLhesoZMKXehZwtM3vsxOdtxHKWQyLNwtbyy4snYpARXDwf8f1QHNmQ/M1PwBQvk1ozrZBXb4a6k/iYj+P4v8Xw2M++CRHqZv0LaxFtyHOXnNYZ6dXpNeF0ZvYYTmm0FsYvK+/3/F6VDB3Oe6xWlXFLwaCCP/jA9i2+dKp6iq8NLOo4VnxenPKWWYz20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VZ9Jly/YUriHZURS6oDGycH3+DKUn5gRAxgOyjAwxGRqJh/YKfPt14d4iur0H3VUuLwFCbwj5hSvHVIv5cNapitgINU+0qzIlhyeE0HfRKstO7nOQ9A+nclqbOikYgurYIe0z70WZyJ3qSiHbOMMqQqcoKOJ6M9v2hDdJo9MDQ13dF6bl4+BfX4mcF0m7nVUBkzCRiSOQWWFUMgLX7CxSdmotT+eawKLjrCpSPmq9sicWyrFtVlq/NYLDGhT0jUUau6Mb5ksT+/OBVeMzqoezUcly29L1/gaeWAc8zOApVEjAMT48U63NXK5o8GrANeqqAt3TB36S5yeIjMf194nXAAzsJZ+s/tXprLn2M5mA1Iag4RbVPTarEsMp10JYag==",
    },
    "data": [
        {
            "data": "QRfzWcCN4WncvRO3lASG+d+c5gzqXtoCinQ1PgtYiZMKXCksx9eB9Ic1bOt8C/un9/XaX220PjJSO7Kuba+nXXC51qTsjqP9rnLKygnEIWjKrfiDdklzgcukpRzFSjiOAvhy86xFJZ1PfPSrFATy/Gp1RydLzbrBd2ZWxZqXrxcMoA0Q2UTTFXDoCYerEAiZoD69i79tB/6nkLBcUUvN5d52gKd/GowvxWqAAmdO6l1N7jlo6aWjdYQNBAK1KHbJdbRZMJLxC1MqMuZXAYrPoYBRKr5xAnxDTmPn/LEZKLc3gwwZyEgR5x7e9jp5heM6IEMmsv3O/6SUeEQs7P0iVuRSPLMJLfDdwns8Tl3fF2M4IxKVovjCaOVW+yHKsADDAYQPzzH2RcrWVD0TP5I64mzpK64BbTOq3qm3Hn51SV9uA/+LvdGbCp7VnzHx4EdUizHsVyilJULOBwvklsrDRvXMiWmh34ZSR6zilh051tMEcRf0I+Oe7pIxVJd/KKfYA2Z/eWVQTCn5gMuAInQNXFSqDIeIqBX+wca6kvOCUOXB7J2uRjTpLaC4DM9s/sNjSBvFixcGAngt+9oap6Y45rQc8ZJaNN/ALqEJAmkphW8=",
            "type": "personal_details",
            "hash": "What to put here?",
        },
        {
            "reverse_side": {
                "file_size": 32424112,
                "file_date": 1534074942,
                "file_id": "DgADBAADNQQAAtoagFPf4wwmFZdmyQI",
                "file_unique_id": "adc3145fd2e84d95b64d68eaa22aa33e",
            },
            "translation": [
                {
                    "file_size": 28640,
                    "file_date": 1535630933,
                    "file_id": "DgADBAADswMAAisqQVAmooP-kVgLgAI",
                    "file_unique_id": "52a90d53d6064bb58feb582acdc3a324",
                },
                {
                    "file_size": 28672,
                    "file_date": 1535630933,
                    "file_id": "DgADBAAD1QMAAnrpQFBMZsT3HysjwwI",
                    "file_unique_id": "7285f864d168441ba1f7d02146250432",
                },
            ],
            "front_side": {
                "file_size": 28624,
                "file_date": 1534074942,
                "file_id": "DgADBAADxwMAApnQgVPK2-ckL2eXVAI",
                "file_unique_id": "d9d52a700cbb4a189a80104aa5978133",
            },
            "type": "driver_license",
            "selfie": {
                "file_size": 28592,
                "file_date": 1534074942,
                "file_id": "DgADBAADEQQAAkopgFNr6oi-wISRtAI",
                "file_unique_id": "d4e390cca57b4da5a65322b304762a12",
            },
            "data": "eJUOFuY53QKmGqmBgVWlLBAQCUQJ79n405SX6M5aGFIIodOPQqnLYvMNqTwTrXGDlW+mVLZcbu+y8luLVO8WsJB/0SB7q5WaXn/IMt1G9lz5G/KMLIZG/x9zlnimsaQLg7u8srG6L4KZzv+xkbbHjZdETrxU8j0N/DoS4HvLMRSJAgeFUrY6v2YW9vSRg+fSxIqQy1jR2VKpzAT8OhOz7A==",
            "hash": "We seriously need to improve this mess! took so long to debug!",
        },
        {
            "translation": [
                {
                    "file_size": 28480,
                    "file_date": 1535630939,
                    "file_id": "DgADBAADyQUAAqyqQVC_eoX_KwNjJwI",
                    "file_unique_id": "38b2877b443542cbaf520c6e36a33ac4",
                },
                {
                    "file_size": 28528,
                    "file_date": 1535630939,
                    "file_id": "DgADBAADsQQAAubTQVDRO_FN3lOwWwI",
                    "file_unique_id": "f008ca48c44b4a47895ddbcd2f76741e",
                },
            ],
            "files": [
                {
                    "file_size": 28640,
                    "file_date": 1534074988,
                    "file_id": "DgADBAADLAMAAhwfgVMyfGa5Nr0LvAI",
                    "file_unique_id": "b170748794834644baaa3ec57ee4ce7a",
                },
                {
                    "file_size": 28480,
                    "file_date": 1534074988,
                    "file_id": "DgADBAADaQQAAsFxgVNVfLZuT-_3ZQI",
                    "file_unique_id": "19a12ae34dca424b85e0308f706cee75",
                },
            ],
            "type": "utility_bill",
            "hash": "Wow over 30 minutes spent debugging passport stuff.",
        },
        {
            "data": "j9SksVkSj128DBtZA+3aNjSFNirzv+R97guZaMgae4Gi0oDVNAF7twPR7j9VSmPedfJrEwL3O889Ei+a5F1xyLLyEI/qEBljvL70GFIhYGitS0JmNabHPHSZrjOl8b4s/0Z0Px2GpLO5siusTLQonimdUvu4UPjKquYISmlKEKhtmGATy+h+JDjNCYuOkhakeNw0Rk0BHgj0C3fCb7WZNQSyVb+2GTu6caR6eXf/AFwFp0TV3sRz3h0WIVPW8bna",
            "type": "address",
            "hash": "at least I get the pattern now",
        },
        {"email": "fb3e3i47zt@dispostable.com", "type": "email", "hash": "this should be it."},
    ],
}


@pytest.fixture(scope="module")
def all_passport_data():
    return [
        {
            "type": "personal_details",
            "data": RAW_PASSPORT_DATA["data"][0]["data"],
            "hash": "what to put here?",
        },
        {
            "type": "passport",
            "data": RAW_PASSPORT_DATA["data"][1]["data"],
            "front_side": RAW_PASSPORT_DATA["data"][1]["front_side"],
            "selfie": RAW_PASSPORT_DATA["data"][1]["selfie"],
            "translation": RAW_PASSPORT_DATA["data"][1]["translation"],
            "hash": "more data arghh",
        },
        {
            "type": "internal_passport",
            "data": RAW_PASSPORT_DATA["data"][1]["data"],
            "front_side": RAW_PASSPORT_DATA["data"][1]["front_side"],
            "selfie": RAW_PASSPORT_DATA["data"][1]["selfie"],
            "translation": RAW_PASSPORT_DATA["data"][1]["translation"],
            "hash": "more data arghh",
        },
        {
            "type": "driver_license",
            "data": RAW_PASSPORT_DATA["data"][1]["data"],
            "front_side": RAW_PASSPORT_DATA["data"][1]["front_side"],
            "reverse_side": RAW_PASSPORT_DATA["data"][1]["reverse_side"],
            "selfie": RAW_PASSPORT_DATA["data"][1]["selfie"],
            "translation": RAW_PASSPORT_DATA["data"][1]["translation"],
            "hash": "more data arghh",
        },
        {
            "type": "identity_card",
            "data": RAW_PASSPORT_DATA["data"][1]["data"],
            "front_side": RAW_PASSPORT_DATA["data"][1]["front_side"],
            "reverse_side": RAW_PASSPORT_DATA["data"][1]["reverse_side"],
            "selfie": RAW_PASSPORT_DATA["data"][1]["selfie"],
            "translation": RAW_PASSPORT_DATA["data"][1]["translation"],
            "hash": "more data arghh",
        },
        {
            "type": "utility_bill",
            "files": RAW_PASSPORT_DATA["data"][2]["files"],
            "translation": RAW_PASSPORT_DATA["data"][2]["translation"],
            "hash": "more data arghh",
        },
        {
            "type": "bank_statement",
            "files": RAW_PASSPORT_DATA["data"][2]["files"],
            "translation": RAW_PASSPORT_DATA["data"][2]["translation"],
            "hash": "more data arghh",
        },
        {
            "type": "rental_agreement",
            "files": RAW_PASSPORT_DATA["data"][2]["files"],
            "translation": RAW_PASSPORT_DATA["data"][2]["translation"],
            "hash": "more data arghh",
        },
        {
            "type": "passport_registration",
            "files": RAW_PASSPORT_DATA["data"][2]["files"],
            "translation": RAW_PASSPORT_DATA["data"][2]["translation"],
            "hash": "more data arghh",
        },
        {
            "type": "temporary_registration",
            "files": RAW_PASSPORT_DATA["data"][2]["files"],
            "translation": RAW_PASSPORT_DATA["data"][2]["translation"],
            "hash": "more data arghh",
        },
        {
            "type": "address",
            "data": RAW_PASSPORT_DATA["data"][3]["data"],
            "hash": "more data arghh",
        },
        {"type": "email", "email": "fb3e3i47zt@dispostable.com", "hash": "more data arghh"},
        {
            "type": "phone_number",
            "phone_number": "fb3e3i47zt@dispostable.com",
            "hash": "more data arghh",
        },
    ]


@pytest.fixture(scope="module")
def passport_data(bot):
    return PassportData.de_json(RAW_PASSPORT_DATA, bot=bot)


class PassportTestBase:
    driver_license_selfie_file_id = "DgADBAADEQQAAkopgFNr6oi-wISRtAI"
    driver_license_selfie_file_unique_id = "d4e390cca57b4da5a65322b304762a12"
    driver_license_front_side_file_id = "DgADBAADxwMAApnQgVPK2-ckL2eXVAI"
    driver_license_front_side_file_unique_id = "d9d52a700cbb4a189a80104aa5978133"
    driver_license_reverse_side_file_id = "DgADBAADNQQAAtoagFPf4wwmFZdmyQI"
    driver_license_reverse_side_file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e"
    driver_license_translation_1_file_id = "DgADBAADswMAAisqQVAmooP-kVgLgAI"
    driver_license_translation_1_file_unique_id = "52a90d53d6064bb58feb582acdc3a324"
    driver_license_translation_2_file_id = "DgADBAAD1QMAAnrpQFBMZsT3HysjwwI"
    driver_license_translation_2_file_unique_id = "7285f864d168441ba1f7d02146250432"
    utility_bill_1_file_id = "DgADBAADLAMAAhwfgVMyfGa5Nr0LvAI"
    utility_bill_1_file_unique_id = "b170748794834644baaa3ec57ee4ce7a"
    utility_bill_2_file_id = "DgADBAADaQQAAsFxgVNVfLZuT-_3ZQI"
    utility_bill_2_file_unique_id = "19a12ae34dca424b85e0308f706cee75"
    utility_bill_translation_1_file_id = "DgADBAADyQUAAqyqQVC_eoX_KwNjJwI"
    utility_bill_translation_1_file_unique_id = "38b2877b443542cbaf520c6e36a33ac4"
    utility_bill_translation_2_file_id = "DgADBAADsQQAAubTQVDRO_FN3lOwWwI"
    utility_bill_translation_2_file_unique_id = "f008ca48c44b4a47895ddbcd2f76741e"
    driver_license_selfie_credentials_file_hash = "Cila/qLXSBH7DpZFbb5bRZIRxeFW2uv/ulL0u0JNsYI="
    driver_license_selfie_credentials_secret = "tivdId6RNYNsvXYPppdzrbxOBuBOr9wXRPDcCvnXU7E="


class TestPassportWithoutRequest(PassportTestBase):
    def test_slot_behaviour(self, passport_data):
        inst = passport_data
        for attr in inst.__slots__:
            assert getattr(inst, attr, "err") != "err", f"got extra slot '{attr}'"
        assert len(mro_slots(inst)) == len(set(mro_slots(inst))), "duplicate slot"

    def test_creation(self, passport_data):
        assert isinstance(passport_data, PassportData)

    def test_expected_encrypted_values(self, passport_data):
        personal_details, driver_license, utility_bill, address, email = passport_data.data

        assert personal_details.type == "personal_details"
        assert personal_details.data == RAW_PASSPORT_DATA["data"][0]["data"]

        assert driver_license.type == "driver_license"
        assert driver_license.data == RAW_PASSPORT_DATA["data"][1]["data"]
        assert isinstance(driver_license.selfie, PassportFile)
        assert driver_license.selfie.file_id == self.driver_license_selfie_file_id
        assert driver_license.selfie.file_unique_id == self.driver_license_selfie_file_unique_id

        assert isinstance(driver_license.front_side, PassportFile)
        assert driver_license.front_side.file_id == self.driver_license_front_side_file_id
        assert (
            driver_license.front_side.file_unique_id
            == self.driver_license_front_side_file_unique_id
        )

        assert isinstance(driver_license.reverse_side, PassportFile)
        assert driver_license.reverse_side.file_id == self.driver_license_reverse_side_file_id
        assert (
            driver_license.reverse_side.file_unique_id
            == self.driver_license_reverse_side_file_unique_id
        )

        assert isinstance(driver_license.translation[0], PassportFile)
        assert driver_license.translation[0].file_id == self.driver_license_translation_1_file_id
        assert (
            driver_license.translation[0].file_unique_id
            == self.driver_license_translation_1_file_unique_id
        )

        assert isinstance(driver_license.translation[1], PassportFile)
        assert driver_license.translation[1].file_id == self.driver_license_translation_2_file_id
        assert (
            driver_license.translation[1].file_unique_id
            == self.driver_license_translation_2_file_unique_id
        )

        assert utility_bill.type == "utility_bill"
        assert isinstance(utility_bill.files[0], PassportFile)
        assert utility_bill.files[0].file_id == self.utility_bill_1_file_id
        assert utility_bill.files[0].file_unique_id == self.utility_bill_1_file_unique_id

        assert isinstance(utility_bill.files[1], PassportFile)
        assert utility_bill.files[1].file_id == self.utility_bill_2_file_id
        assert utility_bill.files[1].file_unique_id == self.utility_bill_2_file_unique_id

        assert isinstance(utility_bill.translation[0], PassportFile)
        assert utility_bill.translation[0].file_id == self.utility_bill_translation_1_file_id
        assert (
            utility_bill.translation[0].file_unique_id
            == self.utility_bill_translation_1_file_unique_id
        )

        assert isinstance(utility_bill.translation[1], PassportFile)
        assert utility_bill.translation[1].file_id == self.utility_bill_translation_2_file_id
        assert (
            utility_bill.translation[1].file_unique_id
            == self.utility_bill_translation_2_file_unique_id
        )

        assert address.type == "address"
        assert address.data == RAW_PASSPORT_DATA["data"][3]["data"]

        assert email.type == "email"
        assert email.email == "fb3e3i47zt@dispostable.com"

    def test_expected_decrypted_values(self, passport_data):
        (
            personal_details,
            driver_license,
            utility_bill,
            address,
            email,
        ) = passport_data.decrypted_data

        assert personal_details.type == "personal_details"
        assert personal_details.data.to_dict() == {
            "first_name": "FIRSTNAME",
            "middle_name": "MIDDLENAME",
            "first_name_native": "FIRSTNAMENATIVE",
            "residence_country_code": "DK",
            "birth_date": "01.01.2001",
            "last_name_native": "LASTNAMENATIVE",
            "gender": "female",
            "middle_name_native": "MIDDLENAMENATIVE",
            "country_code": "DK",
            "last_name": "LASTNAME",
        }

        assert driver_license.type == "driver_license"
        assert driver_license.data.to_dict() == {
            "expiry_date": "01.01.2001",
            "document_no": "DOCUMENT_NO",
        }
        assert isinstance(driver_license.selfie, PassportFile)
        assert driver_license.selfie.file_id == self.driver_license_selfie_file_id
        assert driver_license.selfie.file_unique_id == self.driver_license_selfie_file_unique_id

        assert isinstance(driver_license.front_side, PassportFile)
        assert driver_license.front_side.file_id == self.driver_license_front_side_file_id
        assert (
            driver_license.front_side.file_unique_id
            == self.driver_license_front_side_file_unique_id
        )

        assert isinstance(driver_license.reverse_side, PassportFile)
        assert driver_license.reverse_side.file_id == self.driver_license_reverse_side_file_id
        assert (
            driver_license.reverse_side.file_unique_id
            == self.driver_license_reverse_side_file_unique_id
        )

        assert address.type == "address"
        assert address.data.to_dict() == {
            "city": "CITY",
            "street_line2": "STREET_LINE2",
            "state": "STATE",
            "post_code": "POSTCODE",
            "country_code": "DK",
            "street_line1": "STREET_LINE1",
        }

        assert utility_bill.type == "utility_bill"
        assert isinstance(utility_bill.files[0], PassportFile)
        assert utility_bill.files[0].file_id == self.utility_bill_1_file_id
        assert utility_bill.files[0].file_unique_id == self.utility_bill_1_file_unique_id

        assert isinstance(utility_bill.files[1], PassportFile)
        assert utility_bill.files[1].file_id == self.utility_bill_2_file_id
        assert utility_bill.files[1].file_unique_id == self.utility_bill_2_file_unique_id

        assert email.type == "email"
        assert email.email == "fb3e3i47zt@dispostable.com"

    def test_de_json_and_to_dict(self, offline_bot):
        passport_data = PassportData.de_json(RAW_PASSPORT_DATA, offline_bot)
        assert passport_data.api_kwargs == {}
        assert passport_data.to_dict() == RAW_PASSPORT_DATA

        assert passport_data.decrypted_data
        assert passport_data.to_dict() == RAW_PASSPORT_DATA

    def test_equality(self, passport_data):
        a = PassportData(passport_data.data, passport_data.credentials)
        b = PassportData(passport_data.data, passport_data.credentials)

        assert a == b
        assert hash(a) == hash(b)
        assert a is not b

        new_pp_data = deepcopy(passport_data)
        new_pp_data.credentials._unfreeze()
        new_pp_data.credentials.hash = "NOTAPROPERHASH"
        c = PassportData(new_pp_data.data, new_pp_data.credentials)

        assert a != c
        assert hash(a) != hash(c)

    def test_bot_init_invalid_key(self, offline_bot):
        with pytest.raises(TypeError):
            Bot(offline_bot.token, private_key="Invalid key!")

        # Different error messages for different cryptography versions
        with pytest.raises(
            ValueError, match="(Could not deserialize key data)|(Unable to load PEM file)"
        ):
            Bot(offline_bot.token, private_key=b"Invalid key!")

    def test_all_types(self, passport_data, offline_bot, all_passport_data):
        credentials = passport_data.decrypted_credentials.to_dict()

        # Copy credentials from other types to all types so we can decrypt everything
        sd = credentials["secure_data"]
        credentials["secure_data"] = {
            "personal_details": sd["personal_details"].copy(),
            "passport": sd["driver_license"].copy(),
            "internal_passport": sd["driver_license"].copy(),
            "driver_license": sd["driver_license"].copy(),
            "identity_card": sd["driver_license"].copy(),
            "address": sd["address"].copy(),
            "utility_bill": sd["utility_bill"].copy(),
            "bank_statement": sd["utility_bill"].copy(),
            "rental_agreement": sd["utility_bill"].copy(),
            "passport_registration": sd["utility_bill"].copy(),
            "temporary_registration": sd["utility_bill"].copy(),
        }

        new = PassportData.de_json(
            {
                "data": all_passport_data,
                # Replaced below
                "credentials": {"data": "data", "hash": "hash", "secret": "secret"},
            },
            bot=offline_bot,
        )
        assert new.api_kwargs == {}

        new.credentials._decrypted_data = Credentials.de_json(credentials, offline_bot)
        assert new.credentials.api_kwargs == {}

        assert isinstance(new, PassportData)
        assert new.decrypted_data

    async def test_passport_data_okay_with_non_crypto_bot(self, offline_bot):
        async with make_bot(token=offline_bot.token) as b:
            assert PassportData.de_json(RAW_PASSPORT_DATA, bot=b)

    def test_wrong_hash(self, offline_bot):
        data = deepcopy(RAW_PASSPORT_DATA)
        data["credentials"]["hash"] = "bm90Y29ycmVjdGhhc2g="  # Not correct hash
        passport_data = PassportData.de_json(data, bot=offline_bot)
        with pytest.raises(PassportDecryptionError):
            assert passport_data.decrypted_data

    async def test_wrong_key(self, offline_bot):
        short_key = (
            b"-----BEGIN RSA PRIVATE"
            b" KEY-----\r\nMIIBOQIBAAJBAKU+OZ2jJm7sCA/ec4gngNZhXYPu+DZ/TAwSMl0W7vAPXAsLplBk\r\nO8l6IBHx8N0ZC4Bc65mO3b2G8YAzqndyqH8CAwEAAQJAWOx3jQFzeVXDsOaBPdAk\r\nYTncXVeIc6tlfUl9mOLyinSbRNCy1XicOiOZFgH1rRKOGIC1235QmqxFvdecySoY\r\nwQIhAOFeGgeX9CrEPuSsd9+kqUcA2avCwqdQgSdy2qggRFyJAiEAu7QHT8JQSkHU\r\nDELfzrzc24AhjyG0z1DpGZArM8COascCIDK42SboXj3Z2UXiQ0CEcMzYNiVgOisq\r\nBUd5pBi+2mPxAiAM5Z7G/Sv1HjbKrOGh29o0/sXPhtpckEuj5QMC6E0gywIgFY6S\r\nNjwrAA+cMmsgY0O2fAzEKkDc5YiFsiXaGaSS4eA=\r\n-----END"
            b" RSA PRIVATE KEY-----"
        )
        async with make_bot(token=offline_bot.token, private_key=short_key) as b:
            passport_data = PassportData.de_json(RAW_PASSPORT_DATA, bot=b)
            with pytest.raises(PassportDecryptionError):
                assert passport_data.decrypted_data

        async with make_bot(token=offline_bot.token, private_key=short_key) as b:
            passport_data = PassportData.de_json(RAW_PASSPORT_DATA, bot=b)
            with pytest.raises(PassportDecryptionError):
                assert passport_data.decrypted_data

    async def test_mocked_download_passport_file(self, passport_data, monkeypatch):
        # The files are not coming from our test offline_bot, therefore the file id is invalid/wrong
        # when coming from this offline_bot, so we monkeypatch the call, to make sure that Bot.get_file
        # at least gets called
        # TODO: Actually download a passport file in a test
        selfie = passport_data.decrypted_data[1].selfie

        # NOTE: file_unique_id is not used in the get_file method, so it is passed directly
        async def get_file(*_, **kwargs):
            return File(kwargs["file_id"], selfie.file_unique_id)

        monkeypatch.setattr(passport_data.get_bot(), "get_file", get_file)
        file = await selfie.get_file()
        assert file.file_id == selfie.file_id
        assert file.file_unique_id == selfie.file_unique_id
        assert file._credentials.file_hash == self.driver_license_selfie_credentials_file_hash
        assert file._credentials.secret == self.driver_license_selfie_credentials_secret

    async def test_mocked_set_passport_data_errors(
        self, monkeypatch, offline_bot, chat_id, passport_data
    ):
        async def make_assertion(url, request_data: RequestData, *args, **kwargs):
            data = request_data.parameters
            return (
                data["user_id"] == str(chat_id)
                and data["errors"][0]["file_hash"]
                == (
                    passport_data.decrypted_credentials.secure_data.driver_license.selfie.file_hash
                )
                and data["errors"][1]["data_hash"]
                == passport_data.decrypted_credentials.secure_data.driver_license.data.data_hash
            )

        monkeypatch.setattr(offline_bot.request, "post", make_assertion)
        message = await offline_bot.set_passport_data_errors(
            chat_id,
            [
                PassportElementErrorSelfie(
                    "driver_license",
                    (
                        passport_data.decrypted_credentials.secure_data.driver_license.selfie.file_hash
                    ),
                    "You're not handsome enough to use this app!",
                ),
                PassportElementErrorDataField(
                    "driver_license",
                    "expiry_date",
                    (
                        passport_data.decrypted_credentials.secure_data.driver_license.data.data_hash
                    ),
                    "Your driver license is expired!",
                ),
            ],
        )
        assert message