Skip to content

Commit

Permalink
add tests for did seed generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jchartrand committed Sep 12, 2024
1 parent 74c87d3 commit dbb1b1e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import unProtectedRandomWalletQuery from './test-fixtures/nocks/unProtectedRando
import vprTestNocks from './test-fixtures/nocks/vprTest.js'
import unknownStatusListNock from './test-fixtures/nocks/unknown_status_list_nock.js'
import statusListNock from './test-fixtures/nocks/status_list_nock.js'

import didWebGeneratorNock from './test-fixtures/nocks/did-web-generator.js'
import unprotectedStatusUpdateNock from './test-fixtures/nocks/unprotected_status_update.js'
import unknownStatusIdNock from './test-fixtures/nocks/unknown_status_id_nock.js'
import protectedStatusUpdateNock from './test-fixtures/nocks/protected_status_update.js'
import didKeyGeneratorNock from './test-fixtures/nocks/did-key-generator.js'

import { getSignedDIDAuth } from './didAuth.js';

Expand Down Expand Up @@ -462,4 +462,42 @@ describe('api', () => {
expect(returnedList.proof.proofValue).to.equal('z4y3GawinQg1aCqbYqZM8dmDpbmtFa3kE6tFefdXvLi5iby25dvmVwLNZrfcFPyhpshrhCWB76pdSZchVve3K1Znr')
})
})

describe('/did-web-generator', () => {
it('returns a new did:web', async () => {
didWebGeneratorNock()
await request(app)
.post(`/did-web-generator`)
.send({
url: 'https://raw.githubusercontent.com/jchartrand/didWebTest/main'
})
.expect('Content-Type', /json/)
.expect((res) => {
expect(res.body.seed).to.exist
expect(res.body.didDocument.id).to.eql(
'did:web:raw.githubusercontent.com:jchartrand:didWebTest:main'
)
expect(res.body.did).to.eql(
'did:web:raw.githubusercontent.com:jchartrand:didWebTest:main'
)
})
.expect(200)
})
})

describe('/did-key-generator', () => {
it('returns a new did:key', async () => {
didKeyGeneratorNock()
await request(app)
.get(`/did-key-generator`)
.expect('Content-Type', /json/)
.expect((res) => {
expect(res.body.seed).to.exist
expect(res.body.didDocument.id).to.contain('did:key')
expect(res.body.did).to.contain('did:key')
})
.expect(200)
})
})

})
25 changes: 25 additions & 0 deletions src/test-fixtures/nocks/did-key-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import nock from 'nock'

export default () => {

nock('http://localhost:4006', {"encodedQueryParams":true})
.get('/did-key-generator')
.reply(200, {"seed":"z1Ak67saZZnW6e41kw8dFNgWPQC7kb4MgmKrB5Saj9fTQtR","decodedSeed":{"0":204,"1":42,"2":201,"3":165,"4":122,"5":6,"6":144,"7":61,"8":229,"9":222,"10":134,"11":94,"12":219,"13":6,"14":191,"15":210,"16":103,"17":71,"18":241,"19":109,"20":215,"21":216,"22":2,"23":72,"24":19,"25":144,"26":20,"27":32,"28":178,"29":172,"30":81,"31":82},"did":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","didDocument":{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/suites/ed25519-2020/v1","https://w3id.org/security/suites/x25519-2020/v1"],"id":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","verificationMethod":[{"id":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","type":"Ed25519VerificationKey2020","controller":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","publicKeyMultibase":"z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"}],"authentication":["did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"],"assertionMethod":["did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"],"capabilityDelegation":["did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"],"capabilityInvocation":["did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"],"keyAgreement":[{"id":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6LScqycbURGxJztJiSkK6MKZJhujV7PygbA2BHexuriMAdr","type":"X25519KeyAgreementKey2020","controller":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","publicKeyMultibase":"z6LScqycbURGxJztJiSkK6MKZJhujV7PygbA2BHexuriMAdr"}]}}, [
'X-Powered-By',
'Express',
'Access-Control-Allow-Origin',
'*',
'Content-Type',
'application/json; charset=utf-8',
'Content-Length',
'1776',
'ETag',
'W/"6f0-JdoCppKv4nbnXnQDbZJxlFrXG7o"',
'Date',
'Mon, 09 Sep 2024 18:06:31 GMT',
'Connection',
'keep-alive',
'Keep-Alive',
'timeout=5'
]);
}
25 changes: 25 additions & 0 deletions src/test-fixtures/nocks/did-web-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import nock from 'nock'

export default () => {

nock('http://localhost:4006', {"encodedQueryParams":true})
.post('/did-web-generator', {"url":"https://raw.githubusercontent.com/jchartrand/didWebTest/main"})
.reply(200, {"seed":"z1AhHNg9RSiUrjKAeTLXeYjJG5xE4fyZsxfFwKkXM4PhPMn","decodedSeed":{"0":162,"1":121,"2":218,"3":124,"4":128,"5":83,"6":6,"7":120,"8":155,"9":52,"10":67,"11":214,"12":9,"13":96,"14":98,"15":108,"16":249,"17":187,"18":45,"19":240,"20":184,"21":177,"22":120,"23":176,"24":189,"25":125,"26":247,"27":38,"28":7,"29":64,"30":91,"31":77},"did":"did:web:raw.githubusercontent.com:jchartrand:didWebTest:main","didDocument":{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/suites/ed25519-2020/v1","https://w3id.org/security/suites/x25519-2020/v1"],"id":"did:web:raw.githubusercontent.com:jchartrand:didWebTest:main","assertionMethod":[{"id":"did:web:raw.githubusercontent.com:jchartrand:didWebTest:main#z6Mkoy5dFU7xajPV2QGEif1cz43To6go9Yhtf1T39TXCSMrS","type":"Ed25519VerificationKey2020","controller":"did:web:raw.githubusercontent.com:jchartrand:didWebTest:main","publicKeyMultibase":"z6Mkoy5dFU7xajPV2QGEif1cz43To6go9Yhtf1T39TXCSMrS"}]}}, [
'X-Powered-By',
'Express',
'Access-Control-Allow-Origin',
'*',
'Content-Type',
'application/json; charset=utf-8',
'Content-Length',
'957',
'ETag',
'W/"3bd-+yFc27zaIMTPRG+dm/pWiYDTumc"',
'Date',
'Mon, 09 Sep 2024 17:55:01 GMT',
'Connection',
'keep-alive',
'Keep-Alive',
'timeout=5'
]);
}

0 comments on commit dbb1b1e

Please sign in to comment.