From 53ce2b94bc35243710dec9b7972c7aaaa79dbc75 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Mon, 28 May 2018 17:26:56 +0200 Subject: js: Keyring listing keys -- * implementing Keyring methods: - Keyring.getKeys: has an additional option that retrieves the armor and secret state once at the beginning. This is power hungry, but allows for Keys to be used directly (without querying gpgme-json each call) * permittedOperations.js: reflect recent changes in the native counterpart, adding more options * Key: adding two methods for retrieving the armored Key block and for finding out if the Key includes a secret subkey. --- lang/js/unittests.js | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'lang/js/unittests.js') diff --git a/lang/js/unittests.js b/lang/js/unittests.js index 9830a2c5..443aa685 100644 --- a/lang/js/unittests.js +++ b/lang/js/unittests.js @@ -197,7 +197,34 @@ function unittests (){ expect(result).to.be.a('boolean'); done(); }); - }) + }); + + it('Non-cached key async armored Key', function (done){ + let key = createKey(kp.validKeyFingerprint); + key.get('armor', false).then(function(result){ + expect(result).to.be.a('string'); + expect(result).to.include('KEY BLOCK-----'); + done(); + }); + }); + + it('Non-cached key async hasSecret', function (done){ + let key = createKey(kp.validKeyFingerprint); + key.get('hasSecret', false).then(function(result){ + expect(result).to.be.a('boolean'); + done(); + }); + }); + + it('Non-cached key async hasSecret (no secret in Key)', function (done){ + let key = createKey(kp.validFingerprintNoSecret); + expect(key).to.be.an.instanceof(GPGME_Key); + key.get('hasSecret', false).then(function(result){ + expect(result).to.be.a('boolean'); + expect(result).to.equal(false); + done(); + }); + }); it('Querying non-existing Key returns an error', function(done) { let key = createKey(kp.invalidKeyFingerprint); @@ -224,7 +251,6 @@ function unittests (){ expect(key.fingerprint.code).to.equal('KEY_INVALID'); } }); - // TODO: tests for subkeys // TODO: tests for userids // TODO: some invalid tests for key/keyring @@ -236,19 +262,19 @@ function unittests (){ let keyring = new GPGME_Keyring; expect(keyring).to.be.an.instanceof(GPGME_Keyring); expect(keyring.getKeys).to.be.a('function'); - expect(keyring.getSubset).to.be.a('function'); }); - it('correct initialization', function(){ + it('Loading Keys from Keyring, to be used synchronously', function(done){ let keyring = new GPGME_Keyring; - expect(keyring).to.be.an.instanceof(GPGME_Keyring); - expect(keyring.getKeys).to.be.a('function'); - expect(keyring.getSubset).to.be.a('function'); + 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('armor')).to.be.a('string'); + expect(result[0].get('armor')).to.include( + '-----END PGP PUBLIC KEY BLOCK-----'); + done(); + }); }); - //TODO not yet implemented: - // getKeys(pattern, include_secret) //note: pattern can be null - // getSubset(flags, pattern) - // available Boolean flags: secret revoked expired }); describe('GPGME_Message', function(){ -- cgit v1.2.3