-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_verifier.py
848 lines (727 loc) · 24.7 KB
/
test_verifier.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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
from unittest.mock import AsyncMock, patch
import pytest
from aries_cloudcontroller import AcaPyClient, ConnRecord, IndyCredInfo, IndyCredPrecis
from fastapi.testclient import TestClient
from mockito import verify, when
from pytest_mock import MockerFixture
import app.routes.verifier as test_module
from app.dependencies.auth import AcaPyAuth
from app.exceptions.cloudapi_exception import CloudApiException
from app.main import app
from app.models.verifier import CredInfo, CredPrecis
from app.routes.verifier import acapy_auth_from_header, get_credentials_by_proof_id
from app.services.verifier.acapy_verifier_v2 import VerifierV2
from app.tests.services.verifier.utils import indy_pres_spec, sample_indy_proof_request
from app.tests.util.mock import to_async
from app.util import acapy_verifier_utils
from shared.models.presentation_exchange import PresentationExchange
from shared.models.trustregistry import Actor
from shared.util.mock_agent_controller import MockContextManagedController
presentation_exchange_record_2 = PresentationExchange(
connection_id="abcde",
created_at="2021-11-22 11:37:45.179595Z",
updated_at="2021-11-22 11:37:45.179595Z",
proof_id="abcde",
presentation={},
role="prover",
state="presentation-sent",
verified=False,
)
actor = Actor(
id="abcde",
name="Flint",
roles=["verifier"],
did="did:sov:2cpBmR3FqGKWi5EyUbpRY8",
didcomm_invitation=None,
)
conn_record = ConnRecord(
connection_id="abcde",
invitation_key="H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV",
)
@pytest.mark.anyio
async def test_send_proof_request_v2(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
# V2
when(VerifierV2).send_proof_request(...).thenReturn(
to_async(presentation_exchange_record_2)
)
when(mock_agent_controller.connection).get_connection(conn_id="abcde").thenReturn(
to_async(conn_record)
)
when(mock_agent_controller.wallet).get_public_did().thenRaise(
CloudApiException("No did")
)
when(acapy_verifier_utils).get_actor(
did="did:key:z6MkvVT4kkAmhTb9srDHScsL1q7pVKt9cpUJUah2pKuYh4As"
).thenReturn(to_async(actor))
send_proof_request = test_module.SendProofRequest(
connection_id="abcde",
indy_proof_request=sample_indy_proof_request(),
)
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
result = await test_module.send_proof_request(
body=send_proof_request,
auth=mock_tenant_auth,
)
assert result is presentation_exchange_record_2
verify(VerifierV2).send_proof_request(
controller=mock_agent_controller, send_proof_request=send_proof_request
)
@pytest.mark.anyio
async def test_send_proof_request_v2_exception(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
# V2
when(VerifierV2).send_proof_request(...).thenRaise(CloudApiException("ERROR"))
mocker.patch.object(
test_module,
"assert_valid_verifier",
return_value=None,
)
send_proof_request = test_module.SendProofRequest(
connection_id="abcde",
indy_proof_request=sample_indy_proof_request(),
)
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
with pytest.raises(CloudApiException, match="500: ERROR") as exc:
await test_module.send_proof_request(
body=send_proof_request,
auth=mock_tenant_auth,
)
assert exc.value.status_code == 500
@pytest.mark.anyio
async def test_send_proof_request_v2_no_response(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
# V2
when(VerifierV2).send_proof_request(...).thenReturn(to_async(None))
mocker.patch.object(
test_module,
"assert_valid_verifier",
return_value=None,
)
send_proof_request = test_module.SendProofRequest(
connection_id="abcde",
indy_proof_request=sample_indy_proof_request(),
)
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
result = await test_module.send_proof_request(
body=send_proof_request,
auth=mock_tenant_auth,
)
assert result is None
verify(VerifierV2).send_proof_request(
controller=mock_agent_controller, send_proof_request=send_proof_request
)
@pytest.mark.anyio
async def test_create_proof_request(mock_tenant_auth: AcaPyAuth):
when(VerifierV2).create_proof_request(...).thenReturn(
to_async(presentation_exchange_record_2)
)
result = await test_module.create_proof_request(
body=test_module.CreateProofRequest(
indy_proof_request=sample_indy_proof_request(),
connection_id="abcde",
),
auth=mock_tenant_auth,
)
assert result is presentation_exchange_record_2
@pytest.mark.anyio
async def test_create_proof_request_exception(mock_tenant_auth: AcaPyAuth):
when(VerifierV2).create_proof_request(...).thenRaise(CloudApiException("ERROR"))
with pytest.raises(CloudApiException, match="500: ERROR") as exc:
await test_module.create_proof_request(
body=test_module.CreateProofRequest(
indy_proof_request=sample_indy_proof_request(),
connection_id="abcde",
),
auth=mock_tenant_auth,
)
assert exc.value.status_code == 500
@pytest.mark.anyio
async def test_create_proof_request_no_result(mock_tenant_auth: AcaPyAuth):
when(VerifierV2).create_proof_request(...).thenReturn(to_async(None))
result = await test_module.create_proof_request(
body=test_module.CreateProofRequest(
indy_proof_request=sample_indy_proof_request(),
connection_id="abcde",
),
auth=mock_tenant_auth,
)
assert result is None
@pytest.mark.anyio
async def test_accept_proof_request_v2(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
# V2
when(VerifierV2).accept_proof_request(...).thenReturn(
to_async(presentation_exchange_record_2)
)
when(VerifierV2).get_proof_record(...).thenReturn(
to_async(presentation_exchange_record_2)
)
presentation = test_module.AcceptProofRequest(
proof_id="v2-1234", indy_presentation_spec=indy_pres_spec
)
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
mocker.patch.object(
test_module, "assert_valid_prover", new_callable=AsyncMock, return_value=None
)
result = await test_module.accept_proof_request(
body=presentation,
auth=mock_tenant_auth,
)
assert result is presentation_exchange_record_2
verify(VerifierV2).accept_proof_request(...)
@pytest.mark.anyio
async def test_accept_proof_request_v2_exception(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
# V2
when(VerifierV2).accept_proof_request(...).thenRaise(CloudApiException("ERROR"))
when(VerifierV2).get_proof_record(...).thenReturn(
to_async(presentation_exchange_record_2)
)
presentation = test_module.AcceptProofRequest(
proof_id="v2-1234", indy_presentation_spec=indy_pres_spec
)
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
mocker.patch.object(
test_module, "assert_valid_prover", new_callable=AsyncMock, return_value=None
)
with pytest.raises(CloudApiException, match="500: ERROR") as exc:
await test_module.accept_proof_request(
body=presentation,
auth=mock_tenant_auth,
)
assert exc.value.status_code == 500
@pytest.mark.anyio
async def test_accept_proof_request_v2_no_result(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
# V2
when(VerifierV2).accept_proof_request(...).thenReturn(to_async(None))
when(VerifierV2).get_proof_record(...).thenReturn(
to_async(presentation_exchange_record_2)
)
presentation = test_module.AcceptProofRequest(
proof_id="v2-1234", indy_presentation_spec=indy_pres_spec
)
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
mocker.patch.object(
test_module, "assert_valid_prover", new_callable=AsyncMock, return_value=None
)
result = await test_module.accept_proof_request(
body=presentation,
auth=mock_tenant_auth,
)
assert result is None
verify(VerifierV2).accept_proof_request(...)
@pytest.mark.anyio
async def test_accept_proof_request_v2_no_connection(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
presentation_exchange_record_no_conn = presentation_exchange_record_2.model_copy()
presentation_exchange_record_no_conn.connection_id = None
# V2
when(VerifierV2).accept_proof_request(...).thenReturn(
to_async(presentation_exchange_record_no_conn)
)
when(VerifierV2).get_proof_record(...).thenReturn(
to_async(presentation_exchange_record_no_conn)
)
presentation = test_module.AcceptProofRequest(
proof_id="v2-1234", indy_presentation_spec=indy_pres_spec
)
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
mocker.patch.object(
test_module, "assert_valid_prover", new_callable=AsyncMock, return_value=None
)
result = await test_module.accept_proof_request(
body=presentation,
auth=mock_tenant_auth,
)
assert result is presentation_exchange_record_no_conn
verify(VerifierV2).accept_proof_request(...)
@pytest.mark.anyio
async def test_reject_proof_request(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
proof_request_v2 = test_module.RejectProofRequest(
proof_id="v2-1234", problem_report="rejected"
)
when(VerifierV2).reject_proof_request(
controller=mock_agent_controller, reject_proof_request=proof_request_v2
).thenReturn(to_async(None))
presentation_exchange_record_2.state = "request-received"
when(VerifierV2).get_proof_record(
controller=mock_agent_controller, proof_id=proof_request_v2.proof_id
).thenReturn(to_async(presentation_exchange_record_2))
result = await test_module.reject_proof_request(
body=test_module.RejectProofRequest(
proof_id="v2-1234", problem_report="rejected"
),
auth=mock_tenant_auth,
)
assert result is None
verify(VerifierV2).reject_proof_request(
controller=mock_agent_controller, reject_proof_request=proof_request_v2
)
verify(VerifierV2).get_proof_record(
controller=mock_agent_controller, proof_id=proof_request_v2.proof_id
)
@pytest.mark.anyio
async def test_reject_proof_request_bad_state(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
proof_request_v2 = test_module.RejectProofRequest(
proof_id="v2-1234", problem_report="rejected"
)
presentation_exchange_record_2.state = "done"
when(VerifierV2).get_proof_record(
controller=mock_agent_controller, proof_id=proof_request_v2.proof_id
).thenReturn(to_async(presentation_exchange_record_2))
with pytest.raises(
CloudApiException,
match="400: Proof record must be in state `request-received` to reject; record has state: `done`.",
):
await test_module.reject_proof_request(
body=test_module.RejectProofRequest(
proof_id="v2-1234", problem_report="rejected"
),
auth=mock_tenant_auth,
)
verify(VerifierV2).get_proof_record(
controller=mock_agent_controller, proof_id=proof_request_v2.proof_id
)
@pytest.mark.anyio
async def test_delete_proof(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
when(VerifierV2).delete_proof(
controller=mock_agent_controller, proof_id="v2-1234"
).thenReturn(to_async())
result = await test_module.delete_proof(proof_id="v2-1234", auth=mock_tenant_auth)
assert result is None
verify(VerifierV2).delete_proof(
controller=mock_agent_controller, proof_id="v2-1234"
)
@pytest.mark.anyio
async def test_delete_proof_exception(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
when(VerifierV2).delete_proof(
controller=mock_agent_controller, proof_id="v2-1234"
).thenRaise(CloudApiException("ERROR"))
with pytest.raises(CloudApiException, match="500: ERROR") as exc:
await test_module.delete_proof(proof_id="v2-1234", auth=mock_tenant_auth)
assert exc.value.status_code == 500
@pytest.mark.anyio
async def test_get_proof_record(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
# V2
when(VerifierV2).get_proof_record(
controller=mock_agent_controller, proof_id="v2-abcd"
).thenReturn(to_async(presentation_exchange_record_2))
result = await test_module.get_proof_record(
proof_id="v2-abcd",
auth=mock_tenant_auth,
)
assert result == presentation_exchange_record_2
verify(VerifierV2).get_proof_record(
controller=mock_agent_controller, proof_id="v2-abcd"
)
@pytest.mark.anyio
async def test_get_proof_record_exception(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
# V2
when(VerifierV2).get_proof_record(
controller=mock_agent_controller, proof_id="v2-abcd"
).thenRaise(CloudApiException("ERROR"))
with pytest.raises(CloudApiException, match="500: ERROR") as exc:
await test_module.get_proof_record(
proof_id="v2-abcd",
auth=mock_tenant_auth,
)
assert exc.value.status_code == 500
@pytest.mark.anyio
async def test_get_proof_record_no_result(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
# V2
when(VerifierV2).get_proof_record(
controller=mock_agent_controller, proof_id="v2-abcd"
).thenReturn(to_async(None))
result = await test_module.get_proof_record(
proof_id="v2-abcd",
auth=mock_tenant_auth,
)
assert result is None
verify(VerifierV2).get_proof_record(
controller=mock_agent_controller, proof_id="v2-abcd"
)
@pytest.mark.anyio
async def test_get_proof_records(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
with when(VerifierV2).get_proof_records(
controller=mock_agent_controller,
limit=100,
offset=0,
order_by="id",
descending=True,
connection_id=None,
role=None,
state=None,
thread_id=None,
).thenReturn(to_async([presentation_exchange_record_2])):
result = await test_module.get_proof_records(
auth=mock_tenant_auth,
limit=100,
offset=0,
order_by="id",
descending=True,
connection_id=None,
role=None,
state=None,
thread_id=None,
)
assert result == [
presentation_exchange_record_2,
]
verify(VerifierV2).get_proof_records(
controller=mock_agent_controller,
limit=100,
offset=0,
order_by="id",
descending=True,
connection_id=None,
role=None,
state=None,
thread_id=None,
)
@pytest.mark.anyio
async def test_get_proof_records_exception(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
with when(VerifierV2).get_proof_records(
controller=mock_agent_controller,
limit=100,
offset=0,
order_by="id",
descending=True,
connection_id=None,
role=None,
state=None,
thread_id=None,
).thenRaise(CloudApiException("ERROR")):
with pytest.raises(CloudApiException, match="500: ERROR"):
await test_module.get_proof_records(
auth=mock_tenant_auth,
limit=100,
offset=0,
order_by="id",
descending=True,
connection_id=None,
role=None,
state=None,
thread_id=None,
)
@pytest.mark.anyio
async def test_get_proof_records_no_result(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
with when(VerifierV2).get_proof_records(
controller=mock_agent_controller,
limit=100,
offset=0,
order_by="id",
descending=True,
connection_id=None,
role=None,
state=None,
thread_id=None,
).thenReturn(to_async(None)):
result = await test_module.get_proof_records(
auth=mock_tenant_auth,
limit=100,
offset=0,
order_by="id",
descending=True,
connection_id=None,
role=None,
state=None,
thread_id=None,
)
assert result is None
verify(VerifierV2).get_proof_records(
controller=mock_agent_controller,
limit=100,
offset=0,
order_by="id",
descending=True,
connection_id=None,
role=None,
state=None,
thread_id=None,
)
@pytest.mark.anyio
async def test_get_credentials_by_proof_id(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
cred_precis = [
IndyCredPrecis(
cred_info=IndyCredInfo(
cred_def_id="WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
referent="abcde",
attrs={"attr1": "value1"},
),
)
]
returned_cred_precis = [
CredPrecis(
cred_info=CredInfo(
**cred.cred_info.model_dump(), credential_id=cred.cred_info.referent
),
interval=cred.interval,
presentation_referents=cred.presentation_referents,
)
for cred in cred_precis
]
# V2
when(VerifierV2).get_credentials_by_proof_id(
controller=mock_agent_controller,
proof_id="v2-abcd",
referent=None,
limit=100,
offset=0,
).thenReturn(to_async(cred_precis))
result = await test_module.get_credentials_by_proof_id(
proof_id="v2-abcd",
auth=mock_tenant_auth,
referent=None,
limit=100,
offset=0,
)
assert result == returned_cred_precis
verify(VerifierV2).get_credentials_by_proof_id(
controller=mock_agent_controller,
proof_id="v2-abcd",
referent=None,
limit=100,
offset=0,
)
@pytest.mark.anyio
async def test_get_credentials_by_proof_id_exception(
mock_agent_controller: AcaPyClient,
mock_context_managed_controller: MockContextManagedController,
mock_tenant_auth: AcaPyAuth,
mocker: MockerFixture,
):
mocker.patch.object(
test_module,
"client_from_auth",
return_value=mock_context_managed_controller(mock_agent_controller),
)
# V2
when(VerifierV2).get_credentials_by_proof_id(
controller=mock_agent_controller,
proof_id="v2-abcd",
referent=None,
limit=100,
offset=0,
).thenRaise(CloudApiException("ERROR"))
with pytest.raises(CloudApiException, match="500: ERROR"):
await test_module.get_credentials_by_proof_id(
proof_id="v2-abcd",
auth=mock_tenant_auth,
referent=None,
limit=100,
offset=0,
)
@pytest.mark.anyio
async def test_get_credentials_by_proof_id_bad_limit():
client = TestClient(app)
def override_auth():
return "mocked_auth"
app.dependency_overrides[acapy_auth_from_header] = override_auth
try:
response = client.get(
"/v1/verifier/proofs/v2-abcd/credentials",
params={"limit": 10001, "offset": 0},
headers={"x-api-key": "mocked_auth"},
)
assert response.status_code == 422
assert response.json() == {
"detail": [
{
"type": "less_than_equal",
"loc": ["query", "limit"],
"msg": "Input should be less than or equal to 10000",
"input": "10001",
"ctx": {"le": 10000},
}
]
}
finally:
app.dependency_overrides.clear()
@pytest.mark.anyio
async def test_get_credentials_by_proof_id_with_limit_offset():
mock_aries_controller = AsyncMock()
with patch("app.routes.verifier.client_from_auth") as mock_client_from_auth:
mock_client_from_auth.return_value.__aenter__.return_value = (
mock_aries_controller
)
await get_credentials_by_proof_id(
proof_id="v2-abcd",
auth="mocked_auth",
referent=None,
limit=2,
offset=1,
)
mock_aries_controller.present_proof_v2_0.get_matching_credentials.assert_called_once_with(
pres_ex_id="abcd",
referent=None,
limit=2,
offset=1,
)