From 2c3358aa49948d047981d410e4fb03339a413d27 Mon Sep 17 00:00:00 2001 From: James Chartrand Date: Mon, 9 Sep 2024 17:34:24 -0400 Subject: [PATCH] add did generator tests --- src/app.test.js | 41 ++++++++++++++++++++ src/test-fixtures/nocks/did-key-generator.js | 25 ++++++++++++ src/test-fixtures/nocks/did-web-generator.js | 25 ++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/test-fixtures/nocks/did-key-generator.js create mode 100644 src/test-fixtures/nocks/did-web-generator.js diff --git a/src/app.test.js b/src/app.test.js index 5f0c2eb..982aaf3 100644 --- a/src/app.test.js +++ b/src/app.test.js @@ -9,6 +9,9 @@ import unknownStatusIdNock from './test-fixtures/nocks/unknown_status_id_nock.js import protectedStatusUpdateNock from './test-fixtures/nocks/protected_status_update.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 didKeyGeneratorNock from './test-fixtures/nocks/did-key-generator.js' + import { build } from './app.js' @@ -250,4 +253,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) + }) + }) + }) diff --git a/src/test-fixtures/nocks/did-key-generator.js b/src/test-fixtures/nocks/did-key-generator.js new file mode 100644 index 0000000..dd296cb --- /dev/null +++ b/src/test-fixtures/nocks/did-key-generator.js @@ -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' +]); +} diff --git a/src/test-fixtures/nocks/did-web-generator.js b/src/test-fixtures/nocks/did-web-generator.js new file mode 100644 index 0000000..142ef22 --- /dev/null +++ b/src/test-fixtures/nocks/did-web-generator.js @@ -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' +]); +}