forked from hyperledger/aries-acapy-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daniel Bluhm <[email protected]>
- Loading branch information
Showing
7 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from aries_cloudagent.admin.request_context import AdminRequestContext | ||
import pytest | ||
from unittest.mock import MagicMock | ||
|
||
|
||
@pytest.fixture | ||
def context(): | ||
"""Test AdminRequestContext.""" | ||
yield AdminRequestContext.test_context() | ||
|
||
|
||
@pytest.fixture | ||
def req(context: AdminRequestContext): | ||
"""Test web.Request.""" | ||
items = {"context": context} | ||
mock = MagicMock() | ||
mock.__getitem__ = lambda _, k: items[k] | ||
yield mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from aiohttp import web | ||
from unittest.mock import AsyncMock | ||
from aries_cloudagent.admin.request_context import AdminRequestContext | ||
from oid4vci.v1_0 import routes as test_module | ||
import pytest | ||
|
||
from oid4vci.v1_0.models.supported_cred import SupportedCredential | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_credential_supported_create( | ||
context: AdminRequestContext, req: web.Request | ||
): | ||
"""Test credential_supported_create endpoint.""" | ||
req.json = AsyncMock( | ||
return_value={ | ||
"format": "jwt_vc_json", | ||
"id": "MyCredential", | ||
"credentialSubject": {"name": "alice"}, | ||
"type": ["VerifiableCredential", "MyCredential"], | ||
"cryptographic_binding_methods_supported": ["proof"], | ||
"cryptographic_suites_supported": ["ES256"], | ||
"display": {"some nonsense": "here"}, | ||
} | ||
) | ||
|
||
await test_module.credential_supported_create(req) | ||
|
||
async with context.session() as session: | ||
records = await SupportedCredential.query( | ||
session, {"identifier": "MyCredential"} | ||
) | ||
|
||
assert records | ||
record = records[0] | ||
assert record | ||
assert record.format == "jwt_vc_json" | ||
assert record.identifier == "MyCredential" | ||
assert record.format_data == { | ||
"credentialSubject": {"name": "alice"}, | ||
"type": ["VerifiableCredential", "MyCredential"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from unittest.mock import patch | ||
|
||
from aiohttp import web | ||
from aries_cloudagent.admin.request_context import AdminRequestContext | ||
import pytest | ||
|
||
from oid4vci.v1_0 import public_routes as test_module | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_issuer_metadata(context: AdminRequestContext, req: web.Request): | ||
"""Test issuer metadata endpoint.""" | ||
supported = test_module.SupportedCredential( | ||
format="jwt_vc_json", | ||
identifier="MyCredential", | ||
format_data={ | ||
"credentialSubject": {"name": "alice"}, | ||
}, | ||
) | ||
|
||
async with context.session() as session: | ||
await supported.save(session) | ||
|
||
with patch.object( | ||
test_module, "OID4VCI_ENDPOINT", "http://localhost:8020" | ||
), patch.object(test_module, "web", autospec=True) as mock_web: | ||
await test_module.oid_cred_issuer(req) | ||
mock_web.json_response.assert_called_once_with( | ||
{ | ||
"credential_issuer": "http://localhost:8020/", | ||
"credential_endpoint": "http://localhost:8020/credential", | ||
"credentials_supported": [ | ||
{ | ||
"format": "jwt_vc_json", | ||
"id": "MyCredential", | ||
"credentialSubject": {"name": "alice"}, | ||
} | ||
], | ||
} | ||
) |