Ejemplo n.º 1
0
 async def dereference(self, profile: Profile,
                       did_url: str) -> Union[Service, VerificationMethod]:
     """Dereference a DID URL to its corresponding DID Doc object."""
     # TODO Use cached DID Docs when possible
     try:
         did_url = DIDUrl.parse(did_url)
         doc = await self.resolve(profile, did_url.did)
         return doc.dereference(did_url)
     except DIDError as err:
         raise ResolverError(
             "Failed to parse DID URL from {}".format(did_url)) from err
Ejemplo n.º 2
0
 async def dereference(self, profile: Profile, did_url: str) -> Resource:
     """Dereference a DID URL to its corresponding DID Doc object."""
     # TODO Use cached DID Docs when possible
     try:
         parsed = DIDUrl.parse(did_url)
         if not parsed.did:
             raise ValueError("Invalid DID URL")
         doc_dict = await self.resolve(profile, parsed.did)
         return pydid.deserialize_document(doc_dict).dereference(parsed)
     except DIDError as err:
         raise ResolverError(
             "Failed to parse DID URL from {}".format(did_url)) from err
Ejemplo n.º 3
0
    async def dereference(self,
                          profile: Profile,
                          did_url: str,
                          *,
                          cls: Type[ResourceType] = Resource) -> ResourceType:
        """Dereference a DID URL to its corresponding DID Doc object."""
        # TODO Use cached DID Docs when possible
        try:
            parsed = DIDUrl.parse(did_url)
            if not parsed.did:
                raise ValueError("Invalid DID URL")
        except DIDError as err:
            raise ResolverError(
                "Failed to parse DID URL from {}".format(did_url)) from err

        doc_dict = await self.resolve(profile, parsed.did)
        # Use non-conformant doc as the "least common denominator"
        try:
            return NonconformantDocument.deserialize(doc_dict).dereference_as(
                cls, parsed)
        except IDNotFoundError as error:
            raise ResolverError(
                "Failed to dereference DID URL: {}".format(error)) from error
Ejemplo n.º 4
0
def test_url_method(did, parts):
    did = DID(did)
    assert did.url(parts.get("path"), parts.get("query"),
                   parts.get("fragment")) == DIDUrl(**parts)
Ejemplo n.º 5
0
def test_relative_url():
    url = DIDUrl.parse("/some/path?query=value#fragment")
    assert not url.did
    assert url.path
    assert url.query
    assert url.fragment
Ejemplo n.º 6
0
def test_partial_match_url():
    assert not DIDUrl.is_valid("did:bad:char'@='acters:example:1234abcd#4")
Ejemplo n.º 7
0
def test_is_valid_x(bad_url):
    assert not DIDUrl.is_valid(bad_url)
Ejemplo n.º 8
0
def test_is_valid(url):
    assert DIDUrl.is_valid(url)
Ejemplo n.º 9
0
def test_as_str(parts, url):
    assert DIDUrl.unparse(**parts) == url
Ejemplo n.º 10
0
def test_did_url_parse_x(bad_url):
    with pytest.raises(InvalidDIDUrlError):
        DIDUrl(bad_url)
Ejemplo n.º 11
0
def test_did_url_neq(lhs, rhs):
    lhs = DIDUrl(lhs)
    assert lhs != rhs
    rhs = DIDUrl(rhs)
    assert lhs != rhs
    assert lhs != {"not a": "DIDUrl"}
Ejemplo n.º 12
0
def test_did_url(url, parts):
    assert DIDUrl(url) == DIDUrl.unparse(**parts)
Ejemplo n.º 13
0
def test_did_url_from_parts(inputs, output):
    url = DIDUrl.unparse(**inputs)
    assert url == output
    assert repr(url)
Ejemplo n.º 14
0
def test_did_url_parse(url, parts):
    assert DIDUrl.parse(url) == DIDUrl(**parts)
Ejemplo n.º 15
0
def test_did_url(inputs, output):
    url = DIDUrl(**inputs)
    assert str(url) == output
    assert repr(url)