diff options
author | Maximilian Krambach <[email protected]> | 2018-07-30 10:31:27 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-07-30 10:31:27 +0000 |
commit | e16a87e83910ebb6bfdc4148369165f121f0997e (patch) | |
tree | 40727a6f9aec8110cc0bfaefc8aa36d14e302ecd /lang/js/unittests.js | |
parent | js: fix indentaion (diff) | |
download | gpgme-e16a87e83910ebb6bfdc4148369165f121f0997e.tar.gz gpgme-e16a87e83910ebb6bfdc4148369165f121f0997e.zip |
js: Making objects inmutable
--
* An Object.freeze should stop any malicious third party from changing
objects' methods once the objects are instantiated (see unittest for
an approach that would have worked before)
- An initialized gpgmejs- object doesn't have a '_Keyring' property
anymore (it still has its 'Keyring')
- The internal expect='base64' needed to be turned into a method.
Diffstat (limited to 'lang/js/unittests.js')
-rw-r--r-- | lang/js/unittests.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lang/js/unittests.js b/lang/js/unittests.js index 6228993b..3304b1eb 100644 --- a/lang/js/unittests.js +++ b/lang/js/unittests.js @@ -253,6 +253,22 @@ function unittests (){ expect(key.fingerprint.code).to.equal('KEY_INVALID'); } }); + + it('Overwriting getFingerprint does not work', function(){ + const evilFunction = function(){ + return 'bad Data'; + }; + let key = createKey(kp.validKeyFingerprint, true); + expect(key.fingerprint).to.equal(kp.validKeyFingerprint); + try { + key.getFingerprint = evilFunction; + } + catch(e) { + expect(e).to.be.an.instanceof(TypeError); + } + expect(key.fingerprint).to.equal(kp.validKeyFingerprint); + expect(key.getFingerprint).to.not.equal(evilFunction); + }); // TODO: tests for subkeys // TODO: tests for userids // TODO: some invalid tests for key/keyring |