|
4 | 4 |
|
5 | 5 | import asyncio |
6 | 6 | import uuid |
7 | | -from typing import Optional |
8 | 7 |
|
9 | 8 | import pytest |
10 | 9 | from acapy_controller import Controller |
11 | 10 | from acapy_controller.controller import params |
12 | | -from acapy_controller.protocols import ( |
13 | | - ConnRecord, |
14 | | - InvitationMessage, |
15 | | - OobRecord, |
16 | | - oob_invitation, |
17 | | -) |
18 | 11 |
|
19 | 12 | from .constants import ( |
20 | 13 | CONTROLLER_ENV, |
|
26 | 19 | ) |
27 | 20 |
|
28 | 21 |
|
29 | | -async def didexchange( |
30 | | - inviter: Controller, |
31 | | - invitee: Controller, |
32 | | - *, |
33 | | - invite: Optional[InvitationMessage] = None, |
34 | | - use_existing_connection: bool = False, |
35 | | - alias: Optional[str] = None, |
36 | | -): |
37 | | - """Connect two agents using did exchange protocol.""" |
38 | | - if not invite: |
39 | | - invite = await oob_invitation(inviter) |
40 | | - |
41 | | - invitee_oob_record = await invitee.post( |
42 | | - "/out-of-band/receive-invitation", |
43 | | - json=invite, |
44 | | - params=params( |
45 | | - use_existing_connection=use_existing_connection, |
46 | | - alias=alias, |
47 | | - ), |
48 | | - response=OobRecord, |
49 | | - ) |
50 | | - |
51 | | - if use_existing_connection and invitee_oob_record == "reuse-accepted": |
52 | | - inviter_oob_record = await inviter.event_with_values( |
53 | | - topic="out_of_band", |
54 | | - invi_msg_id=invite.id, |
55 | | - event_type=OobRecord, |
56 | | - ) |
57 | | - inviter_conn = await inviter.get( |
58 | | - f"/connections/{inviter_oob_record.connection_id}", |
59 | | - response=ConnRecord, |
60 | | - ) |
61 | | - invitee_conn = await invitee.get( |
62 | | - f"/connections/{invitee_oob_record.connection_id}", |
63 | | - response=ConnRecord, |
64 | | - ) |
65 | | - return inviter_conn, invitee_conn |
66 | | - |
67 | | - invitee_conn = await invitee.post( |
68 | | - f"/didexchange/{invitee_oob_record.connection_id}/accept-invitation", |
69 | | - response=ConnRecord, |
70 | | - ) |
71 | | - inviter_oob_record = await inviter.event_with_values( |
72 | | - topic="out_of_band", |
73 | | - invi_msg_id=invite.id, |
74 | | - state="done", |
75 | | - event_type=OobRecord, |
76 | | - ) |
77 | | - inviter_conn = await inviter.event_with_values( |
78 | | - topic="connections", |
79 | | - event_type=ConnRecord, |
80 | | - rfc23_state="request-received", |
81 | | - invitation_key=inviter_oob_record.our_recipient_key, |
82 | | - ) |
83 | | - # TODO Remove after ACA-Py 0.12.0 |
84 | | - # There's a bug with race conditions in the OOB multiuse handling |
85 | | - await asyncio.sleep(1) |
86 | | - inviter_conn = await inviter.post( |
87 | | - f"/didexchange/{inviter_conn.connection_id}/accept-request", |
88 | | - response=ConnRecord, |
89 | | - ) |
90 | | - |
91 | | - await invitee.event_with_values( |
92 | | - topic="connections", |
93 | | - connection_id=invitee_conn.connection_id, |
94 | | - rfc23_state="response-received", |
95 | | - ) |
96 | | - invitee_conn = await invitee.event_with_values( |
97 | | - topic="connections", |
98 | | - connection_id=invitee_conn.connection_id, |
99 | | - rfc23_state="completed", |
100 | | - event_type=ConnRecord, |
101 | | - ) |
102 | | - inviter_conn = await inviter.event_with_values( |
103 | | - topic="connections", |
104 | | - connection_id=inviter_conn.connection_id, |
105 | | - rfc23_state="completed", |
106 | | - event_type=ConnRecord, |
107 | | - ) |
108 | | - |
109 | | - return inviter_conn, invitee_conn |
110 | | - |
111 | | - |
112 | 22 | @pytest.mark.asyncio |
113 | 23 | async def test_create_single_tenant(): |
114 | 24 | """Test Controller protocols.""" |
@@ -314,3 +224,53 @@ async def test_create_with_witness_and_manual_attest(): |
314 | 224 | did_web = f"did:web:{WEBVH_DOMAIN}:{TEST_NAMESPACE}:{identifier}" |
315 | 225 | assert response["did_document"]["id"] == did_web |
316 | 226 | assert response["did_document"]["alsoKnownAs"][0].startswith("did:webvh:") |
| 227 | + |
| 228 | + |
| 229 | +@pytest.mark.asyncio |
| 230 | +async def test_create_self_witness_and_manual_attest(): |
| 231 | + """Test Controller protocols.""" |
| 232 | + async with Controller(base_url=WITNESS) as witness: |
| 233 | + witness_config = (await witness.get("/status/config"))["config"] |
| 234 | + server_url: str = witness_config["plugin_config"]["did-webvh"]["server_url"] |
| 235 | + |
| 236 | + # Configure WebVH Witness |
| 237 | + response = await witness.post( |
| 238 | + "/did/webvh/configuration", |
| 239 | + json={ |
| 240 | + "server_url": server_url, |
| 241 | + "witness_key": WITNESS_KEY, |
| 242 | + "witness": True, |
| 243 | + "auto_attest": False, |
| 244 | + }, |
| 245 | + ) |
| 246 | + assert response["multikey"] == WITNESS_KEY |
| 247 | + |
| 248 | + # Ensure the witness key is properly configured |
| 249 | + response = await witness.get(f"/wallet/keys/{WITNESS_KEY}") |
| 250 | + assert response["kid"] == WITNESS_KID |
| 251 | + |
| 252 | + # Create the initial did |
| 253 | + identifier = str(uuid.uuid4()) |
| 254 | + response = await witness.post( |
| 255 | + "/did/webvh/controller/create", |
| 256 | + json={"options": {"namespace": TEST_NAMESPACE, "identifier": identifier}}, |
| 257 | + ) |
| 258 | + |
| 259 | + status = response.get("status") |
| 260 | + assert status == "pending" |
| 261 | + |
| 262 | + response = await witness.get("/did/webvh/witness/registrations") |
| 263 | + entry = response.get("results", []).pop() |
| 264 | + assert isinstance(entry, dict) |
| 265 | + |
| 266 | + await witness.post( |
| 267 | + "/did/webvh/witness/registrations", |
| 268 | + params=params(did=entry["id"]), |
| 269 | + ) |
| 270 | + await asyncio.sleep(3) |
| 271 | + |
| 272 | + # Confirm DID is published |
| 273 | + response = await witness.get(f"/resolver/resolve/{entry['id']}") |
| 274 | + did_web = f"did:web:{WEBVH_DOMAIN}:{TEST_NAMESPACE}:{identifier}" |
| 275 | + assert response["did_document"]["id"] == did_web |
| 276 | + assert response["did_document"]["alsoKnownAs"][0].startswith("did:webvh:") |
0 commit comments