-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration testing for the verifier/resolver. i'll create issues for…
… the current bugs Signed-off-by: 2byrds <[email protected]>
- Loading branch information
Showing
5 changed files
with
161 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
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,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
13
volume/dkr/examples/my-scripts/keri/cf/config-local-verifier.json
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,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/" | ||
} |