diff --git a/.circleci/config.yml b/.circleci/config.yml index af3d307..34eb05d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -165,12 +165,12 @@ jobs: # command: npm install github:interledgerjs/five-bells-ledger-api-tests - run: name: Update NPM install - command: cd src && npm install + command: cd src && npm ci - run: name: Delete build dependencies command: apk del build-dependencies - save_cache: - key: dependency-cache-{{ checksum "src/package.json" }} + key: dependency-cache-{{ checksum "src/package-lock.json" }} paths: - src/node_modules @@ -184,7 +184,10 @@ jobs: - checkout - restore_cache: keys: - - dependency-cache-{{ checksum "src/package.json" }} + - dependency-cache-{{ checksum "src/package-lock.json" }} + - run: + name: Execute linter + command: cd src && npm run lint - run: name: Create dir for test results command: cd src && mkdir -p ./test/results @@ -286,7 +289,7 @@ jobs: - run: <<: *defaults_license_scanner - restore_cache: - key: dependency-cache-{{ checksum "src/package.json" }} + key: dependency-cache-{{ checksum "src/package-lock.json" }} - run: name: Prune non-production packages before running license-scanner command: cd src && npm prune --production diff --git a/src/db.js b/src/db.js index 8e93b28..ae41648 100644 --- a/src/db.js +++ b/src/db.js @@ -580,8 +580,8 @@ module.exports = class Database { } async getCurrentSettlementWindowId() { - const thisSettlementWindowId = await this.connection.query(currentSettlementWindowId); - return thisSettlementWindowId[0][0].settlementWindowId; + const thisSettlementWindowId = await this.connection.query(currentSettlementWindowId); + return thisSettlementWindowId[0][0].settlementWindowId; } async getCurrentSettlementWindowInfo(participantId) { diff --git a/src/handlers/settlement-windows.js b/src/handlers/settlement-windows.js index bbc043e..40925a8 100644 --- a/src/handlers/settlement-windows.js +++ b/src/handlers/settlement-windows.js @@ -19,12 +19,16 @@ const handler = (router, routesContext) => { }); router.get('/settlement-windows/:settlementWindowId', async (ctx, next) => { - const settlementWindow = await routesContext.db.getSettlementWindowInfo(ctx.params.settlementWindowId); + const settlementWindow = await routesContext + .db.getSettlementWindowInfo(ctx.params.settlementWindowId); + try { const api = new Model({ endpoint: routesContext.config.settlementsEndpoint }); - const settlement = await api.getSettlements({ settlementWindowId: ctx.params.settlementWindowId }); + const settlement = await api.getSettlements({ + settlementWindowId: ctx.params.settlementWindowId, + }); settlementWindow.settlement = (settlement.length === 1 ? settlement[0] : {}); - } catch(error) { + } catch (error) { routesContext.log(error); settlementWindow.settlement = {}; } diff --git a/src/handlers/validate-transfer.js b/src/handlers/validate-transfer.js index b82515a..e34bc14 100644 --- a/src/handlers/validate-transfer.js +++ b/src/handlers/validate-transfer.js @@ -5,10 +5,10 @@ const util = require('util'); const AzureLog = require('../lib/azureLog'); -const dir = './secrets' +const dir = './secrets'; const pubKeys = fs.readdirSync(dir) - .filter(fname => !fs.statSync(`${dir}/${fname}`).isDirectory()) - .map(fname => fs.readFileSync(`${dir}/${fname}`, 'utf-8')); + .filter(fname => !fs.statSync(`${dir}/${fname}`).isDirectory()) + .map(fname => fs.readFileSync(`${dir}/${fname}`, 'utf-8')); const handler = (router, routesContext) => { router.get('/validate-transfer/:transferId', async (ctx, next) => { @@ -30,18 +30,7 @@ const handler = (router, routesContext) => { const token = `${check.protectedHeader}.${check.body}.${check.signature}`; try { - for (const pubKey of pubKeys) { - // TODO: Investigate the linting error - // eslint-disable-next-line - JWT.verify(token, pubKey, (err) => { - if (err) { - routesContext.log(`Error verifying JWS token: ${err.stack || util.inspect(err)}`); - } else { - isValidTransfer = true; - } - }); - if (isValidTransfer === true) break; - } + isValidTransfer = pubKeys.some(pubKey => JWT.verify(token, pubKey)); } catch (err) { routesContext.log(`Error validating JWS token: ${err.stack || util.inspect(err)}`); } diff --git a/src/package-lock.json b/src/package-lock.json index 6f8e9e7..900ea61 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1,6 +1,6 @@ { "name": "@mojaloop/finance-portal-backend-service", - "version": "0.0.2", + "version": "8.8.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/package.json b/src/package.json index 275953b..065ff4c 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "@mojaloop/finance-portal-backend-service", - "version": "8.8.6", + "version": "8.8.7", "description": "The backend service to support the finance portal web ui. Essentially a thin wrapper around SQL queries.", "license": "Apache-2.0", "contributors": [