Mise à jour de GitLab prévue ce samedi 8 mai 2021 à partir de 9h00 CET | GitLab upgrade planned this Saturday May 4th of 2021 from 9:00 AM CET

Commit d8cd97ff authored by Cédric Moreau's avatar Cédric Moreau

TDD: Block:Global: certification replay must respect 'sigDelay'

parent 12cc7d47
......@@ -6,12 +6,12 @@ var Identity = mongoose.model('Identity', require('../models/identity'));
var Membership = mongoose.model('Membership', require('../models/membership'));
var Certification = mongoose.model('Certification', require('../models/certification'));
module.exports = function (dao) {
module.exports = function (conf, dao) {
return new GlobalValidator(dao);
return new GlobalValidator(conf, dao);
};
function GlobalValidator (dao) {
function GlobalValidator (conf, dao) {
this.checkSignatures = function (block, done) {
async.series([
......@@ -147,7 +147,22 @@ function GlobalValidator (dao) {
}
function checkCertificationsDelayIsRespected (block, done) {
done();
async.forEach(block.certifications, function(inlineCert, callback){
var cert = Certification.fromInline(inlineCert);
async.waterfall([
function (next){
dao.getPreviousLinkFor(cert.from, cert.to, next);
},
function (previous, next){
var duration = previous && (block.confirmedDate - parseInt(previous.timestamp));
if (previous && (duration < conf.sigDelay)) {
next('Too early for this certification');
} else {
next();
}
},
], callback);
}, done);
}
function checkNewcomersHaveEnoughCertifications (block, done) {
......
......@@ -623,4 +623,33 @@ module.exports = {
"HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:F5PtTpt8QFYMGtpZaETygB2C2yxCSxH1UW1VopBNZ6qg:1411844659:kr2JA6wCGfbNKGpyM86BscsFk22aA9oiAon8mWRPl4G8UpJKZs3tjuPRAw5+04KLCRWl/TT1TumDCkeEjev7DA==\n" +
"Transactions:\n" +
"kNsKdC8eH0d4zdHh1djyMzRXjFrwk3Bc3M8wo4DV/7clE9J66K/U0FljyS79SI78ZZUPaVmrImKJ9SNiubCiBg==\n",
TOO_EARLY_CERTIFICATION_REPLAY:
"Version: 1\n" +
"Type: Block\n" +
"Currency: beta_brousouf\n" +
"Nonce: 11\n" +
"Number: 0\n" +
"Date: 1411776000\n" +
"ConfirmedDate: 1411776000\n" +
"Issuer: CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n" +
"MembersCount: 3\n" +
"Identities:\n" +
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC:Die9lYNW1u/w50AfuaXwb4MJc3aKA3WfJwiy+31TqHIGC+VNnRKjMmrwMptN+a+dL6INjLrhMrPqoK60IkTlDQ==:1411837451:CAT\n" +
"G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU:NJE8nYU4Im+KQDRdoAn5gcfic+Gjjzp0Pp0iji/Fzh9JIThoQeUDDew4Q5vJBEg/Aw7gPnIg+11TbLkIGa/ODQ==:1411837452:TAC\n" +
"F5PtTpt8QFYMGtpZaETygB2C2yxCSxH1UW1VopBNZ6qg:1V/QnQcnJtQSSvhOFBhl7kGXBea8gKEQ6iqPNCVb41yI9gN79XGtUeHhjlumhQkPeizlzpkcNBkL8bhokiNcBQ==:1411837457:SNOW\n" +
"Joiners:\n" +
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC:iSQvl1VVc6+b1AUaBJ/VTTurGGHgaIcjASBhIlzI7M/7KVQV2Wi3oGUZUzLWqCAtGUsPcsj1HCV2/sRyxHmqAw==:1411837455:1411837451:CAT\n" +
"G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU:25xK7+ph7IYeN9Hu8PvuIBjYdVURYtvKayPHZg7zrrYTs6ii2fMtk5J65a3bT/NKr2Qsd7I5TCL29QyiAXa7BA==:1411837456:1411837452:TAC\n" +
"F5PtTpt8QFYMGtpZaETygB2C2yxCSxH1UW1VopBNZ6qg:ze+ftHWFLYmjfvXyrx4a15N2VQjf6oen8kkMiYNYrVllbpb5IUcb28CenlOQbVd9cZCNGSkTP7xP5bt8KAqUAw==:1411837462:1411837457:SNOW\n" +
"Leavers:\n" +
"Excluded:\n" +
"Certifications:\n" +
"G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU:CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC:1411844654:vTvKYvjTYUT30t/9h7uNE/2LFJiYuA4YleIetFkb62XxDoxGizKC9VvVs7WRNArcfHvJ+RLyOoawQzpmw2DyCw==\n" +
"F5PtTpt8QFYMGtpZaETygB2C2yxCSxH1UW1VopBNZ6qg:CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC:1411844658:2KmmmIL8eK/TACjOqTqO5ZG/tgMYWWV8zRICWFQJuqWyYVg/y5wzXyHrgfpdMYhwYMRBhwbMk1sPNLo/kzp0AA==\n" +
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC:G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU:1411844653:DU4JlHxJtIb2Z7Ag4Jy+z0qjNNo5jzN5EvTUWOTRRzeb6LbOClw2X+pmb0mV/wpVKd/lJrUHAWeKMDHG4MukCA==\n" +
"F5PtTpt8QFYMGtpZaETygB2C2yxCSxH1UW1VopBNZ6qg:G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU:1411844660:tY5J+g3sM421sx0WNUuESUL8Zz2BU0UbtXT+nRsTlYThaDubMg/GmhsxWa0ccRJcZvftEwpENtVjyd6hyPSQCw==\n" +
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC:F5PtTpt8QFYMGtpZaETygB2C2yxCSxH1UW1VopBNZ6qg:1411844659:kr2JA6wCGfbNKGpyM86BscsFk22aA9oiAon8mWRPl4G8UpJKZs3tjuPRAw5+04KLCRWl/TT1TumDCkeEjev7DA==\n" +
"Transactions:\n" +
"kNsKdC8eH0d4zdHh1djyMzRXjFrwk3Bc3M8wo4DV/7clE9J66K/U0FljyS79SI78ZZUPaVmrImKJ9SNiubCiBg==\n",
};
var async = require('async');
var should = require('should');
var assert = require('assert');
var mongoose = require('mongoose');
var parsers = require('../../../app/lib/streams/parsers/doc');
var blocks = require('../../data/blocks');
var validator = require('../../../app/lib/globalValidator');
var parser = parsers.parseBlock();
var Block = mongoose.model('Block', require('../../../app/models/block'));
var Identity = mongoose.model('Identity', require('../../../app/models/identity'));
var async = require('async');
var should = require('should');
var assert = require('assert');
var mongoose = require('mongoose');
var parsers = require('../../../app/lib/streams/parsers/doc');
var blocks = require('../../data/blocks');
var validator = require('../../../app/lib/globalValidator');
var parser = parsers.parseBlock();
var Block = mongoose.model('Block', require('../../../app/models/block'));
var Identity = mongoose.model('Identity', require('../../../app/models/identity'));
var Configuration = mongoose.model('Configuration', require('../../../app/models/configuration'));
var conf = new Configuration({
sigDelay: 365.25*24*3600 // 1 year
});
describe("Block local coherence", function(){
......@@ -46,6 +51,12 @@ describe("Block local coherence", function(){
done();
}));
it('a block with too early certification replay should fail', validate(blocks.TOO_EARLY_CERTIFICATION_REPLAY, function (err, done) {
should.exist(err);
err.should.equal('Too early for this certification');
done();
}));
});
function validate (raw, callback) {
......@@ -57,10 +68,10 @@ function validate (raw, callback) {
},
function (obj, next){
block = new Block(obj);
validator(new BlockCheckerDao(block)).validate(block, next);
validator(conf, new BlockCheckerDao(block)).validate(block, next);
},
function (obj, next){
validator(new BlockCheckerDao(block)).checkSignatures(block, next);
validator(conf, new BlockCheckerDao(block)).checkSignatures(block, next);
},
], function (err) {
callback(err, done);
......@@ -98,4 +109,15 @@ function BlockCheckerDao (block) {
// No existing member
done(null, false);
}
this.getPreviousLinkFor = function (from, to, done) {
if (from == 'G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU'
&& to == 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC') {
done(null, {
timestamp: '1380218401' // Exactly 1 second remaining
});
} else {
done(null, null);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment