Skip to content

Commit

Permalink
Merge pull request #50 from mojaloop/outbound-ilp-fix
Browse files Browse the repository at this point in the history
fix missing ILP verification on outbound model and enhance tests
  • Loading branch information
bushjames committed Sep 16, 2019
2 parents 4b13d3d + 0209956 commit 32411e1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/__mocks__/@mojaloop/sdk-standard-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class MockIlp {
console.log('MockIlp constructed');
this.config = config;
}

validateFulfil(fulfil, condition) {
console.log(`Mock ILP not checking fulfil ${fulfil} against condition ${condition}`);
return true;
}
}


Expand Down
1 change: 1 addition & 0 deletions src/lib/model/outboundModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class OutboundTransfersModel {
this.expirySeconds = config.expirySeconds;
this.autoAcceptQuotes = config.autoAcceptQuotes;
this.autoAcceptParty = config.autoAcceptParty;
this.checkIlp = config.checkIlp;

this.requests = new MojaloopRequests({
logger: this.logger,
Expand Down
67 changes: 51 additions & 16 deletions src/test/unit/outboundModel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


// load default local environment vars
require('dotenv').config({path: 'local.env'});
//require('dotenv').config({path: 'local.env'});

// we use a mock standard components lib to intercept and mock certain funcs
jest.mock('@mojaloop/sdk-standard-components');
Expand All @@ -28,6 +28,41 @@ const Model = require('@internal/model').outboundTransfersModel;
let logTransports;


// dummy environment config
const config = {
INBOUND_LISTEN_PORT: '4000',
OUTBOUND_LISTEN_PORT: '4001',
MUTUAL_TLS_ENABLED: 'false',
VALIDATE_INBOUND_JWS: 'true',
JWS_SIGN: 'true',
JWS_SIGNING_KEY_PATH: '/jwsSigningKey.key',
JWS_VERIFICATION_KEYS_DIRECTORY: '/jwsVerificationKeys',
IN_CA_CERT_PATH: './secrets/cacert.pem',
IN_SERVER_CERT_PATH: './secrets/servercert.pem',
IN_SERVER_KEY_PATH: './secrets/serverkey.pem',
OUT_CA_CERT_PATH: './secrets/cacert.pem',
OUT_CLIENT_CERT_PATH: './secrets/servercert.pem',
OUT_CLIENT_KEY_PATH: './secrets/serverkey.pem',
LOG_INDENT: '0',
CACHE_HOST: '172.17.0.2',
CACHE_PORT: '6379',
PEER_ENDPOINT: '172.17.0.3:4000',
BACKEND_ENDPOINT: '172.17.0.5:4000',
DFSP_ID: 'mojaloop-sdk',
ILP_SECRET: 'Quaixohyaesahju3thivuiChai5cahng',
EXPIRY_SECONDS: '60',
AUTO_ACCEPT_QUOTES: 'false',
AUTO_ACCEPT_PARTY: 'false',
CHECK_ILP: 'true',
ENABLE_TEST_FEATURES: 'false',
WS02_BEARER_TOKEN: '7718fa9b-be13-3fe7-87f0-a12cf1628168',
OAUTH_TOKEN_ENDPOINT: '',
OAUTH_CLIENT_KEY: '',
OAUTH_CLIENT_SECRET: '',
OAUTH_REFRESH_SECONDS: '3600'
};


// a dummy transfer request
const transferRequest = {
"from": {
Expand Down Expand Up @@ -101,7 +136,7 @@ const quoteResponse = {
const transferFulfil = {
"type": "transferFulfil",
"data": {
"fulfilment": "7mm1-reS3SAi8oIWXgBkLmgWc1MkZ_yLbFDX5XAdo5o",
"fulfilment": "87mm1-reS3SAi8oIWXgBkLmgWc1MkZ_yLbFDX5XAdo5o",
"completedTimestamp": "2017-11-15T14:16:09.663+01:00",
"transferState": "COMMITTED"
}
Expand All @@ -111,8 +146,8 @@ const transferFulfil = {
describe('outboundModel', () => {
// the keys are under the "secrets" folder that is supposed to be moved by Dockerfile
// so for the needs of the unit tests, we have to define the proper path manually.
process.env.JWS_SIGNING_KEY_PATH = path.join('..', 'secrets', process.env.JWS_SIGNING_KEY_PATH);
process.env.JWS_VERIFICATION_KEYS_DIRECTORY = path.join('..', 'secrets', process.env.JWS_VERIFICATION_KEYS_DIRECTORY);
config.JWS_SIGNING_KEY_PATH = path.join('..', 'secrets', config.JWS_SIGNING_KEY_PATH);
config.JWS_VERIFICATION_KEYS_DIRECTORY = path.join('..', 'secrets', config.JWS_VERIFICATION_KEYS_DIRECTORY);

beforeAll(async () => {
logTransports = await Promise.all([Transports.consoleDir()]);
Expand All @@ -125,7 +160,7 @@ describe('outboundModel', () => {
test('initializes to starting state', async () => {
init();

await setConfig(process.env);
await setConfig(config);
const conf = getConfig();

const model = new Model({
Expand All @@ -146,10 +181,10 @@ describe('outboundModel', () => {

test('executes all three transfer stages without halting when AUTO_ACCEPT_PARTY and AUTO_ACCEPT_QUOTES are true', async () => {
init();
process.env.AUTO_ACCEPT_PARTY = true;
process.env.AUTO_ACCEPT_QUOTES = true;
config.AUTO_ACCEPT_PARTY = 'true';
config.AUTO_ACCEPT_QUOTES = 'true';

await setConfig(process.env);
await setConfig(config);
const conf = getConfig();

const model = new Model({
Expand Down Expand Up @@ -197,9 +232,9 @@ describe('outboundModel', () => {

test('resolves payee and halts when AUTO_ACCEPT_PARTY is false', async () => {
init();
process.env.AUTO_ACCEPT_PARTY = false;
config.AUTO_ACCEPT_PARTY = 'false';

await setConfig(process.env);
await setConfig(config);
const conf = getConfig();

const model = new Model({
Expand Down Expand Up @@ -235,10 +270,10 @@ describe('outboundModel', () => {

test('halts after resolving payee, resumes and then halts after receiving quote response when AUTO_ACCEPT_PARTY is false and AUTO_ACCEPT_QUOTES is false', async () => {
init();
process.env.AUTO_ACCEPT_PARTY = false;
process.env.AUTO_ACCEPT_QUOTES = false;
config.AUTO_ACCEPT_PARTY = 'false';
config.AUTO_ACCEPT_QUOTES = 'false';

await setConfig(process.env);
await setConfig(config);
const conf = getConfig();

const cache = new MockCache();
Expand Down Expand Up @@ -308,10 +343,10 @@ describe('outboundModel', () => {

test('halts and resumes after parties and quotes stages when AUTO_ACCEPT_PARTY is false and AUTO_ACCEPT_QUOTES is false', async () => {
init();
process.env.AUTO_ACCEPT_PARTY = false;
process.env.AUTO_ACCEPT_QUOTES = false;
config.AUTO_ACCEPT_PARTY = 'false';
config.AUTO_ACCEPT_QUOTES = 'false';

await setConfig(process.env);
await setConfig(config);
const conf = getConfig();

const cache = new MockCache();
Expand Down

0 comments on commit 32411e1

Please sign in to comment.