Skip to content

Commit

Permalink
Merge branch 'main' into rtd-updates-071
Browse files Browse the repository at this point in the history
  • Loading branch information
swcurran authored Aug 23, 2021
2 parents 6938977 + a304568 commit cd1294b
Show file tree
Hide file tree
Showing 39 changed files with 174 additions and 153 deletions.
9 changes: 4 additions & 5 deletions aries_cloudagent/core/tests/test_dispatcher.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import asyncio
import json

import pytest

from asynctest import TestCase as AsyncTestCase, mock as async_mock
from marshmallow import EXCLUDE

from ...config.injection_context import InjectionContext
from ...connections.models.conn_record import ConnRecord
from ...core.event_bus import EventBus
from ...core.in_memory import InMemoryProfile
from ...core.profile import Profile
from ...core.protocol_registry import ProtocolRegistry
from ...messaging.agent_message import AgentMessage, AgentMessageSchema
from ...messaging.responder import MockResponder
from ...messaging.request_context import RequestContext
from ...messaging.util import datetime_now
from ...protocols.didcomm_prefix import DIDCommPrefix
from ...protocols.issue_credential.v2_0.message_types import CRED_20_PROBLEM_REPORT
from ...protocols.issue_credential.v2_0.messages.cred_problem_report import (
Expand Down Expand Up @@ -393,7 +391,8 @@ async def test_create_send_webhook(self):
context = RequestContext(profile)
message = StubAgentMessage()
responder = test_module.DispatcherResponder(context, message, None)
await responder.send_webhook("topic", {"pay": "load"})
with pytest.deprecated_call():
await responder.send_webhook("topic", {"pay": "load"})

async def test_create_enc_outbound(self):
profile = make_profile()
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/core/tests/test_error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio

from asynctest import TestCase as AsyncTestCase, mock as async_mock
from asynctest import TestCase as AsyncTestCase

from ..error import BaseError

Expand Down
10 changes: 6 additions & 4 deletions aries_cloudagent/resolver/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Base Class for DID Resolvers."""

import re
import warnings

from abc import ABC, abstractmethod
from enum import Enum
import re
from typing import NamedTuple, Pattern, Sequence, Union
import warnings

from pydid import DID

Expand Down Expand Up @@ -116,7 +117,8 @@ async def supports(self, profile: Profile, did: str) -> bool:
try:
supported_did_regex = self.supported_did_regex
except NotImplementedError as error:
if not self.supported_methods:
methods = self.supported_methods
if not methods:
raise error
warnings.warn(
"BaseResolver.supported_methods is deprecated; "
Expand All @@ -125,7 +127,7 @@ async def supports(self, profile: Profile, did: str) -> bool:
)

supported_did_regex = re.compile(
"^did:(?:{}):.*$".format("|".join(self.supported_methods))
"^did:(?:{}):.*$".format("|".join(methods))
)

return bool(supported_did_regex.match(did))
Expand Down
11 changes: 1 addition & 10 deletions aries_cloudagent/resolver/default/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Resolution is performed using the IndyLedger class.
"""

from typing import Sequence, Pattern
from typing import Pattern

from pydid import DID, DIDDocumentBuilder
from pydid.verification_method import Ed25519VerificationKey2018
Expand Down Expand Up @@ -34,15 +34,6 @@ def __init__(self):
async def setup(self, context: InjectionContext):
"""Perform required setup for Indy DID resolution."""

@property
def supported_methods(self) -> Sequence[str]:
"""
Return supported methods of Indy DID Resolver.
DEPRECATED: Use supported_did_regex instead.
"""
return ["sov"]

@property
def supported_did_regex(self) -> Pattern:
"""Return supported_did_regex of Indy DID Resolver."""
Expand Down
11 changes: 1 addition & 10 deletions aries_cloudagent/resolver/default/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Resolution is performed using the IndyLedger class.
"""

from typing import Sequence, Pattern
from typing import Pattern

from ...did.did_key import DIDKey
from ...config.injection_context import InjectionContext
Expand All @@ -23,15 +23,6 @@ def __init__(self):
async def setup(self, context: InjectionContext):
"""Perform required setup for Key DID resolution."""

@property
def supported_methods(self) -> Sequence[str]:
"""
Return supported methods of Key DID Resolver.
DEPRECATED: Use supported_did_regex instead.
"""
return ["key"]

@property
def supported_did_regex(self) -> Pattern:
"""Return supported_did_regex of Key DID Resolver."""
Expand Down
6 changes: 0 additions & 6 deletions aries_cloudagent/resolver/default/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ def profile(ledger):


class TestIndyResolver:
@pytest.mark.asyncio
async def test_supported_methods(self, profile, resolver: IndyDIDResolver):
"""Test the supported_methods."""
assert resolver.supported_methods == ["sov"]
assert await resolver.supports(profile, TEST_DID0)

@pytest.mark.asyncio
async def test_supported_did_regex(self, profile, resolver: IndyDIDResolver):
"""Test the supported_did_regex."""
Expand Down
10 changes: 0 additions & 10 deletions aries_cloudagent/resolver/default/tests/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ def profile():
yield profile


@pytest.mark.asyncio
async def test_supported_methods(profile, resolver: KeyDIDResolver):
"""Test the supported_methods."""
assert resolver.supported_methods == ["key"]
assert await resolver.supports(
profile,
TEST_DID0,
)


@pytest.mark.asyncio
async def test_supported_did_regex(profile, resolver: KeyDIDResolver):
"""Test the supported_did_regex."""
Expand Down
6 changes: 1 addition & 5 deletions aries_cloudagent/resolver/default/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import urllib.parse

from typing import Sequence, Pattern
from typing import Pattern

import aiohttp

Expand Down Expand Up @@ -35,10 +35,6 @@ def supported_did_regex(self) -> Pattern:
"""Return supported_did_regex of Web DID Resolver."""
return DIDWeb.PATTERN

def supported_methods(self) -> Sequence[str]:
"""Return list of supported methods."""
return ["web"]

def __transform_to_url(self, did):
"""
Transform did to url.
Expand Down
23 changes: 19 additions & 4 deletions aries_cloudagent/resolver/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ def __init__(self):
async def setup(self, context):
pass

@property
def supported_methods(self):
return ["test"]

@property
def supported_did_regex(self):
return re.compile("^did:example:[a-zA-Z0-9_.-]+$")
Expand Down Expand Up @@ -66,3 +62,22 @@ async def test_resolve_x(native_resolver):
with pytest.raises(DIDMethodNotSupported) as x_did:
await native_resolver.resolve(None, "did:nosuchmethod:xxx")
assert "does not support DID method" in str(x_did.value)


@pytest.mark.asyncio
async def test_supported_methods():
class TestDIDResolver(BaseDIDResolver):
async def setup(self, context):
pass

@property
def supported_methods(self):
return ["example"]

async def _resolve(self, profile, did) -> DIDDocument:
return DIDDocument("did:example:123")

with pytest.deprecated_call():
assert await TestDIDResolver().supports(
profile, "did:example:WgWxqztrNooG92RXvxSTWv"
)
16 changes: 11 additions & 5 deletions aries_cloudagent/resolver/tests/test_did_resolver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""Test did resolver registry."""

from typing import Pattern

import re

import pytest

from asynctest import mock as async_mock
Expand Down Expand Up @@ -64,16 +68,18 @@
class MockResolver(BaseDIDResolver):
def __init__(self, supported_methods, resolved=None, native: bool = False):
super().__init__(ResolverType.NATIVE if native else ResolverType.NON_NATIVE)
self._supported_methods = supported_methods
self._did_regex = re.compile(
"^did:(?:{}):.*$".format("|".join(supported_methods))
)
self.resolved = resolved

@property
def supported_did_regex(self) -> Pattern:
return self._did_regex

async def setup(self, context):
pass

@property
def supported_methods(self):
return self._supported_methods

async def _resolve(self, profile, did):
if isinstance(self.resolved, Exception):
raise self.resolved
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/vc/ld_proofs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .ld_proofs import sign, verify, derive
from .ProofSet import ProofSet
from .proof_set import ProofSet
from .purposes import (
ProofPurpose,
ControllerProofPurpose,
Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/vc/ld_proofs/crypto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .KeyPair import KeyPair
from .WalletKeyPair import WalletKeyPair
from .key_pair import KeyPair
from .wallet_key_pair import WalletKeyPair

__all__ = ["KeyPair", "WalletKeyPair"]
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from asynctest import TestCase
from asynctest import mock as async_mock
from asynctest import TestCase, mock as async_mock

from .....wallet.key_pair import KeyType

from ...error import LinkedDataProofException
from ..WalletKeyPair import WalletKeyPair

from ..wallet_key_pair import WalletKeyPair


class TestWalletKeyPair(TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from ....wallet.util import b58_to_bytes
from ....wallet.key_type import KeyType
from ....wallet.base import BaseWallet

from ..error import LinkedDataProofException
from .KeyPair import KeyPair

from .key_pair import KeyPair


class WalletKeyPair(KeyPair):
Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/vc/ld_proofs/ld_proofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from typing import List

from .validation_result import DocumentVerificationResult
from .document_loader import DocumentLoaderMethod
from .ProofSet import ProofSet
from .proof_set import ProofSet
from .purposes import ProofPurpose
from .suites import LinkedDataProof
from .validation_result import DocumentVerificationResult


async def sign(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""Class to represent a Linked Data proof set."""

from typing import List, Union

from pyld.jsonld import JsonLdProcessor

from .error import LinkedDataProofException
from .validation_result import DocumentVerificationResult, ProofResult
from .constants import SECURITY_CONTEXT_URL
from .document_loader import DocumentLoaderMethod
from .purposes.ProofPurpose import ProofPurpose
from .error import LinkedDataProofException
from .purposes.proof_purpose import ProofPurpose
from .suites import LinkedDataProof
from .validation_result import DocumentVerificationResult, ProofResult


class ProofSet:
Expand Down
11 changes: 6 additions & 5 deletions aries_cloudagent/vc/ld_proofs/purposes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .ProofPurpose import ProofPurpose
from .ControllerProofPurpose import ControllerProofPurpose
from .AssertionProofPurpose import AssertionProofPurpose
from .AuthenticationProofPurpose import AuthenticationProofPurpose
from .CredentialIssuancePurpose import CredentialIssuancePurpose
from .proof_purpose import ProofPurpose

from .assertion_proof_purpose import AssertionProofPurpose
from .authentication_proof_purpose import AuthenticationProofPurpose
from .controller_proof_purpose import ControllerProofPurpose
from .credential_issuance_purpose import CredentialIssuancePurpose

__all__ = [
"ProofPurpose",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from datetime import datetime, timedelta

from .ControllerProofPurpose import ControllerProofPurpose
from .controller_proof_purpose import ControllerProofPurpose


class AssertionProofPurpose(ControllerProofPurpose):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
"""Authentication proof purpose class."""

from datetime import datetime, timedelta
from typing import TYPE_CHECKING

from ..document_loader import DocumentLoaderMethod
from ..error import LinkedDataProofException
from ..validation_result import PurposeResult
from ..document_loader import DocumentLoaderMethod
from ..suites import LinkedDataProof
from .ControllerProofPurpose import ControllerProofPurpose

from .controller_proof_purpose import ControllerProofPurpose

# Avoid circular dependency
if TYPE_CHECKING:
from ..suites import LinkedDataProof


class AuthenticationProofPurpose(ControllerProofPurpose):
Expand Down Expand Up @@ -37,7 +42,7 @@ def validate(
*,
proof: dict,
document: dict,
suite: LinkedDataProof,
suite: "LinkedDataProof",
verification_method: dict,
document_loader: DocumentLoaderMethod,
) -> PurposeResult:
Expand Down
Loading

0 comments on commit cd1294b

Please sign in to comment.