aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/unittests.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-07-30 10:31:27 +0000
committerMaximilian Krambach <[email protected]>2018-07-30 10:31:27 +0000
commite16a87e83910ebb6bfdc4148369165f121f0997e (patch)
tree40727a6f9aec8110cc0bfaefc8aa36d14e302ecd /lang/js/unittests.js
parentjs: fix indentaion (diff)
downloadgpgme-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 '')
-rw-r--r--lang/js/unittests.js16
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