js: include armored Key in import callback
authorMaximilian Krambach <maximilian.krambach@intevation.de>
Tue, 24 Jul 2018 12:56:33 +0000 (14:56 +0200)
committerMaximilian Krambach <maximilian.krambach@intevation.de>
Tue, 24 Jul 2018 12:56:33 +0000 (14:56 +0200)
--

* The import answer now also directly contains the armored Key as Key
  property, without need to refresh the Key object created in the
  answer. This allows for direct comparision of input and output.
* BrowserTestExtension: added test for that import callback

lang/js/BrowserTestExtension/tests/KeyImportExport.js
lang/js/src/Key.js

index 4a53c7a..ed307b3 100644 (file)
@@ -83,6 +83,32 @@ describe('Key importing', function () {
                 });
         });
     });
+
+    it('Import result feedback', function(done){
+        let prm = Gpgmejs.init();
+        prm.then(function (context) {
+            context.Keyring.getKeys(ImportablePublicKey.fingerprint).then(
+                function(result){
+                    expect(result).to.be.an('array');
+                    expect(result.length).to.equal(0);
+                    context.Keyring.importKey(ImportablePublicKey.key, true)
+                        .then(function(result){
+                            expect(result).to.be.an('object');
+                            expect(result.Keys[0]).to.be.an('object');
+                            expect(result.Keys[0].key.fingerprint).to.equal(
+                                ImportablePublicKey.fingerprint);
+                            expect(result.Keys[0].status).to.equal('newkey');
+                            result.Keys[0].key.getArmor().then(function(armor){
+                                expect(armor).to.be.a('string');
+                                result.Keys[0].key.delete().then(function(){
+                                    done();
+                                });
+                            });
+                        });
+                });
+        });
+    });
+
     it('exporting armored Key with getKeysArmored', function (done) {
         let prm = Gpgmejs.init();
         const fpr = inputvalues.encrypt.good.fingerprint;
index 30f507c..b024a77 100644 (file)
@@ -141,7 +141,7 @@ export class GPGME_Key {
      * during a session. The key still can be reloaded by invoking
      * {@link refreshKey}.
      * @returns {*|Promise<*>} the value (Boolean, String, Array, Object).
-     * If 'cached' is true, the value will be resolved as a Promise.
+     * If 'cached' is false, the value will be resolved as a Promise.
      */
     get(property, cached=true) {
         if (cached === false) {
@@ -194,8 +194,11 @@ export class GPGME_Key {
                 if (result.keys.length === 1){
                     me.setKeyData(result.keys[0]);
                     me.getHasSecret().then(function(){
-                        //TODO retrieve armored Key
-                        resolve(me);
+                        me.getArmor().then(function(){
+                            resolve(me);
+                        }, function(error){
+                            reject(error);
+                        });
                     }, function(error){
                         reject(error);
                     });