diff --git a/.secrets.baseline b/.secrets.baseline index edd3e5d839..9d27348a07 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "package-lock.json", "lines": null }, - "generated_at": "2021-01-18T10:18:13Z", + "generated_at": "2021-01-18T11:24:19Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -150,21 +150,21 @@ "hashed_secret": "d0be4e729498f4cfe8a72a28d4fceae35bd8bb27", "is_secret": false, "is_verified": false, - "line_number": 14, + "line_number": 16, "type": "Secret Keyword" }, { "hashed_secret": "2c877f34a0f47f32a5f3c77e398938b3cdc32221", "is_secret": false, "is_verified": false, - "line_number": 19, + "line_number": 21, "type": "Secret Keyword" }, { "hashed_secret": "379f1968f09d8a343338667844e01a2f433f0a3f", "is_secret": false, "is_verified": false, - "line_number": 23, + "line_number": 25, "type": "Hex High Entropy String" } ], @@ -232,14 +232,14 @@ "hashed_secret": "0ea7458942ab65e0a340cf4fd28ca00d93c494f3", "is_secret": false, "is_verified": false, - "line_number": 502, + "line_number": 513, "type": "Secret Keyword" }, { "hashed_secret": "1695899a3d59e9fe2af1cdf242d8c451b8506173", "is_secret": false, "is_verified": false, - "line_number": 546, + "line_number": 556, "type": "Secret Keyword" } ], diff --git a/app/controllers/credentials.controller.js b/app/controllers/credentials.controller.js index 149ee38655..d5ab40efde 100644 --- a/app/controllers/credentials.controller.js +++ b/app/controllers/credentials.controller.js @@ -3,10 +3,10 @@ const EDIT_NOTIFICATION_CREDENTIALS_MODE = 'editNotificationCredentials' const _ = require('lodash') const paths = require('../paths') +const formatAccountPathsFor = require('../utils/format-account-paths-for') const { response } = require('../utils/response') const { renderErrorView } = require('../utils/response') const { ConnectorClient } = require('../services/clients/connector.client') -const router = require('../routes') const { CONNECTOR_URL } = process.env const { CORRELATION_HEADER } = require('../utils/correlation-header') const { isPasswordLessThanTenChars } = require('../browsered/field-validation-checks') @@ -109,7 +109,7 @@ module.exports = { gatewayAccountId: accountId }) - return res.redirect(303, router.paths.yourPsp.index) + return res.redirect(303, formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id)) } catch (err) { return renderErrorView(req, res) } @@ -124,7 +124,7 @@ module.exports = { payload: credentialsPatchRequestValueOf(req), correlationId: correlationId, gatewayAccountId: accountId }) - return res.redirect(303, router.paths.yourPsp.index) + return res.redirect(303, formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id)) } catch (err) { return renderErrorView(req, res) } diff --git a/app/controllers/your-psp/post-flex.controller.js b/app/controllers/your-psp/post-flex.controller.js index f0a5c84b83..a2ccd713d9 100644 --- a/app/controllers/your-psp/post-flex.controller.js +++ b/app/controllers/your-psp/post-flex.controller.js @@ -3,6 +3,7 @@ const lodash = require('lodash') const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const { renderErrorView } = require('../../utils/response') const { ConnectorClient } = require('../../services/clients/connector.client') const { correlationHeader } = require('../../utils/correlation-header') @@ -17,8 +18,9 @@ const JWT_MAC_KEY_FIELD = 'jwt-mac-key' module.exports = async (req, res) => { const correlationId = req.headers[correlationHeader] || '' - const accountId = req.account.gateway_account_id + const flexUrl = formatAccountPathsFor(paths.account.yourPsp.flex, req.account && req.account.external_id) + const indexUrl = formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id) const orgUnitId = lodash.get(req.body, ORGANISATIONAL_UNIT_ID_FIELD, '').trim() const issuer = lodash.get(req.body, ISSUER_FIELD, '').trim() @@ -32,7 +34,7 @@ module.exports = async (req, res) => { orgUnitId: orgUnitId, issuer: issuer }) - return res.redirect(303, paths.yourPsp.flex) + return res.redirect(303, flexUrl) } try { @@ -58,7 +60,7 @@ module.exports = async (req, res) => { orgUnitId: orgUnitId, issuer: issuer }) - return res.redirect(303, paths.yourPsp.flex) + return res.redirect(303, flexUrl) } } @@ -68,7 +70,7 @@ module.exports = async (req, res) => { await connector.post3dsFlexAccountCredentials(flexParams) req.flash('generic', 'Your Worldpay 3DS Flex settings have been updated') - return res.redirect(paths.yourPsp.index) + return res.redirect(indexUrl) } catch (error) { return renderErrorView(req, res, false, error.errorCode) } diff --git a/app/controllers/your-psp/post-toggle-worldpay-3ds-flex.controller.js b/app/controllers/your-psp/post-toggle-worldpay-3ds-flex.controller.js index c04ad73f18..68933109e9 100644 --- a/app/controllers/your-psp/post-toggle-worldpay-3ds-flex.controller.js +++ b/app/controllers/your-psp/post-toggle-worldpay-3ds-flex.controller.js @@ -1,6 +1,7 @@ 'use strict' const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const { renderErrorView } = require('../../utils/response') const { ConnectorClient } = require('../../services/clients/connector.client') const connector = new ConnectorClient(process.env.CONNECTOR_URL) @@ -8,6 +9,7 @@ const connector = new ConnectorClient(process.env.CONNECTOR_URL) module.exports = async function toggleWorldpay3dsFlex (req, res) { const accountId = req.account.gateway_account_id const toggleWorldpay3dsFlex = req.body['toggle-worldpay-3ds-flex'] + const indexUrl = formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id) if (req.body['toggle-worldpay-3ds-flex'] === 'on' || req.body['toggle-worldpay-3ds-flex'] === 'off') { const enabling3dsFlex = toggleWorldpay3dsFlex === 'on' @@ -16,7 +18,7 @@ module.exports = async function toggleWorldpay3dsFlex (req, res) { try { await connector.updateIntegrationVersion3ds(accountId, integrationVersion3ds, req.correlationId) req.flash('generic', message) - return res.redirect(303, paths.yourPsp.index) + return res.redirect(303, indexUrl) } catch (error) { return renderErrorView(req, res, false, error.errorCode) } diff --git a/app/controllers/your-psp/post-toggle-worldpay-3ds-flex.controller.test.js b/app/controllers/your-psp/post-toggle-worldpay-3ds-flex.controller.test.js index 5d0483ef11..9c0c86e62d 100644 --- a/app/controllers/your-psp/post-toggle-worldpay-3ds-flex.controller.test.js +++ b/app/controllers/your-psp/post-toggle-worldpay-3ds-flex.controller.test.js @@ -2,9 +2,9 @@ const proxyquire = require('proxyquire') const sinon = require('sinon') -const paths = require('../../paths') describe('Toggle Worldpay 3DS Flex controller', () => { + const gatewayAccountExternalId = 'a-gateway-account-external-id' let req let res let updateIntegrationVersion3dsMock @@ -14,7 +14,8 @@ describe('Toggle Worldpay 3DS Flex controller', () => { req = { correlationId: 'correlation-id', account: { - gateway_account_id: '1' + gateway_account_id: '1', + external_id: gatewayAccountExternalId }, flash: sinon.spy(), body: {} @@ -36,7 +37,7 @@ describe('Toggle Worldpay 3DS Flex controller', () => { sinon.assert.calledWith(updateIntegrationVersion3dsMock, req.account.gateway_account_id, 2, req.correlationId) sinon.assert.calledWith(req.flash, 'generic', '3DS Flex has been turned on.') - sinon.assert.calledWith(res.redirect, 303, paths.yourPsp.index) + sinon.assert.calledWith(res.redirect, 303, `/account/${gatewayAccountExternalId}/your-psp`) }) it('should toggle 3DS Flex off by setting 3DS integration version to 1', async () => { @@ -48,7 +49,7 @@ describe('Toggle Worldpay 3DS Flex controller', () => { sinon.assert.calledWith(updateIntegrationVersion3dsMock, req.account.gateway_account_id, 1, req.correlationId) sinon.assert.calledWith(req.flash, 'generic', '3DS Flex has been turned off. Your payments will now use 3DS only.') - sinon.assert.calledWith(res.redirect, 303, paths.yourPsp.index) + sinon.assert.calledWith(res.redirect, 303, `/account/${gatewayAccountExternalId}/your-psp`) }) it('should render an error if problem calling connector', async () => { diff --git a/app/paths.js b/app/paths.js index 6b624dee12..609d58e56a 100644 --- a/app/paths.js +++ b/app/paths.js @@ -12,6 +12,13 @@ module.exports = { keys, account: { root: `/account/:${keys.GATEWAY_ACCOUNT_EXTERNAL_ID}`, + apiKeys: { + index: '/api-keys', + revoked: '/api-keys/revoked', + create: '/api-keys/create', + revoke: '/api-keys/revoke', + update: '/api-keys/update' + }, digitalWallet: { applePay: '/digital-wallet/apple-pay', googlePay: '/digital-wallet/google-pay' @@ -44,12 +51,10 @@ module.exports = { cardNumber: '/moto-hide-card-number', securityCode: '/moto-hide-security-code' }, - apiKeys: { - index: '/api-keys', - revoked: '/api-keys/revoked', - create: '/api-keys/create', - revoke: '/api-keys/revoke', - update: '/api-keys/update' + yourPsp: { + index: '/your-psp', + flex: '/your-psp/flex', + worldpay3dsFlex: '/your-psp/worldpay-3ds-flex' } }, transactions: { @@ -63,11 +68,6 @@ module.exports = { index: '/all-service-transactions', download: '/all-service-transactions/download' }, - yourPsp: { - index: '/your-psp', - flex: '/your-psp/flex', - worldpay3dsFlex: '/your-psp/worldpay-3ds-flex' - }, credentials: { index: '/credentials', edit: '/credentials/edit', diff --git a/app/routes.js b/app/routes.js index b8fcf8c4a4..8d94c52724 100644 --- a/app/routes.js +++ b/app/routes.js @@ -90,7 +90,7 @@ const { serviceSwitcher, teamMembers, staticPaths, inviteValidation, editServiceName, merchantDetails, notificationCredentials, prototyping, paymentLinks, requestToGoLive, policyPages, stripeSetup, stripe, - yourPsp, allServiceTransactions, payouts + allServiceTransactions, payouts } = paths const { apiKeys, @@ -100,7 +100,8 @@ const { settings, toggle3ds, toggleBillingAddress, - toggleMotoMaskCardNumberAndSecurityCode + toggleMotoMaskCardNumberAndSecurityCode, + yourPsp } = paths.account // Exports @@ -180,7 +181,6 @@ module.exports.bind = function (app) { ...lodash.values(allServiceTransactions), ...lodash.values(credentials), ...lodash.values(notificationCredentials), - ...lodash.values(apiKeys), ...lodash.values(editServiceName), ...lodash.values(serviceSwitcher), ...lodash.values(teamMembers), @@ -193,7 +193,6 @@ module.exports.bind = function (app) { ...lodash.values(policyPages), ...lodash.values(stripeSetup), ...lodash.values(stripe), - ...lodash.values(yourPsp), ...lodash.values(payouts), paths.feedback ] // Extract all the authenticated paths as a single array @@ -285,11 +284,6 @@ module.exports.bind = function (app) { account.get(settings.index, permission('transactions-details:read'), settingsController.index) // Your PSP - app.get(yourPsp.index, permission('gateway-credentials:read'), getAccount, paymentMethodIsCard, yourPspController.getIndex) - app.post(yourPsp.worldpay3dsFlex, permission('toggle-3ds:update'), getAccount, paymentMethodIsCard, yourPspController.postToggleWorldpay3dsFlex) - app.get(yourPsp.flex, permission('gateway-credentials:update'), getAccount, paymentMethodIsCard, yourPspController.getFlex) - app.post(yourPsp.flex, permission('gateway-credentials:update'), getAccount, paymentMethodIsCard, yourPspController.postFlex) - account.get(yourPsp.index, permission('gateway-credentials:read'), paymentMethodIsCard, yourPspController.getIndex) account.post(yourPsp.worldpay3dsFlex, permission('toggle-3ds:update'), paymentMethodIsCard, yourPspController.postToggleWorldpay3dsFlex) account.get(yourPsp.flex, permission('gateway-credentials:update'), paymentMethodIsCard, yourPspController.getFlex) diff --git a/app/utils/nav-builder.js b/app/utils/nav-builder.js index deff51746d..a23528ecef 100644 --- a/app/utils/nav-builder.js +++ b/app/utils/nav-builder.js @@ -16,7 +16,7 @@ const mainSettingsPaths = [ ] const yourPspPaths = [ - paths.yourPsp, + paths.account.yourPsp, paths.credentials, paths.notificationCredentials ] @@ -89,7 +89,7 @@ const adminNavigationItems = (currentPath, permissions, type, paymentProvider, a { id: 'navigation-menu-your-psp', name: `Your PSP - ${formatPSPname(paymentProvider)}`, - url: paths.yourPsp.index, + url: formatAccountPathsFor(paths.account.yourPsp.index, account.external_id), current: pathLookup(currentPath, yourPspPaths), permissions: permissions.gateway_credentials_update && type === 'card' && (paymentProvider !== 'stripe') && (paymentProvider !== 'sandbox') }, diff --git a/app/views/credentials/worldpay.njk b/app/views/credentials/worldpay.njk index f1ec6a8e7e..ff7b825a29 100644 --- a/app/views/credentials/worldpay.njk +++ b/app/views/credentials/worldpay.njk @@ -113,7 +113,7 @@
{% endif %} {% endblock %} diff --git a/app/views/your-psp/_worldpay-flex.njk b/app/views/your-psp/_worldpay-flex.njk index c95a312dd7..84d57a60d0 100644 --- a/app/views/your-psp/_worldpay-flex.njk +++ b/app/views/your-psp/_worldpay-flex.njk @@ -29,7 +29,7 @@ actions: { items: [ { - href: routes.yourPsp.flex + "?change=organisationalUnitId", + href: formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) + "?change=organisationalUnitId", text: "Change", visuallyHiddenText: "3DS Flex credentials", attributes: { @@ -50,7 +50,7 @@ actions: { items: [ { - href: routes.yourPsp.flex + "?change=issuer", + href: formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) + "?change=issuer", text: "Change", visuallyHiddenText: "3DS Flex credentials" } @@ -68,7 +68,7 @@ actions: { items: [ { - href: routes.yourPsp.flex + "?change=password", + href: formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) + "?change=password", text: "Change", visuallyHiddenText: "3DS Flex credentials" } @@ -80,7 +80,7 @@ }} {% if (is3dsEnabled and isWorldpay3dsFlexCredentialsConfigured) or isWorldpay3dsFlexEnabled %} -