-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_v2_indy.py
294 lines (243 loc) · 8.71 KB
/
test_v2_indy.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
import asyncio
import pytest
from assertpy import assert_that
from app.event_handling.sse_listener import SseListener
from app.models.tenants import CreateTenantResponse
from app.routes.definitions import CredentialSchema
from app.routes.issuer import router as issuer_router
from app.routes.oob import router as oob_router
from app.tests.util.ecosystem_connections import FaberAliceConnect
from app.tests.util.webhooks import check_webhook_state, get_wallet_id_from_async_client
from app.util.credentials import cred_id_no_version
from shared import RichAsyncClient
CREDENTIALS_BASE_PATH = issuer_router.prefix
OOB_BASE_PATH = oob_router.prefix
@pytest.mark.anyio
async def test_send_credential_oob_v2(
faber_client: RichAsyncClient,
schema_definition: CredentialSchema,
credential_definition_id: str,
alice_member_client: RichAsyncClient,
):
wallet_id = get_wallet_id_from_async_client(alice_member_client)
alice_credentials_listener = SseListener(topic="credentials", wallet_id=wallet_id)
credential = {
"protocol_version": "v2",
"indy_credential_detail": {
"credential_definition_id": credential_definition_id,
"attributes": {"speed": "10"},
},
}
create_offer_response = await faber_client.post(
CREDENTIALS_BASE_PATH + "/create-offer",
json=credential,
)
data = create_offer_response.json()
assert_that(data).contains("credential_id")
assert_that(data).has_state("offer-sent")
assert_that(data).has_protocol_version("v2")
assert_that(data).has_attributes({"speed": "10"})
assert_that(data).has_schema_id(schema_definition.id)
invitation_response = await faber_client.post(
OOB_BASE_PATH + "/create-invitation",
json={
"create_connection": False,
"use_public_did": False,
"attachments": [
{"id": data["credential_id"][3:], "type": "credential-offer"}
],
},
)
assert_that(invitation_response.status_code).is_equal_to(200)
invitation = (invitation_response.json())["invitation"]
thread_id = invitation["requests~attach"][0]["data"]["json"]["@id"]
accept_response = await alice_member_client.post(
OOB_BASE_PATH + "/accept-invitation",
json={"invitation": invitation},
)
oob_record = accept_response.json()
assert_that(accept_response.status_code).is_equal_to(200)
assert_that(oob_record).contains("created_at", "oob_id", "invitation")
result = await alice_credentials_listener.wait_for_event(
field="thread_id",
field_id=thread_id,
desired_state="offer-received",
)
assert result["credential_id"]
@pytest.mark.anyio
async def test_send_credential(
faber_client: RichAsyncClient,
schema_definition: CredentialSchema,
credential_definition_id: str,
faber_and_alice_connection: FaberAliceConnect,
alice_member_client: RichAsyncClient,
):
credential = {
"protocol_version": "v2",
"connection_id": faber_and_alice_connection.faber_connection_id,
"indy_credential_detail": {
"credential_definition_id": credential_definition_id,
"attributes": {"speed": "10"},
},
}
response = await alice_member_client.get(
CREDENTIALS_BASE_PATH,
params={"connection_id": faber_and_alice_connection.alice_connection_id},
)
records = response.json()
# nothing currently in alice's records
assert len(records) == 0
response = await faber_client.post(
CREDENTIALS_BASE_PATH,
json=credential,
)
data = response.json()
assert_that(data).contains("credential_id")
assert_that(data).has_state("offer-sent")
assert_that(data).has_protocol_version("v2")
assert_that(data).has_attributes({"speed": "10"})
assert_that(data).has_schema_id(schema_definition.id)
assert await check_webhook_state(
client=faber_client,
topic="credentials",
filter_map={
"state": "offer-sent",
"credential_id": data["credential_id"],
},
)
@pytest.mark.anyio
async def test_create_offer(
faber_client: RichAsyncClient,
schema_definition: CredentialSchema,
credential_definition_id: str,
):
credential = {
"protocol_version": "v2",
"indy_credential_detail": {
"credential_definition_id": credential_definition_id,
"attributes": {"speed": "10"},
},
}
response = await faber_client.post(
CREDENTIALS_BASE_PATH + "/create-offer",
json=credential,
)
data = response.json()
assert_that(data).contains("credential_id")
assert_that(data).has_state("offer-sent")
assert_that(data).has_protocol_version("v2")
assert_that(data).has_attributes({"speed": "10"})
assert_that(data).has_schema_id(schema_definition.id)
assert await check_webhook_state(
client=faber_client,
topic="credentials",
filter_map={
"state": "offer-sent",
"credential_id": data["credential_id"],
},
)
@pytest.mark.anyio
async def test_send_credential_request(
alice_member_client: RichAsyncClient,
faber_client: RichAsyncClient,
faber_and_alice_connection: FaberAliceConnect,
credential_definition_id: str,
):
credential = {
"protocol_version": "v2",
"connection_id": faber_and_alice_connection.faber_connection_id,
"indy_credential_detail": {
"credential_definition_id": credential_definition_id,
"attributes": {"speed": "10"},
},
}
response = await faber_client.post(
CREDENTIALS_BASE_PATH,
json=credential,
)
credential_exchange = response.json()
assert credential_exchange["protocol_version"] == "v2"
assert await check_webhook_state(
client=faber_client,
topic="credentials",
filter_map={
"state": "offer-sent",
"credential_id": credential_exchange["credential_id"],
},
)
await asyncio.sleep(0.1) # credential may take moment to reflect after webhook
response = await alice_member_client.get(
CREDENTIALS_BASE_PATH,
params={"connection_id": faber_and_alice_connection.alice_connection_id},
)
credential_id = (response.json())[0]["credential_id"]
assert await check_webhook_state(
client=alice_member_client,
filter_map={"state": "offer-received"},
topic="credentials",
)
request_response = await alice_member_client.post(
f"{CREDENTIALS_BASE_PATH}/{credential_id}/request",
)
assert request_response.status_code == 200
assert await check_webhook_state(
client=alice_member_client,
filter_map={"state": "request-sent"},
topic="credentials",
)
assert await check_webhook_state(
client=faber_client,
filter_map={"state": "request-received"},
topic="credentials",
)
@pytest.mark.anyio
async def test_revoke_credential(
faber_client: RichAsyncClient,
alice_member_client: RichAsyncClient,
alice_tenant: CreateTenantResponse,
credential_definition_id_revocable: str,
faber_and_alice_connection: FaberAliceConnect,
):
faber_connection_id = faber_and_alice_connection.faber_connection_id
credential = {
"protocol_version": "v2",
"connection_id": faber_connection_id,
"indy_credential_detail": {
"credential_definition_id": credential_definition_id_revocable,
"attributes": {"speed": "10"},
},
}
alice_credentials_listener = SseListener(
topic="credentials", wallet_id=alice_tenant.wallet_id
)
# create and send credential offer: issuer
faber_credential_id = (
await faber_client.post(
CREDENTIALS_BASE_PATH,
json=credential,
)
).json()["credential_id"]
payload = await alice_credentials_listener.wait_for_event(
field="connection_id",
field_id=faber_and_alice_connection.alice_connection_id,
desired_state="offer-received",
)
alice_credential_id = payload["credential_id"]
# send credential request: holder
response = await alice_member_client.post(
f"{CREDENTIALS_BASE_PATH}/{alice_credential_id}/request", json={}
)
await alice_credentials_listener.wait_for_event(
field="credential_id",
field_id=alice_credential_id,
desired_state="done",
)
cred_id = cred_id_no_version(faber_credential_id)
response = await faber_client.post(
f"{CREDENTIALS_BASE_PATH}/revoke",
json={
"credential_definition_id": credential_definition_id_revocable,
"credential_exchange_id": cred_id,
},
)
assert response.status_code == 204