-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_proof_revoked_credential.py
203 lines (180 loc) · 6.41 KB
/
test_proof_revoked_credential.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
import time
from typing import List
import pytest
from app.routes.issuer import router
from app.routes.verifier import router as verifier_router
from app.tests.fixtures.credentials import ReferentCredDef
from app.tests.util.connections import AcmeAliceConnect
from app.tests.util.regression_testing import TestMode
from app.tests.util.verifier import send_proof_request
from app.tests.util.webhooks import assert_both_webhooks_received, check_webhook_state
from shared import RichAsyncClient
from shared.models.credential_exchange import CredentialExchange
CREDENTIALS_BASE_PATH = router.prefix
VERIFIER_BASE_PATH = verifier_router.prefix
@pytest.mark.anyio
@pytest.mark.parametrize(
"revoke_alice_creds_and_publish", ["auto_publish_true", "default"], indirect=True
)
@pytest.mark.parametrize("protocol_version", ["v1", "v2"])
@pytest.mark.skipif(
TestMode.regression_run in TestMode.fixture_params,
reason="Proving revoked credentials is currently non-deterministic",
)
async def test_proof_revoked_credential(
revoke_alice_creds_and_publish: List[ # pylint: disable=unused-argument
CredentialExchange
],
credential_definition_id_revocable: str,
acme_client: RichAsyncClient,
alice_member_client: RichAsyncClient,
acme_and_alice_connection: AcmeAliceConnect,
protocol_version: str,
):
time.sleep(10) # moment for revocation registry to update
# todo: remove sleep when issue resolved: https://github.com/hyperledger/aries-cloudagent-python/issues/3018
# Do proof request
request_body = {
"protocol_version": protocol_version,
"comment": "Test proof of revocation",
"type": "indy",
"indy_proof_request": {
"name": "Proof of SPEED",
"version": "1.0",
"non_revoked": {"to": int(time.time())},
"requested_attributes": {
"THE_SPEED": {
"name": "speed",
"restrictions": [
{"cred_def_id": credential_definition_id_revocable}
],
}
},
"requested_predicates": {},
},
"save_exchange_record": True,
"connection_id": acme_and_alice_connection.acme_connection_id,
}
send_proof_response = await send_proof_request(acme_client, request_body)
acme_proof_exchange_id = send_proof_response["proof_id"]
alice_payload = await check_webhook_state(
client=alice_member_client,
topic="proofs",
state="request-received",
filter_map={
"thread_id": send_proof_response["thread_id"],
},
)
alice_proof_exchange_id = alice_payload["proof_id"]
# Get referent
referent = (
await alice_member_client.get(
f"{VERIFIER_BASE_PATH}/proofs/{alice_proof_exchange_id}/credentials"
)
).json()[0]["cred_info"]["referent"]
# Send proof
await alice_member_client.post(
f"{VERIFIER_BASE_PATH}/accept-request",
json={
"proof_id": alice_proof_exchange_id,
"type": "indy",
"indy_presentation_spec": {
"requested_attributes": {
"THE_SPEED": {"cred_id": referent, "revealed": True}
},
"requested_predicates": {},
"self_attested_attributes": {},
},
"dif_presentation_spec": {},
},
)
await assert_both_webhooks_received(
alice_member_client,
acme_client,
"proofs",
"done",
alice_proof_exchange_id,
acme_proof_exchange_id,
)
# Check proof
proof = (
await acme_client.get(f"{VERIFIER_BASE_PATH}/proofs/{acme_proof_exchange_id}")
).json()
assert proof["verified"] is False
@pytest.mark.anyio
@pytest.mark.skipif(
TestMode.clean_run in TestMode.fixture_params,
reason="Run only in regression mode",
)
async def test_regression_proof_revoked_credential(
get_or_issue_regression_cred_revoked: ReferentCredDef,
acme_client: RichAsyncClient,
alice_member_client: RichAsyncClient,
acme_and_alice_connection: AcmeAliceConnect,
):
time.sleep(10) # moment for revocation registry to update
# todo: remove sleep when issue resolved: https://github.com/hyperledger/aries-cloudagent-python/issues/3018
referent = get_or_issue_regression_cred_revoked.referent
credential_definition_id_revocable = (
get_or_issue_regression_cred_revoked.cred_def_revocable
)
# Do proof request
request_body = {
"protocol_version": "v2",
"comment": "Test proof of revocation",
"type": "indy",
"indy_proof_request": {
"non_revoked": {"to": int(time.time())},
"requested_attributes": {
"THE_SPEED": {
"name": "speed",
"restrictions": [
{"cred_def_id": credential_definition_id_revocable}
],
}
},
"requested_predicates": {},
},
"save_exchange_record": True,
"connection_id": acme_and_alice_connection.acme_connection_id,
}
send_proof_response = await send_proof_request(acme_client, request_body)
acme_proof_exchange_id = send_proof_response["proof_id"]
alice_payload = await check_webhook_state(
client=alice_member_client,
topic="proofs",
state="request-received",
filter_map={
"thread_id": send_proof_response["thread_id"],
},
)
alice_proof_exchange_id = alice_payload["proof_id"]
# Send proof
await alice_member_client.post(
f"{VERIFIER_BASE_PATH}/accept-request",
json={
"proof_id": alice_proof_exchange_id,
"type": "indy",
"indy_presentation_spec": {
"requested_attributes": {
"THE_SPEED": {"cred_id": referent, "revealed": True}
},
"requested_predicates": {},
"self_attested_attributes": {},
},
"dif_presentation_spec": {},
},
)
await assert_both_webhooks_received(
alice_member_client,
acme_client,
"proofs",
"done",
alice_proof_exchange_id,
acme_proof_exchange_id,
)
# Check proof
proof = (
await acme_client.get(f"{VERIFIER_BASE_PATH}/proofs/{acme_proof_exchange_id}")
).json()
assert proof["verified"] is False