From d752c1cdddc8c2e8d851f3c73aac773d2c321887 Mon Sep 17 00:00:00 2001 From: cgeek <cem.moreau@gmail.com> Date: Fri, 10 Nov 2017 09:03:18 +0100 Subject: [PATCH] [fix] #1190 Revoked identity inclusion in a block [test] --- test/integration/revoked_pubkey_replay.ts | 68 +++++++++++++++++++++++ test/integration/tools/toolbox.ts | 4 +- test/integration/tools/user.js | 10 ++-- 3 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 test/integration/revoked_pubkey_replay.ts diff --git a/test/integration/revoked_pubkey_replay.ts b/test/integration/revoked_pubkey_replay.ts new file mode 100644 index 000000000..dbaddc9a2 --- /dev/null +++ b/test/integration/revoked_pubkey_replay.ts @@ -0,0 +1,68 @@ +import {simpleNodeWith2Users, TestingServer} from "./tools/toolbox" + +const _ = require('underscore') +const user = require('./tools/user') + +describe("Revoked pubkey replay", function() { + + const now = 1500000000 + const DONT_WAIT_FOR_BLOCKCHAIN_CHANGE = true + let s1:TestingServer, cat:any, tic:any + + const conf = { nbCores: 1, sigQty: 1 } + + before(async () => { + const res1 = await simpleNodeWith2Users(conf) + s1 = res1.s1 + cat = res1.cat + tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }) + await s1.commit({ time: now }) + await s1.commit({ time: now }) + // Create the tested identity « tic » + await tic.createIdentity() + }) + + it('should exist tic as pending identity', () => s1.expect('/wot/lookup/tic', (res:any) => { + res.should.have.property('results').length(1) + res.results[0].should.have.property('uids').length(1) + res.results[0].uids[0].should.have.property('uid').equal('tic') + })) + + it('should be able to make tic become a member', async () => { + await tic.join() + await cat.cert(tic) + await s1.commit() + await s1.expect('/wot/members', (res:any) => { + res.should.have.property('results').length(3) + const ticEntries = _.filter(res.results, (entry:any) => entry.uid === 'tic') + ticEntries.should.have.length(1) + }) + }) + + it('should be able to revoke tic', async () => { + await tic.revoke() + await s1.expect('/wot/lookup/tic', (res:any) => { + res.should.have.property('results').length(1) + res.results[0].should.have.property('uids').length(1) + res.results[0].uids[0].should.have.property('uid').equal('tic') + res.results[0].uids[0].should.have.property('revocation_sig').not.equal(null) + }) + await s1.commit() + await s1.expect('/wot/members', (res:any) => { + res.should.have.property('results').length(2) + const ticEntries = _.filter(res.results, (entry:any) => entry.uid === 'tic') + ticEntries.should.have.length(0) + }) + }) + + it('should not try to include tic2 in a new block', async () => { + await s1.commit() + await tic.join() + const block = await s1.commit(null, DONT_WAIT_FOR_BLOCKCHAIN_CHANGE) + block.should.have.property('joiners').length(0) + }) + + after(async () => { + await s1.closeCluster() + }) +}) diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index cbbe1d156..0bb986b75 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -476,8 +476,8 @@ export class TestingServer { return until(this.server, type, count); } - async commit(options:any = null) { - const raw = await commit(this.server)(options); + async commit(options:any = null, noWait = false) { + const raw = await commit(this.server, null, noWait)(options); return JSON.parse(raw); } diff --git a/test/integration/tools/user.js b/test/integration/tools/user.js index 9e82326e7..1f910f88e 100644 --- a/test/integration/tools/user.js +++ b/test/integration/tools/user.js @@ -26,6 +26,7 @@ function User (uid, options, node) { var pub, sec; var createdIdentity = ""; that.node = node; + that.uid = uid // For sync code if (options.pub && options.sec) { @@ -68,7 +69,7 @@ function User (uid, options, node) { this.makeCert = (user, fromServer, overrideProps) => co(function*() { const lookup = yield that.lookup(user.pub, fromServer); const current = yield node.server.BlockchainService.current(); - const idty = lookup.results[0].uids[0]; + const idty = _.filter(lookup.results[0].uids, (uidEntry) => uidEntry.uid === user.uid)[0] let buid = current ? ucp.format.buid(current.number, current.hash) : ucp.format.buid(); const cert = { "version": constants.DOCUMENTS_VERSION, @@ -103,10 +104,11 @@ function User (uid, options, node) { this.makeRevocation = (givenLookupIdty, overrideProps) => co(function*() { const res = givenLookupIdty || (yield that.lookup(pub)); + const matchingResult = _.filter(res.results[0].uids, (uidEntry) => uidEntry.uid === uid)[0] const idty = { - uid: res.results[0].uids[0].uid, - buid: res.results[0].uids[0].meta.timestamp, - sig: res.results[0].uids[0].self + uid: matchingResult.uid, + buid: matchingResult.meta.timestamp, + sig: matchingResult.self } const revocation = { "currency": node.server.conf.currency, -- GitLab