
This change implements Web Key Directory lookup using user's e-mail address. The target host is the same as the e-mail's domain and the local-part is hashed with SHA-1 and encoded using Z-Base32 encoding. Implemented is basic flow of version 06 of OpenPGP Web Key Directory draft [0]. It was necessary to update node-fetch package to allow returning array buffers from HTTP responses. If openpgpjs is used in the browser all keys retrieved from Web Key Directory should have `Access-Control-Allow-Origin` header set to `*` (including 404 Not found responses). [0]: https://datatracker.ietf.org/doc/draft-koch-openpgp-webkey-service/
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
|
|
|
|
const chai = require('chai');
|
|
|
|
const { expect } = chai;
|
|
|
|
describe('WKD unit tests', function() {
|
|
this.timeout(60000);
|
|
|
|
let wkd;
|
|
|
|
beforeEach(function() {
|
|
wkd = new openpgp.WKD();
|
|
});
|
|
|
|
afterEach(function() {});
|
|
|
|
describe('lookup', function() {
|
|
it('by email address should work', function() {
|
|
return wkd.lookup({
|
|
email: 'test-wkd@metacode.biz',
|
|
rawBytes: true
|
|
}).then(function(key) {
|
|
expect(key).to.exist;
|
|
expect(key).to.be.an.instanceof(Uint8Array);
|
|
});
|
|
});
|
|
|
|
it('by email address should work', function() {
|
|
return wkd.lookup({
|
|
email: 'test-wkd@metacode.biz'
|
|
}).then(function(key) {
|
|
expect(key).to.exist;
|
|
expect(key).to.have.property('keys');
|
|
expect(key.keys).to.have.lengthOf(1);
|
|
});
|
|
});
|
|
|
|
it('by email address should not find a key', function() {
|
|
return wkd.lookup({
|
|
email: 'test-wkd-does-not-exist@metacode.biz'
|
|
}).then(function(key) {
|
|
expect(key).to.be.undefined;
|
|
});
|
|
});
|
|
});
|
|
|
|
});
|