-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(identity): resolve DID from url and tests
- Loading branch information
1 parent
806a5cc
commit 8181d2b
Showing
8 changed files
with
85 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 |
---|---|---|
@@ -1,5 +1,34 @@ | ||
import { Restroom } from "@restroom-mw/core"; | ||
import { ObjectLiteral } from "@restroom-mw/types"; | ||
import { Zencode } from "@restroom-mw/zencode"; | ||
import { NextFunction, Request, Response } from "express"; | ||
import axios from "axios"; | ||
import { Action } from "./actions"; | ||
|
||
export default (req: Request, res: Response, next: NextFunction) => { | ||
const rr = new Restroom(req, res); | ||
let content: ObjectLiteral = {}; | ||
|
||
rr.onBefore( | ||
async (params: { | ||
zencode: Zencode; | ||
keys: ObjectLiteral; | ||
data: ObjectLiteral; | ||
}) => { | ||
let { zencode, keys, data } = params; | ||
content = rr.combineDataKeys(data, keys); | ||
|
||
if (zencode.match(Action.RESOLVE_DID)) { | ||
let [did, urlName, o] = zencode.paramsOf(Action.RESOLVE_DID); | ||
let url = content[urlName] | ||
if( url[-1] !== "/") { | ||
url = url + "/"; | ||
} | ||
const url_resolver = url + content[did]; | ||
const response = await axios.get(url_resolver); | ||
data[o] = response.data; | ||
} | ||
} | ||
) | ||
next(); | ||
} |
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,35 @@ | ||
import test from "ava"; | ||
import request from "supertest"; | ||
import express from "express"; | ||
import bodyParser from "body-parser"; | ||
|
||
process.env.ZENCODE_DIR = "./test/identity"; | ||
const identity = require("..").default; | ||
const zencode = require("../../core").default; | ||
|
||
test("Resolve did", | ||
async (t) => { | ||
const app = express(); | ||
app.use(bodyParser.json()); | ||
app.use(identity); | ||
app.use("/*", zencode); | ||
const res = await request(app).post("/resolve-did"); | ||
t.true( | ||
Object.keys(res.body).includes("myOutput"), | ||
'could not find "myOutput " in response' | ||
); | ||
const output = res.body.myOutput; | ||
t.true( | ||
Object.keys(output).includes("didDocument"), | ||
'could not find "didDocument" in myOutput' | ||
); | ||
t.true( | ||
Object.keys(output).includes("didDocumentMetadata"), | ||
'could not find "didDocumentMetadata" in myOutput' | ||
); | ||
t.true( | ||
Object.keys(output).includes("@context"), | ||
'could not find "@context" in myOutput' | ||
); | ||
t.is(res.status, 200); | ||
}); |
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 |
---|---|---|
|
@@ -9,5 +9,5 @@ | |
}, { | ||
"path": "../types" | ||
}], | ||
"exclude": ["node_modules", "dist", "tests"] | ||
"exclude": ["dist", "tests"] | ||
} |
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,4 @@ | ||
{ | ||
"myUrl": "https://did.dyne.org/dids", | ||
"myDid": "did:dyne:sandbox.zenswarm:HwSjX94eXVmVpqGnN6L5HD3rjSBwxJeNc9xByJKB83wB" | ||
} |
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,8 @@ | ||
Rule caller restroom-mw | ||
|
||
Given I have a 'string' named 'myDid' | ||
Given I have a 'string' named 'myUrl' | ||
Given I have a 'string dictionary' named 'myOutput' | ||
Given I resolve the did 'myDid' from 'myUrl' and save the output into 'myOutput' | ||
|
||
Then print all data |