Skip to content

Commit

Permalink
integration testing for the verifier/resolver. i'll create issues for…
Browse files Browse the repository at this point in the history
… the current bugs

Signed-off-by: 2byrds <[email protected]>
  • Loading branch information
2byrds committed Jan 5, 2024
1 parent 9870033 commit ef12efa
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 3 deletions.
2 changes: 1 addition & 1 deletion integration/app/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ verifier="my-verifier"
vsalt="0ABPTOtI5Qy8dCYNSs3uoCHe"
host="127.0.0.1"
caid="ELCUOZXs-0xn3jOihm0AJ-L8XTFVT8SnIpmEDhFF9Kz_"
vaid="ENdjGq0Hfxtr0tBe7TzAtS2A6Gv9wEGu7GjFKcARalUE"
vaid="EKK9_Aau-htVcu8HyAZCIUkTFMqyVB6I2LCa_GhMYWm2"

KERI_BRANCH="main"
# KERI_TAG="c3a6fc455b5fac194aa9c264e48ea2c52328d4c5"
Expand Down
2 changes: 1 addition & 1 deletion src/dkr/app/cli/commands/did/webs/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def resolve(self, tymth, tock=0.125, **opts):
kc_url = f"{base_url}/{webbing.KERI_CESR}"
print(f"Loading KERI CESR from {kc_url}", file=sys.stderr)
kc_bytes = self.loadUrl(kc_url)
print(f"Got KERI CESR: {kc_bytes.decode('utf-8')}", file=sys.stderr)
print(f"Got KERI CESR: {kc_bytes.decode('utf-8')}")
self.hby.psr.parse(ims=bytearray(kc_bytes))
print("Waiting for KERI CESR to be processed...")
yield 3.0
Expand Down
10 changes: 9 additions & 1 deletion src/dkr/core/didding.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ def generateDIDDoc(hby: habbing.Habery, did, aid, oobi=None, metadata=None, reg_
data = json.dumps(msg)
return data.encode("utf-8")

kever = hby.kevers[aid]
kever = None
if aid in hby.kevers:
kever = hby.kevers[aid]
else:
print(f"Habery does not have a kever for {did}. Did you parse the keri.cesr file?")
for kev in hby.kevers:
print("Known kevers: ", kev)
hby.kevers[aid]

vms = []
for idx, verfer in enumerate(kever.verfers):
kid = verfer.qb64
Expand Down
137 changes: 137 additions & 0 deletions tests/app/cli/commands/did/webs/test_resolve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import json

import falcon
from falcon import testing, media, http_status
from hio.base import doing

import keri
from dkr.app.cli.commands.did.webs import resolve
from hio.core import http
from keri.app import habbing, oobiing
from keri.core import coring
from keri.db import basing
from keri.end import ending
from keri.help import helping
from keri import help, kering

import os
import time

class ExampleEnd:
def on_get(self, req, rep):
"""
Handles GET requests
"""
message = "\nHello World\n\n"
rep.status = falcon.HTTP_200 # This is the default status
rep.content_type = "text/html"
rep.text = message

class DidWebsEnd:
""" Test endpoint returning a static did document """
def __init__(self, url):
self.url = url

def on_get(self, req, rep):
""" Return a did document
Args:
req (Request): Falcon request object
rep (Response): Falcon response object
"""
a = {
"urls": [
self.url
]
}

rep.status = falcon.HTTP_200
rep.content_type = "application/json"
rep.data = "{reply: '/ELCUOZXs-0xn3jOihm0AJ-L8XTFVT8SnIpmEDhFF9Kz_/did.json'}"

class KeriCesrEnd:
""" Test endpoint returning a static keri cesr file """
def __init__(self, url):
self.url = url

def on_get(self, req, rep):
""" Return a did document
Args:
req (Request): Falcon request object
rep (Response): Falcon response object
"""
a = {
"urls": [
self.url
]
}

rep.status = falcon.HTTP_200
rep.content_type = "application/json"
rep.data = "{reply: 'http://127.0.0.1:7676/ELCUOZXs-0xn3jOihm0AJ-L8XTFVT8SnIpmEDhFF9Kz_/keri.cesr'}"

def test_resolver():
with habbing.openHby(name="verifier") as hby:
hab = hby.makeHab(name="verifier")
hbyDoer = habbing.HaberyDoer(habery=hby) # setup doer
obl = oobiing.Oobiery(hby=hby)
did = "did:web:127.0.0.1%3a7676:ELCUOZXs-0xn3jOihm0AJ-L8XTFVT8SnIpmEDhFF9Kz_"
res = resolve.WebsResolver(hby,hbyDoer,obl,did,False)

# Configure the did doc and keri cesr URL
ddurl = f'http://127.0.0.1:7676/ELCUOZXs-0xn3jOihm0AJ-L8XTFVT8SnIpmEDhFF9Kz_/did.json'
kcurl = f'http://127.0.0.1:7676/ELCUOZXs-0xn3jOihm0AJ-L8XTFVT8SnIpmEDhFF9Kz_/keri.cesr'

app = falcon.App(middleware=falcon.CORSMiddleware(
allow_origins='*', allow_credentials='*',
expose_headers=['cesr-attachment', 'cesr-date', 'content-type', 'signature', 'signature-input',
'signify-resource', 'signify-timestamp']))

print("CORS enabled")
app.add_middleware(middleware=HandleCORS())
app.req_options.media_handlers.update(media.Handlers())
app.resp_options.media_handlers.update(media.Handlers())
# falcon.App instances are callable WSGI apps
example = ExampleEnd() # Resources are represented by long-lived class instances
app.add_route('/example', example)
dd = DidWebsEnd(url=ddurl)
kc = KeriCesrEnd(url=kcurl)
app.add_route(f"/did", dd)
app.add_route(f"/cesr", kc)

server = http.Server(host="127.0.0.1",port=7676, app=app, scheme="http")
httpServerDoer = http.ServerDoer(server=server)

client = testing.TestClient(app=app)

rep = client.simulate_get('/example')
assert rep.status == falcon.HTTP_OK
assert rep.text == '\nHello World\n\n'

limit = 2.0
tock = 0.03125
doers = [httpServerDoer]
doist = doing.Doist(limit=limit, tock=tock)
doist.do(doers=doers)

assert doist.limit == limit

# obr = hby.db.roobi.get(keys=(kcurl,))
# assert obr is not None
# assert obr.state == oobiing.Result.resolved
# time.sleep(20)
# doist.exit()

"""Done Test"""

class HandleCORS(object):
def process_request(self, req, resp):
resp.set_header('Access-Control-Allow-Origin', '*')
resp.set_header('Access-Control-Allow-Methods', '*')
resp.set_header('Access-Control-Allow-Headers', '*')
resp.set_header('Access-Control-Max-Age', 1728000) # 20 days
if req.method == 'OPTIONS':
raise http_status.HTTPStatus(falcon.HTTP_200, text='\n')
13 changes: 13 additions & 0 deletions volume/dkr/examples/my-scripts/keri/cf/config-local-verifier.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"dt": "2022-01-20T12:57:59.823350+00:00",
"iurls": [
"http://127.0.0.1:5642/oobi/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha/controller",
"http://127.0.0.1:5644/oobi/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX/controller",
"http://127.0.0.1:5643/oobi/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM/controller"
],
"durls": [
"https://weboftrust.github.io/oobi/EN6Oh5XSD5_q2Hgu-aqpdfbVepdpYpFlgz6zvJL5b_r5"
],
"keri.cesr.dir": "./volume/dkr/pages/",
"did.doc.dir": "./volume/dkr/pages/"
}

0 comments on commit ef12efa

Please sign in to comment.