mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2025-08-14 03:35:36 +00:00
chore: cleanup
This commit is contained in:
92
test/unit/keys.js
Normal file
92
test/unit/keys.js
Normal file
@@ -0,0 +1,92 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-env node, mocha */
|
||||
|
||||
const { assert } = require('chai');
|
||||
const fixtures = require('../fixtures/keys');
|
||||
// const Key = require('../lib/keymanagers/keyRSA');
|
||||
const Key = require('../../lib/keymanagers/Key');
|
||||
|
||||
const stripWhitespace = str => str.replace(/\s+/g, '');
|
||||
|
||||
describe('Keys management', () => {
|
||||
describe('generates brand new', () => {
|
||||
const keySize = 2048;
|
||||
// const newKey = Key().generate(keySize);
|
||||
const newKey = Key.generate();
|
||||
|
||||
it('private key', () => {
|
||||
assert.isTrue(newKey.isPrivate());
|
||||
});
|
||||
|
||||
it('that has the right key size', () => {
|
||||
// const newKeySize = newKey.size(); // console.log(newKey.size());
|
||||
assert(newKey.size(), keySize);
|
||||
});
|
||||
});
|
||||
|
||||
describe('creates public key from mod and exp', () => {
|
||||
const { pem, mod, exp } = fixtures.pblc.big;
|
||||
|
||||
describe('that are strings', () => {
|
||||
const m = Buffer.from(mod.string, 'base64');
|
||||
const e = Buffer.from(exp.string, 'base64');
|
||||
/* const newKey = Key().importKey({
|
||||
mod: m, exp: e, modulus: mod.string, exponent: exp.string,
|
||||
}); */
|
||||
const newKey = new Key({ mod: m, exp: e });
|
||||
|
||||
it('and is really public', () => {
|
||||
assert.isTrue(newKey.isPublic());
|
||||
});
|
||||
|
||||
|
||||
it('and has a propper mod in bytes', () => {
|
||||
assert.deepEqual([...newKey.n()], mod.bytes);
|
||||
});
|
||||
|
||||
it('and has a propper pem string', () => {
|
||||
assert.equal(stripWhitespace(newKey.toPem()), stripWhitespace(pem));
|
||||
});
|
||||
});
|
||||
|
||||
describe('that are bytes', () => {
|
||||
const m = Buffer.from(mod.bytes);
|
||||
const e = Buffer.from(exp.bytes);
|
||||
/* const newKey = Key().importKey({
|
||||
mod: m, exp: e, modulus: mod.string, exponent: exp.string,
|
||||
}); */
|
||||
const newKey = new Key({ mod: m, exp: e });
|
||||
|
||||
it('and is really public', () => {
|
||||
assert.isTrue(newKey.isPublic());
|
||||
});
|
||||
|
||||
it('and has a propper mod as a string', () => {
|
||||
assert.equal(newKey.n().toString('base64'), mod.string);
|
||||
});
|
||||
|
||||
it('and has a propper pem string', () => {
|
||||
assert.equal(stripWhitespace(newKey.toPem()), stripWhitespace(pem));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('creates public key from pem string', () => {
|
||||
const { pem } = fixtures.pblc.big;
|
||||
// const newKey = Key(pem);
|
||||
const newKey = new Key({ pem });
|
||||
|
||||
it('and is really public', () => {
|
||||
assert.isTrue(newKey.isPublic());
|
||||
});
|
||||
|
||||
it('and has a propper(the same) pem string', () => {
|
||||
/* newKey.pempem = {
|
||||
modulus: mod.string,
|
||||
exponent: exp.string,
|
||||
}; */
|
||||
assert.equal(stripWhitespace(newKey.toPem()), stripWhitespace(pem));
|
||||
});
|
||||
});
|
||||
});
|
45
test/unit/responseParser.js
Normal file
45
test/unit/responseParser.js
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-env node, mocha */
|
||||
|
||||
const { assert } = require('chai');
|
||||
const H004Response = require('../../lib/orders/H004/response');
|
||||
|
||||
describe('H004 response parsing', () => {
|
||||
it('parses bank keys', () => {
|
||||
const response = H004Response('<xml/>', {});
|
||||
|
||||
const x002mod = 'ntbX6WFjAJP5RyH4ogDG/26wZGzEJXsTudyvcgXmUdk1AExCNqArXDiSlGXpVNq4BKddUMFUmVOyvkdNckPRV2mk3uHNCE5T3tFKQI3FlwHSJHvPSpb9gtHnsK03jByMigWjhTKvsjIdfLVay5m5Bctxq9+5JMHwlNk7MlVXBQcqaFiHFFS1lPfA3Wk1bptPeeGyYcP0+U798oQWnCABKwS8hmYcp5xBtozGoRj9L/NDE68pdP8o/wTKNwT4Jo5nQKYfDsgO4R+z9vVv37Htp6bWhK8Jw3tpkcd3JnkYWx+Ylg0XBpg8LfjFhY2Jc7FqLlx0Bn0Y3PRLI1apxgC85w==';
|
||||
const e002mod = '4eOGrzcJHVzbEgZTmyPYUIq9kFoua8Ure1Mvyq6XlawFgCWskfu/xSKNLIMJ7H675wl/5y0Oy16P/b6pJEhWrzOw8omW46PBDTaXw9BDYBTuBblluz1yUnzpgfblP8gkRmxAo+QMIskmwdSzuZMiJcLNSzu/bkmLHK2RdrVYMAZLlB6QXTykdenPZtNmc2z4VU6TRmGljAwg2VUNF6iQoucbzDUuca+yUo3fiXZp69nfXv81X2ND+p1ir6zQpx7tbOdfauw0sEKI/Z/lC+E4fMrMlh/ZvOxSYUMA55J4liC3aUV3mTR3dPJHWu1aD1a7EfJnNw0eHLwlB+36qfgGuw==';
|
||||
|
||||
response.orderData = () => `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<HPBResponseOrderData xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
||||
<AuthenticationPubKeyInfo>
|
||||
<PubKeyValue>
|
||||
<ds:RSAKeyValue>
|
||||
<ds:Modulus>${x002mod}</ds:Modulus>
|
||||
<ds:Exponent>AQAB</ds:Exponent>
|
||||
</ds:RSAKeyValue>
|
||||
<TimeStamp>2015-02-25T08:01:13.061Z</TimeStamp>
|
||||
</PubKeyValue>
|
||||
<AuthenticationVersion>X002</AuthenticationVersion>
|
||||
</AuthenticationPubKeyInfo>
|
||||
<EncryptionPubKeyInfo>
|
||||
<PubKeyValue>
|
||||
<ds:RSAKeyValue>
|
||||
<ds:Modulus>${e002mod}</ds:Modulus>
|
||||
<ds:Exponent>AQAB</ds:Exponent>
|
||||
</ds:RSAKeyValue>
|
||||
<TimeStamp>2015-02-25T08:01:12.344Z</TimeStamp>
|
||||
</PubKeyValue>
|
||||
<EncryptionVersion>E002</EncryptionVersion>
|
||||
</EncryptionPubKeyInfo>
|
||||
<HostID>SBKPR01</HostID>
|
||||
</HPBResponseOrderData>`;
|
||||
|
||||
const bankKeys = response.bankKeys();
|
||||
|
||||
assert.equal(bankKeys.bankX002.mod.toString('base64'), x002mod);
|
||||
assert.equal(bankKeys.bankE002.mod.toString('base64'), e002mod);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user