Fix handling of keys with non-proof notations

This commit is contained in:
Yarmo Mackenbach 2021-06-03 11:55:08 +02:00
parent ddc80c9380
commit cd7f3dfd8d
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
2 changed files with 26 additions and 0 deletions

View file

@ -246,6 +246,10 @@ exports.process = (publicKey) => {
if ('selfCertifications' in user && user.selfCertifications.length > 0) {
const notations = user.selfCertifications[0].rawNotations
usersOutput[i].notations = notations
.filter(({ name, humanReadable }) => humanReadable && name === 'proof@metacode.biz')
.map(({ value }) => openpgp.util.decode_utf8(value))
usersOutput[i].claims = notations.map(
({ name, value, humanReadable }) => {
if (humanReadable && name === 'proof@metacode.biz') {

View file

@ -23,6 +23,7 @@ const doipjs = require('../src')
const pubKeyFingerprint = `3637202523e7c1309ab79e99ef2dc5827b445f4b`
const pubKeyEmail = `test@doip.rocks`
const pubKeyPlaintext = `-----BEGIN PGP PUBLIC KEY BLOCK-----
mQGNBF+036UBDACoxWRdp7rBAFB2l/+dxX0XA50NJC92EEacB5L0TnC0lP/MsNHv
@ -49,6 +50,19 @@ x77L7mBkREbuZpFoD/c=
=w7qB
-----END PGP PUBLIC KEY BLOCK-----`
const pubKeyWithOtherNotations = `-----BEGIN PGP PUBLIC KEY BLOCK-----
mDMEX9Mt6xYJKwYBBAHaRw8BAQdAch8jfp+8KHH5cy/t45GjPvl6dkEv2soIy9fo
Oe9DbP20EVlhcm1vJ3MgRXZpbCBUd2luiNsEExYIAIMCGwMFCwkIBwIGFQoJCAsC
BBYCAwECHgECF4AWIQTeePcduHH8EU2iM3aw5zJVrULhnwUCX9MuHBkUgAAAAAAN
AANldmlsQHlhcm1vLmV1eWVzMBSAAAAAABIAFXByb29mQG1ldGFjb2RlLmJpemRu
czp5YXJtby5ldT90eXBlPVRYVAAKCRCw5zJVrULhn4DtAQCVkyI8UxUbkxspXkWB
qUL+3uqCl9gTbNImhv/OxxJdEAEAqf8SJ9FSeAwgWhPHOidR1m+J6/qVdAJdp0HJ
Yn6RMQ8=
=Oo3X
-----END PGP PUBLIC KEY BLOCK-----`
describe('keys.fetchURI', () => {
it('should be a function (1 argument)', () => {
expect(doipjs.keys.fetchURI).to.be.a('function')
@ -124,4 +138,12 @@ describe('keys.process', () => {
'key',
])
})
it('should ignore non-proof notations', async () => {
const pubKey = await doipjs.keys.fetchPlaintext(pubKeyWithOtherNotations)
const obj = await doipjs.keys.process(pubKey)
console.log(obj.users[0]);
expect(obj.users).to.be.lengthOf(1)
expect(obj.users[0].notations).to.be.lengthOf(1)
expect(obj.users[0].notations[0]).to.be.equal('dns:yarmo.eu?type=TXT')
})
})