-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_wallet_dids.py
131 lines (98 loc) · 4.23 KB
/
test_wallet_dids.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
import os
from typing import List
import pytest
from aries_cloudcontroller import DID, AcaPyClient
from assertpy import assert_that
import app.services.acapy_wallet as wallet_service
from app.dependencies.auth import AcaPyAuthVerified
from app.models.wallet import SetDidEndpointRequest
from app.routes.wallet.dids import (
get_did_endpoint,
get_public_did,
list_dids,
router,
set_did_endpoint,
)
from app.tests.util.ledger import create_public_did, post_to_ledger
from app.tests.util.regression_testing import TestMode
from shared import RichAsyncClient
WALLET_BASE_PATH = router.prefix
# The setting public did test should be skipped in prod.
# SKIP_SET_PUBLIC_DID env var is configured in capi_test charts
skip_set_public_did = os.getenv("SKIP_SET_PUBLIC_DID") is not None
async def create_did_mock(governance_client: RichAsyncClient):
did_response = await governance_client.post(WALLET_BASE_PATH)
did_response = did_response.json()
did = did_response["did"]
return did
@pytest.mark.anyio
async def test_list_dids(
governance_client: RichAsyncClient, mock_governance_auth: AcaPyAuthVerified
):
response = await governance_client.get(WALLET_BASE_PATH)
assert response.status_code == 200
response = response.json()
res_method: List[DID] = await list_dids(auth=mock_governance_auth)
res_method_dict = list(map(lambda x: x.to_dict(), res_method))
assert res_method_dict == response
@pytest.mark.anyio
async def test_create_local_did(governance_client: RichAsyncClient):
response = await governance_client.post(WALLET_BASE_PATH)
assert_that(response.status_code).is_equal_to(200)
response = response.json()
assert_that(response).contains("did", "verkey")
@pytest.mark.anyio
async def test_get_public_did(
governance_client: RichAsyncClient, mock_governance_auth: AcaPyAuthVerified
):
response = await governance_client.get(f"{WALLET_BASE_PATH}/public")
assert_that(response.status_code).is_equal_to(200)
response = response.json()
assert_that(response).contains("did", "verkey")
res_method: DID = await get_public_did(auth=mock_governance_auth)
assert res_method.to_dict() == response
@pytest.mark.anyio
async def test_get_did_endpoint(governance_client: RichAsyncClient):
did = await create_did_mock(governance_client)
response = await governance_client.get(f"{WALLET_BASE_PATH}/{did}/endpoint")
assert_that(response.status_code).is_equal_to(200)
response = response.json()
assert response["did"] == did
@pytest.mark.anyio
@pytest.mark.skipif(
skip_set_public_did or TestMode.regression_run in TestMode.fixture_params,
reason="Avoid creating additional did for governance from different seed",
)
async def test_set_public_did(
governance_client: RichAsyncClient, governance_acapy_client: AcaPyClient
):
did_object = await wallet_service.create_did(governance_acapy_client)
await post_to_ledger(did=did_object.did, verkey=did_object.verkey)
did = did_object.did
response = await governance_client.put(f"{WALLET_BASE_PATH}/public?did={did}")
assert_that(response.status_code).is_equal_to(200)
# With endorsement the set pub dic returns None but sets the did correctly
# So let's get it a different way and check that it is correct
response = await governance_client.get(f"{WALLET_BASE_PATH}/public")
assert_that(response.status_code).is_equal_to(200)
response = response.json()
assert_that(response).contains("did", "verkey")
assert_that(response).has_did(did)
@pytest.mark.anyio
@pytest.mark.skipif(
TestMode.regression_run in TestMode.fixture_params,
reason="Skip posting to ledger in regression mode",
)
async def test_set_did_endpoint(
governance_acapy_client: AcaPyClient, mock_governance_auth: AcaPyAuthVerified
):
# Don't want us overwriting the real endpoint, so not setting as public did
did = await create_public_did(governance_acapy_client, set_public=False)
endpoint = "https://ssi.com"
await set_did_endpoint(
did.did,
SetDidEndpointRequest(endpoint=endpoint),
auth=mock_governance_auth,
)
retrieved_endpoint = await get_did_endpoint(did.did, auth=mock_governance_auth)
assert_that(endpoint).is_equal_to(retrieved_endpoint.endpoint)