js: reduce request spam at getKeys()
-- * Don't make a secret-Key request for each Key retrieved, use one request for all of them instead, and assemble the info later. This should reduce the traffic with large Keyrings. The bulk retrieval for the public armored Keys for each of these Keys is still up to discussion * unittests: disabled assertion for the armored key (as it currently doesn't work) * encryptTest: clarified the mechanism/reason of rejection for Messages >64 MB. This is still a TODO, as this error comes from a different place (the browser itself) and behaves different from the other errors.
This commit is contained in:
parent
10f2106404
commit
67b6fa5a29
@ -133,7 +133,7 @@ describe('Encryption', function () {
|
||||
});
|
||||
}).timeout(5000);
|
||||
|
||||
it('Overly large message ( > 65MB) is rejected', function (done) {
|
||||
it('Overly large message ( > 64MB) is rejected', function (done) {
|
||||
let prm = Gpgmejs.init();
|
||||
prm.then(function (context) {
|
||||
context.encrypt(
|
||||
@ -142,10 +142,11 @@ describe('Encryption', function () {
|
||||
expect(answer).to.be.undefined;
|
||||
}, function(error){
|
||||
expect(error).to.be.an.instanceof(Error);
|
||||
// expect(error.code).to.equal('GNUPG_ERROR');
|
||||
// TODO: there is a 64 MB hard limit at least in chrome at:
|
||||
// chromium//extensions/renderer/messaging_util.cc:
|
||||
// kMaxMessageLength
|
||||
// The error will be a browser error, not from gnupg or from
|
||||
// this library
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -56,28 +56,46 @@ export class GPGME_Keyring {
|
||||
}
|
||||
msg.post().then(function(result){
|
||||
let resultset = [];
|
||||
let promises = [];
|
||||
if (result.keys.length === 0){
|
||||
resolve([]);
|
||||
} else {
|
||||
for (let i=0; i< result.keys.length; i++){
|
||||
let k = createKey(result.keys[i].fingerprint);
|
||||
k.setKeyData(result.keys[i]);
|
||||
if (prepare_sync === true){
|
||||
promises.push(k.getArmor());
|
||||
promises.push(k.getHasSecret());
|
||||
}
|
||||
resultset.push(k);
|
||||
}
|
||||
if (promises.length > 0) {
|
||||
Promise.all(promises).then(function() {
|
||||
resolve(resultset);
|
||||
}, function(error){
|
||||
reject(error);
|
||||
});
|
||||
let secondrequest;
|
||||
if (prepare_sync === true) {
|
||||
secondrequest = function() {
|
||||
msg.setParameter('secret', true);
|
||||
return msg.post();
|
||||
};
|
||||
} else {
|
||||
resolve(resultset);
|
||||
secondrequest = function() {
|
||||
return Promise.resolve(true);
|
||||
};
|
||||
}
|
||||
secondrequest().then(function(answer) {
|
||||
for (let i=0; i < result.keys.length; i++){
|
||||
if (prepare_sync === true){
|
||||
result.keys[i].hasSecret = false;
|
||||
if (answer && answer.keys) {
|
||||
for (let j=0; j < answer.keys.length; j++ ){
|
||||
if (result.keys[i].fingerprint ===
|
||||
answer.keys[j].fingerprint
|
||||
) {
|
||||
if (answer.keys[j].secret === true){
|
||||
result.keys[i].hasSecret = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TODO getArmor() to be used in sync
|
||||
}
|
||||
}
|
||||
let k = createKey(result.keys[i].fingerprint);
|
||||
k.setKeyData(result.keys[i]);
|
||||
resultset.push(k);
|
||||
}
|
||||
resolve(resultset);
|
||||
}, function(error){
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -272,9 +272,9 @@ function unittests (){
|
||||
keyring.getKeys(null, true).then(function(result){
|
||||
expect(result).to.be.an('array');
|
||||
expect(result[0]).to.be.an.instanceof(GPGME_Key);
|
||||
expect(result[0].get('armored')).to.be.a('string');
|
||||
expect(result[0].get('armored')).to.include(
|
||||
'-----END PGP PUBLIC KEY BLOCK-----');
|
||||
expect(result[0].get('hasSecret')).to.be.a('boolean');
|
||||
// expect(result[0].get('armored')).to.include(
|
||||
// '-----END PGP PUBLIC KEY BLOCK-----');
|
||||
done();
|
||||
});
|
||||
}
|
||||
@ -287,9 +287,11 @@ function unittests (){
|
||||
function(result){
|
||||
expect(result).to.be.an('array');
|
||||
expect(result[0]).to.be.an.instanceof(GPGME_Key);
|
||||
expect(result[0].get('armored')).to.be.a('string');
|
||||
expect(result[0].get('armored')).to.include(
|
||||
'-----END PGP PUBLIC KEY BLOCK-----');
|
||||
expect(result[0].get('hasSecret')).to.be.a('boolean');
|
||||
// TODO: preparing sync for armored is still in discussion
|
||||
// expect(result[0].get('armored')).to.be.a('string');
|
||||
// expect(result[0].get('armored')).to.include(
|
||||
// '-----END PGP PUBLIC KEY BLOCK-----');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user