Skip to content

Commit

Permalink
Merge pull request #95 from roots-id/coecov
Browse files Browse the repository at this point in the history
Adding code coverage
  • Loading branch information
rodolfomiranda authored Aug 24, 2023
2 parents 2ee551e + 97569e7 commit 3de6221
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/keri/app/signify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Prefixer } from "../core/prefixer"
import { Salter } from "../core/salter"
import { randomNonce } from "./apping"
import { parseRangeHeaders } from "../core/httping"
import { TextDecoder } from "util"

const DEFAULT_BOOT_URL = "http://localhost:3903"

Expand Down Expand Up @@ -1724,7 +1725,7 @@ export class Notifications {
*/
async list(start:number=0, end:number=24): Promise<any> {
let extraHeaders = new Headers()
extraHeaders.append('Range', `aids=${start}-${end}`)
extraHeaders.append('Range', `notes=${start}-${end}`)

let path = `/notifications`
let method = 'GET'
Expand Down
1 change: 1 addition & 0 deletions src/keri/core/eventing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Siger } from "./siger";
import { Cigar } from "./cigar";
import { Counter, CtrDex } from "./counter";
import { Seqner } from "./seqner";
import { TextEncoder } from "util";

let MaxIntThold = 2 ** 32 - 1

Expand Down
160 changes: 157 additions & 3 deletions test/app/signify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const mockGetAID ={
"windexes": []
}

const mockCredential = {"sad":{"v":"ACDC10JSON000197_","d":"EMwcsEMUEruPXVwPCW7zmqmN8m0I3CihxolBm-RDrsJo","i":"EMQQpnSkgfUOgWdzQTWfrgiVHKIDAhvAZIPQ6z3EAfz1","ri":"EGK216v1yguLfex4YRFnG7k1sXRjh3OKY7QqzdKsx7df","s":"EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao","a":{"d":"EK0GOjijKd8_RLYz9qDuuG29YbbXjU8yJuTQanf07b6P","i":"EKvn1M6shPLnXTb47bugVJblKMuWC0TcLIePP8p98Bby","dt":"2023-08-23T15:16:07.553000+00:00","LEI":"5493001KJTIIGC8Y1R17"}},"pre":"EMQQpnSkgfUOgWdzQTWfrgiVHKIDAhvAZIPQ6z3EAfz1","sadsigers":[{"path":"-","pre":"EMQQpnSkgfUOgWdzQTWfrgiVHKIDAhvAZIPQ6z3EAfz1","sn":0,"d":"EMQQpnSkgfUOgWdzQTWfrgiVHKIDAhvAZIPQ6z3EAfz1"}],"sadcigars":[],"chains":[],"status":{"v":"KERI10JSON000135_","i":"EMwcsEMUEruPXVwPCW7zmqmN8m0I3CihxolBm-RDrsJo","s":"0","d":"ENf3IEYwYtFmlq5ZzoI-zFzeR7E3ZNRN2YH_0KAFbdJW","ri":"EGK216v1yguLfex4YRFnG7k1sXRjh3OKY7QqzdKsx7df","ra":{},"a":{"s":2,"d":"EIpgyKVF0z0Pcn2_HgbWhEKmJhOXFeD4SA62SrxYXOLt"},"dt":"2023-08-23T15:16:07.553000+00:00","et":"iss"}}


fetchMock.mockResponse(req => {
if (req.url.startsWith(url+'/agent')) {
Expand All @@ -97,14 +99,15 @@ fetchMock.mockResponse(req => {
headers.set('Signify-Timestamp', new Date().toISOString().replace('Z', '000+00:00'))
headers.set('Content-Type', 'application/json')

const url = new URL(req.url)
const requrl = new URL(req.url)
let salter = new Salter({qb64: '0AAwMTIzNDU2Nzg5YWJjZGVm'})
let signer = salter.signer("A",true,"agentagent-ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose00",Tier.low)

let authn = new Authenticater(signer!,signer!.verfer)
signed_headers = authn.sign(headers, req.method, url.pathname.split('?')[0])
signed_headers = authn.sign(headers, req.method, requrl.pathname.split('?')[0])
let body = req.url.startsWith(url+'/identifiers/aid1/credentials')? mockCredential: mockGetAID

return Promise.resolve({body: JSON.stringify(mockGetAID), init:{ status: 202, headers:signed_headers }})
return Promise.resolve({body: JSON.stringify(body), init:{ status: 202, headers:signed_headers }})
}

})
Expand Down Expand Up @@ -239,6 +242,15 @@ describe('SignifyClient', () => {
assert.deepEqual(lastBody.rot.kt,['1','0'])
assert.equal(lastBody.rot.d,'EGFi9pCcRaLK8dPh5S7JP9Em62fBMiR1l4gW1ZazuuAO')

resp = await client.signedFetch('http://example.com','/test','POST',{foo:true},'aid1')
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
assert.equal(lastCall[0]!,'http://example.com/test')
assert.equal(lastCall[1]!.method,'POST')
lastBody = JSON.parse(lastCall[1]!.body!)
assert.deepEqual(lastBody.foo,true)
lastHeaders = new Headers((lastCall[1]!.headers!))
assert.equal(lastHeaders.get('signify-resource'),'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK')

})

it('Salty identifiers', async () => {
Expand Down Expand Up @@ -519,6 +531,72 @@ describe('SignifyClient', () => {
assert.equal(lastCall[0]!,url+'/identifiers/aid1/credentials/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao')
assert.equal(lastCall[1]!.method,'GET')

const registry = "EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX"
const schema = "EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao"
const isuee = "EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p"
await credentials.issue('aid1',registry,schema,isuee,{LEI: '1234'},{},{},false)
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
lastBody = JSON.parse(lastCall[1]!.body!.toString())
assert.equal(lastCall[0]!,url+'/identifiers/aid1/credentials')
assert.equal(lastCall[1]!.method,'POST')
assert.equal(lastBody.cred.ri,registry)
assert.equal(lastBody.cred.s,schema)
assert.equal(lastBody.cred.a.i,isuee)
assert.equal(lastBody.cred.a.LEI,'1234')
assert.equal(lastBody.iss.s,"0")
assert.equal(lastBody.iss.t,"iss")
assert.equal(lastBody.iss.ri,registry)
assert.equal(lastBody.iss.i,lastBody.cred.d)
assert.equal(lastBody.ixn.t,"ixn")
assert.equal(lastBody.ixn.i,lastBody.cred.i)
assert.equal(lastBody.ixn.p,lastBody.cred.i)
assert.equal(lastBody.path,'6AABAAA-')
assert.equal(lastBody.csigs[0].substring(0,2),'AA')
assert.equal(lastBody.csigs[0].length,88)
assert.equal(lastBody.sigs[0].substring(0,2),'AA')
assert.equal(lastBody.sigs[0].length,88)

const credential = lastBody.cred.i
await credentials.revoke('aid1',credential)
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
lastBody = JSON.parse(lastCall[1]!.body!.toString())
assert.equal(lastCall[0]!,url+'/identifiers/aid1/credentials/'+credential)
assert.equal(lastCall[1]!.method,'DELETE')
assert.equal(lastBody.rev.s,"1")
assert.equal(lastBody.rev.t,"rev")
assert.equal(lastBody.rev.ri,"EGK216v1yguLfex4YRFnG7k1sXRjh3OKY7QqzdKsx7df")
assert.equal(lastBody.rev.i,"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK")
assert.equal(lastBody.ixn.t,"ixn")
assert.equal(lastBody.ixn.i,"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK")
assert.equal(lastBody.ixn.p,"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK")
assert.equal(lastBody.sigs[0].substring(0,2),'AA')
assert.equal(lastBody.sigs[0].length,88)

await credentials.present('aid1',credential, "EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX",false)
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
lastBody = JSON.parse(lastCall[1]!.body!.toString())
assert.equal(lastCall[0]!,url+'/identifiers/aid1/credentials/'+credential+'/presentations')
assert.equal(lastCall[1]!.method,'POST')
assert.equal(lastBody.exn.t,"exn")
assert.equal(lastBody.exn.r,"/presentation")
assert.equal(lastBody.exn.a.n,"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK")
assert.equal(lastBody.exn.a.s,schema)
assert.equal(lastBody.sig.length,144)
assert.equal(lastBody.recipient,"EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX")
assert.equal(lastBody.include, false)

await credentials.request('aid1', "EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX", credential,"EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX")
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
lastBody = JSON.parse(lastCall[1]!.body!.toString())
assert.equal(lastCall[0]!,url+'/identifiers/aid1/requests')
assert.equal(lastCall[1]!.method,'POST')
assert.equal(lastBody.exn.t,"exn")
assert.equal(lastBody.exn.r,"/presentation/request")
assert.equal(lastBody.exn.a.i,registry)
assert.equal(lastBody.exn.a.s,"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK")
assert.equal(lastBody.sig.length,144)
assert.equal(lastBody.recipient,"EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX")

})

it('Contacts', async () => {
Expand Down Expand Up @@ -569,5 +647,81 @@ describe('SignifyClient', () => {
assert.equal(lastCall[1]!.method,'DELETE')

})

it('Challenges', async () => {
await libsodium.ready;
const bran = "0123456789abcdefghijk"

let client = new SignifyClient(url, bran, Tier.low, boot_url)

await client.boot()
await client.connect()

let challenges = client.challenges()


await challenges.generate(128)
let lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
assert.equal(lastCall[0]!,url+'/challenges?strength=128')
assert.equal(lastCall[1]!.method,'GET')

const words = ["shell", "gloom", "mimic", "cereal", "stool", "furnace", "nominee", "nation", "sauce", "sausage", "rather", "venue"]
await challenges.respond("aid1","EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p",words)
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
assert.equal(lastCall[0]!,url+'/challenges/aid1')
assert.equal(lastCall[1]!.method,'POST')
let lastBody = JSON.parse(lastCall[1]!.body!.toString())
assert.deepEqual(lastBody.words,words)
assert.equal(lastBody.recipient,"EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p")
assert.equal(lastBody.exn.r,"/challenge/response")
assert.equal(lastBody.exn.a.i,"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK")
assert.deepEqual(lastBody.exn.a.words,words)
assert.equal(lastBody.sig.length,144)

await challenges.accept("aid1","EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p","EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao")
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
assert.equal(lastCall[0]!,url+'/challenges/aid1')
assert.equal(lastCall[1]!.method,'PUT')
lastBody = JSON.parse(lastCall[1]!.body!.toString())
assert.equal(lastBody.aid,"EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p")
assert.equal(lastBody.said,"EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao")

})

it('Notifications', async () => {
await libsodium.ready;
const bran = "0123456789abcdefghijk"

let client = new SignifyClient(url, bran, Tier.low, boot_url)

await client.boot()
await client.connect()

let notifications = client.notifications()
let escrows = client.escrows()

await notifications.list(20, 40)
let lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
assert.equal(lastCall[0]!,url+'/notifications')
assert.equal(lastCall[1]!.method,'GET')
let lastHeaders = new Headers((lastCall[1]!.headers!))
assert.equal(lastHeaders.get('Range'),'notes=20-40')

await notifications.mark("notificationSAID")
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
assert.equal(lastCall[0]!,url+'/notifications/notificationSAID')
assert.equal(lastCall[1]!.method,'PUT')

await notifications.delete("notificationSAID")
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
assert.equal(lastCall[0]!,url+'/notifications/notificationSAID')
assert.equal(lastCall[1]!.method,'DELETE')

await escrows.listReply('/presentation/request')
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]!
assert.equal(lastCall[0]!,url+'/escrows/rpy?route=%2Fpresentation%2Frequest')
assert.equal(lastCall[1]!.method,'GET')

})

})

0 comments on commit 3de6221

Please sign in to comment.