insomnia/packages/insomnia-app/app/__mocks__/node-forge.js

98 lines
1.7 KiB
JavaScript
Raw Normal View History

/*
* This is a stupid little mock that basically disabled encryption.
* The reason it is needed is because the Forge module loader doesn't
* play along with Jest.
*/
const forge = require('../../node_modules/node-forge/lib/index');
module.exports = {
jsbn: forge.jsbn,
util: forge.util,
pkcs5: {
pbkdf2() {},
},
md: {
2016-12-24 22:24:10 +00:00
sha256: {
2018-06-25 17:42:50 +00:00
create() {
return 'TODO';
},
},
},
rsa: {
2018-06-25 17:42:50 +00:00
setPublicKey() {
return {
2018-06-25 17:42:50 +00:00
encrypt(str) {
return str;
},
};
},
2018-06-25 17:42:50 +00:00
setPrivateKey() {
return {
2018-06-25 17:42:50 +00:00
decrypt(str) {
return str;
},
};
},
},
random: {
2018-06-25 17:42:50 +00:00
getBytesSync(n) {
let s = '';
for (let i = 0; i < n; i++) {
s += 'a';
}
return s;
},
},
pki: {
rsa: {
2018-06-25 17:42:50 +00:00
generateKeyPair() {
return {
privateKey: {
d: 'a',
dP: 'a',
dQ: 'a',
e: 'a',
n: 'a',
p: 'a',
q: 'a',
qInv: 'a',
},
publicKey: {
e: 'a',
n: 'a',
},
};
},
},
},
cipher: {
2018-06-25 17:42:50 +00:00
createCipher(alg, key) {
return {
2018-06-25 17:42:50 +00:00
start(config) {
this._config = config;
},
2018-06-25 17:42:50 +00:00
update(buffer) {
this._data = buffer;
},
2018-06-25 17:42:50 +00:00
finish() {
this.mode = { tag: 'tag' };
this.output = this._data;
},
};
},
2018-06-25 17:42:50 +00:00
createDecipher(alg, key) {
return {
2018-06-25 17:42:50 +00:00
start(config) {
this._config = config;
},
2018-06-25 17:42:50 +00:00
update(buffer) {
this.output = buffer;
},
2018-06-25 17:42:50 +00:00
finish() {
return true;
},
};
},
},
};