Skip to content
Snippets Groups Projects
Commit 9c5ed99f authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix #387 Lookup identities are not grouped by pubkey

parent 5201c779
No related branches found
No related tags found
No related merge requests found
...@@ -21,9 +21,13 @@ function WOTBinding (server) { ...@@ -21,9 +21,13 @@ function WOTBinding (server) {
const Identity = require('../lib/entity/identity'); const Identity = require('../lib/entity/identity');
this.lookup = (req) => co(function *() { this.lookup = (req) => co(function *() {
// Get the search parameter from HTTP query
const search = yield ParametersService.getSearchP(req); const search = yield ParametersService.getSearchP(req);
// Make the research
const identities = yield IdentityService.searchIdentities(search); const identities = yield IdentityService.searchIdentities(search);
// Entitify each result
identities.forEach((idty, index) => identities[index] = new Identity(idty)); identities.forEach((idty, index) => identities[index] = new Identity(idty));
// Prepare some data to avoid displaying expired certifications
const excluding = yield BlockchainService.getCertificationsExludingBlock(); const excluding = yield BlockchainService.getCertificationsExludingBlock();
for (const idty of identities) { for (const idty of identities) {
const certs = yield server.dal.certsToTarget(idty.getTargetHash()); const certs = yield server.dal.certsToTarget(idty.getTargetHash());
...@@ -60,17 +64,27 @@ function WOTBinding (server) { ...@@ -60,17 +64,27 @@ function WOTBinding (server) {
} }
idty.signed = validSigned; idty.signed = validSigned;
} }
const json = {
partial: false,
results: []
};
if (identities.length == 0) { if (identities.length == 0) {
throw constants.ERRORS.NO_MATCHING_IDENTITY; throw constants.ERRORS.NO_MATCHING_IDENTITY;
} }
identities.forEach(function(identity){ const resultsByPubkey = {};
json.results.push(identity.json()); identities.forEach((identity) => {
const jsoned = identity.json();
if (!resultsByPubkey[jsoned.pubkey]) {
// Create the first matching identity with this pubkey in the map
resultsByPubkey[jsoned.pubkey] = jsoned;
} else {
// Merge the identity with the existing(s)
const existing = resultsByPubkey[jsoned.pubkey];
// We add the UID of the identity to the list of already added UIDs
existing.uids = existing.uids.concat(jsoned.uids);
// We do not merge the `signed`: every identity with the same pubkey has the same `signed` because it the *pubkey* which signs, not the identity
}
}); });
return json; return {
partial: false,
results: Object.values(resultsByPubkey)
};
}); });
this.members = () => co(function *() { this.members = () => co(function *() {
......
"use strict";
const co = require('co');
const should = require('should');
const bma = require('../../app/lib/streams/bma');
const user = require('./tools/user');
const commit = require('./tools/commit');
const until = require('./tools/until');
const toolbox = require('./tools/toolbox');
const multicaster = require('../../app/lib/streams/multicaster');
const s1 = toolbox.server({
pair: {
pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'
}
});
const cat1 = user('cat1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 });
const cat2 = user('cat2', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 });
const catb = user('cat1', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 });
describe("Identities with shared pubkey", function() {
before(() => co(function*() {
yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections());
yield cat2.createIdentity();
// Early certification, to have only one matching 'HgTT' key at this moment
yield catb.cert(cat2);
// catb gets certified by 'HgTT'
yield cat1.createIdentity();
yield catb.createIdentity();
yield cat1.cert(catb);
}));
it('should exit 2 pubkey result', () => s1.expect('/wot/lookup/cat', (res) => {
console.log(JSON.stringify(res, null, ' '));
res.results.should.have.length(2);
res.results[0].should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
res.results[1].should.have.property('pubkey').equal('2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc');
}));
it('pubkey HgTT should have signed 1 key', () => s1.expect('/wot/lookup/cat', (res) => {
res.results.should.have.length(2);
res.results[0].should.have.property('signed').length(1);
const pubkey_hgtt = res.results[0];
const pubkey_2lvd = res.results[1];
const cat2idty = pubkey_hgtt.uids[0];
const cat1idty = pubkey_hgtt.uids[1];
const catbidty = pubkey_2lvd.uids[0];
cat1idty.should.have.property('uid').equal('cat1');
cat1idty.should.have.property('others').length(0); // Has not been certified
cat2idty.should.have.property('uid').equal('cat2');
cat2idty.should.have.property('others').length(1);
// Certified by 2LvD
cat2idty.others[0].should.have.property('pubkey').equal('2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc');
catbidty.should.have.property('others').length(1);
pubkey_2lvd.should.have.property('signed').length(1);
// Certified by 2LvD
catbidty.others[0].should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
}));
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment