insomnia/app/__mocks__/node-forge.js
Gregory Schier 8efd8fc416 Add Sync Tests (#74)
* Started sync tests

* Simplified logic a bit and better tests

* Some more tests

* More tests yet
2017-01-09 13:59:52 -08:00

119 lines
1.9 KiB
JavaScript

/*
* 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 jsbn = require('jsbn');
module.exports = function (options) {
const forge = require('../../node_modules/node-forge/js/forge')(options);
forge.jsbn = jsbn;
forge.util = {
hexToBytes: forge.hexToBytes,
bytesToHex: forge.bytesToHex,
createBuffer (text) {
return new Buffer(text);
}
};
forge.pkcs5 = {
pbkdf2 () {
}
};
forge.md = {
sha256: {
create () {
return 'TODO'
}
}
};
forge.rsa = {
setPublicKey() {
return {
encrypt (str) {
return str
}
}
},
setPrivateKey() {
return {
decrypt (str) {
return str
}
}
}
};
forge.random = {
getBytesSync(n) {
let s = '';
for (let i = 0; i < n; i++) {
s += 'a';
}
return s;
}
};
forge.pki = {
rsa: {
generateKeyPair() {
return {
privateKey: {
d: 'a',
dP: 'a',
dQ: 'a',
e: 'a',
n: 'a',
p: 'a',
q: 'a',
qInv: 'a',
},
publicKey: {
e: 'a',
n: 'a',
}
}
}
}
};
forge.cipher = {
createCipher(alg, key) {
return {
start(config) {
this._config = config;
},
update(buffer) {
this._data = buffer;
},
finish() {
this.mode = {tag: 'tag'};
this.output = this._data;
}
};
},
createDecipher(alg, key) {
return {
start (config) {
this._config = config;
},
update (buffer) {
this.output = buffer;
},
finish () {
return true;
}
};
}
};
return forge;
}
;