Skip to content

Commit

Permalink
Merge pull request #734 from sklump/finesse-revocation-method-for-con…
Browse files Browse the repository at this point in the history
…sistency

Move parameters for credential revocation to request body for automated test consistency
  • Loading branch information
andrewwhitehead authored Oct 2, 2020
2 parents fced567 + f3548d4 commit 68d888a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 65 deletions.
17 changes: 9 additions & 8 deletions aries_cloudagent/revocation/routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Revocation registry admin routes."""

import json
import logging

from asyncio import shield
Expand Down Expand Up @@ -107,13 +106,13 @@ def validate_fields(self, data, **kwargs):
)


class RevokeQueryStringSchema(CredRevRecordQueryStringSchema):
class RevokeRequestSchema(CredRevRecordQueryStringSchema):
"""Parameters and validators for revocation request."""

publish = fields.Boolean(
description=(
"(True) publish revocation to ledger immediately, or "
"(False) mark it pending (default value)"
"(default, False) mark it pending"
),
required=False,
)
Expand Down Expand Up @@ -249,7 +248,7 @@ class CredDefIdMatchInfoSchema(OpenAPISchema):
tags=["revocation"],
summary="Revoke an issued credential",
)
@querystring_schema(RevokeQueryStringSchema())
@request_schema(RevokeRequestSchema())
async def revoke(request: web.BaseRequest):
"""
Request handler for storing a credential request.
Expand All @@ -263,10 +262,12 @@ async def revoke(request: web.BaseRequest):
"""
context = request.app["request_context"]

rev_reg_id = request.query.get("rev_reg_id")
cred_rev_id = request.query.get("cred_rev_id") # numeric str, which indy wants
cred_ex_id = request.query.get("cred_ex_id")
publish = bool(json.loads(request.query.get("publish", json.dumps(False))))
body = await request.json()

rev_reg_id = body.get("rev_reg_id")
cred_rev_id = body.get("cred_rev_id") # numeric str, which indy wants
cred_ex_id = body.get("cred_ex_id")
publish = body.get("publish")

rev_manager = RevocationManager(context)
try:
Expand Down
101 changes: 52 additions & 49 deletions aries_cloudagent/revocation/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def setUp(self):
}
self.test_did = "sample-did"

async def test_validate_cred_rev_rec_and_revoke_query_strings(self):
async def test_validate_cred_rev_rec_qs_and_revoke_req(self):
for req in (
test_module.CredRevRecordQueryStringSchema(),
test_module.RevokeQueryStringSchema(),
test_module.RevokeRequestSchema(),
):
req.validate_fields(
{
Expand Down Expand Up @@ -78,19 +78,20 @@ async def test_validate_cred_rev_rec_and_revoke_query_strings(self):
)

async def test_revoke(self):
mock = async_mock.MagicMock(
query={
request = async_mock.MagicMock()
request.app = {
"request_context": async_mock.patch.object(
aio_web, "BaseRequest", autospec=True
),
}
request.app["request_context"].settings = {}
request.json = async_mock.CoroutineMock(
return_value={
"rev_reg_id": "rr_id",
"cred_rev_id": "23",
"publish": "false",
}
)
mock.app = {
"request_context": async_mock.patch.object(
aio_web, "BaseRequest", autospec=True
),
}
mock.app["request_context"].settings = {}

with async_mock.patch.object(
test_module, "RevocationManager", autospec=True
Expand All @@ -100,23 +101,24 @@ async def test_revoke(self):

mock_mgr.return_value.revoke_credential = async_mock.CoroutineMock()

await test_module.revoke(mock)
await test_module.revoke(request)

mock_response.assert_called_once_with({})

async def test_revoke_by_cred_ex_id(self):
mock = async_mock.MagicMock(
query={
"cred_ex_id": "dummy-cxid",
"publish": "false",
}
)
mock.app = {
request = async_mock.MagicMock()
request.app = {
"request_context": async_mock.patch.object(
aio_web, "BaseRequest", autospec=True
),
}
mock.app["request_context"].settings = {}
request.app["request_context"].settings = {}
request.json = async_mock.CoroutineMock(
return_value={
"cred_ex_id": "dummy-cxid",
"publish": "false",
}
)

with async_mock.patch.object(
test_module, "RevocationManager", autospec=True
Expand All @@ -126,24 +128,25 @@ async def test_revoke_by_cred_ex_id(self):

mock_mgr.return_value.revoke_credential = async_mock.CoroutineMock()

await test_module.revoke(mock)
await test_module.revoke(request)

mock_response.assert_called_once_with({})

async def test_revoke_not_found(self):
mock = async_mock.MagicMock(
query={
request = async_mock.MagicMock()
request.app = {
"request_context": async_mock.patch.object(
aio_web, "BaseRequest", autospec=True
),
}
request.app["request_context"].settings = {}
request.json = async_mock.CoroutineMock(
return_value={
"rev_reg_id": "rr_id",
"cred_rev_id": "23",
"publish": "false",
}
)
mock.app = {
"request_context": async_mock.patch.object(
aio_web, "BaseRequest", autospec=True
),
}
mock.app["request_context"].settings = {}

with async_mock.patch.object(
test_module, "RevocationManager", autospec=True
Expand All @@ -156,17 +159,17 @@ async def test_revoke_not_found(self):
)

with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.revoke(mock)
await test_module.revoke(request)

async def test_publish_revocations(self):
mock = async_mock.MagicMock()
mock.app = {
request = async_mock.MagicMock()
request.app = {
"request_context": async_mock.patch.object(
aio_web, "BaseRequest", autospec=True
),
}
mock.app["request_context"].settings = {}
mock.json = async_mock.CoroutineMock()
request.app["request_context"].settings = {}
request.json = async_mock.CoroutineMock()

with async_mock.patch.object(
test_module, "RevocationManager", autospec=True
Expand All @@ -176,21 +179,21 @@ async def test_publish_revocations(self):
pub_pending = async_mock.CoroutineMock()
mock_mgr.return_value.publish_pending_revocations = pub_pending

await test_module.publish_revocations(mock)
await test_module.publish_revocations(request)

mock_response.assert_called_once_with(
{"rrid2crid": pub_pending.return_value}
)

async def test_publish_revocations_x(self):
mock = async_mock.MagicMock()
mock.app = {
request = async_mock.MagicMock()
request.app = {
"request_context": async_mock.patch.object(
aio_web, "BaseRequest", autospec=True
),
}
mock.app["request_context"].settings = {}
mock.json = async_mock.CoroutineMock()
request.app["request_context"].settings = {}
request.json = async_mock.CoroutineMock()

with async_mock.patch.object(
test_module, "RevocationManager", autospec=True
Expand All @@ -201,17 +204,17 @@ async def test_publish_revocations_x(self):
mock_mgr.return_value.publish_pending_revocations = pub_pending

with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.publish_revocations(mock)
await test_module.publish_revocations(request)

async def test_clear_pending_revocations(self):
mock = async_mock.MagicMock()
mock.app = {
request = async_mock.MagicMock()
request.app = {
"request_context": async_mock.patch.object(
aio_web, "BaseRequest", autospec=True
),
}
mock.app["request_context"].settings = {}
mock.json = async_mock.CoroutineMock()
request.app["request_context"].settings = {}
request.json = async_mock.CoroutineMock()

with async_mock.patch.object(
test_module, "RevocationManager", autospec=True
Expand All @@ -221,21 +224,21 @@ async def test_clear_pending_revocations(self):
clear_pending = async_mock.CoroutineMock()
mock_mgr.return_value.clear_pending_revocations = clear_pending

await test_module.clear_pending_revocations(mock)
await test_module.clear_pending_revocations(request)

mock_response.assert_called_once_with(
{"rrid2crid": clear_pending.return_value}
)

async def test_clear_pending_revocations_x(self):
mock = async_mock.MagicMock()
mock.app = {
request = async_mock.MagicMock()
request.app = {
"request_context": async_mock.patch.object(
aio_web, "BaseRequest", autospec=True
),
}
mock.app["request_context"].settings = {}
mock.json = async_mock.CoroutineMock()
request.app["request_context"].settings = {}
request.json = async_mock.CoroutineMock()

with async_mock.patch.object(
test_module, "RevocationManager", autospec=True
Expand All @@ -248,7 +251,7 @@ async def test_clear_pending_revocations_x(self):
mock_mgr.return_value.clear_pending_revocations = clear_pending

with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.clear_pending_revocations(mock)
await test_module.clear_pending_revocations(request)

async def test_create_rev_reg(self):
CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default"
Expand Down
17 changes: 9 additions & 8 deletions demo/runners/faber.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,17 @@ async def main(
elif option == "4" and revocation:
rev_reg_id = (await prompt("Enter revocation registry ID: ")).strip()
cred_rev_id = (await prompt("Enter credential revocation ID: ")).strip()
publish = json.dumps(
(await prompt("Publish now? [Y/N]: ", default="N")).strip()
in ("yY")
)
publish = (
await prompt("Publish now? [Y/N]: ", default="N")
).strip() in "yY"
try:
await agent.admin_POST(
"/revocation/revoke"
f"?publish={publish}"
f"&rev_reg_id={rev_reg_id}"
f"&cred_rev_id={cred_rev_id}"
"/revocation/revoke",
{
"rev_reg_id": rev_reg_id,
"cred_rev_id": cred_rev_id,
"publish": publish,
},
)
except ClientError:
pass
Expand Down

0 comments on commit 68d888a

Please sign in to comment.