diff --git a/.secrets.baseline b/.secrets.baseline index 9d27348a07..edd3e5d839 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "package-lock.json", "lines": null }, - "generated_at": "2021-01-18T11:24:19Z", + "generated_at": "2021-01-18T10:18:13Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -150,21 +150,21 @@ "hashed_secret": "d0be4e729498f4cfe8a72a28d4fceae35bd8bb27", "is_secret": false, "is_verified": false, - "line_number": 16, + "line_number": 14, "type": "Secret Keyword" }, { "hashed_secret": "2c877f34a0f47f32a5f3c77e398938b3cdc32221", "is_secret": false, "is_verified": false, - "line_number": 21, + "line_number": 19, "type": "Secret Keyword" }, { "hashed_secret": "379f1968f09d8a343338667844e01a2f433f0a3f", "is_secret": false, "is_verified": false, - "line_number": 25, + "line_number": 23, "type": "Hex High Entropy String" } ], @@ -232,14 +232,14 @@ "hashed_secret": "0ea7458942ab65e0a340cf4fd28ca00d93c494f3", "is_secret": false, "is_verified": false, - "line_number": 513, + "line_number": 502, "type": "Secret Keyword" }, { "hashed_secret": "1695899a3d59e9fe2af1cdf242d8c451b8506173", "is_secret": false, "is_verified": false, - "line_number": 556, + "line_number": 546, "type": "Secret Keyword" } ], diff --git a/app/controllers/credentials.controller.js b/app/controllers/credentials.controller.js index d5ab40efde..149ee38655 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, formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id)) + return res.redirect(303, router.paths.yourPsp.index) } catch (err) { return renderErrorView(req, res) } @@ -124,7 +124,7 @@ module.exports = { payload: credentialsPatchRequestValueOf(req), correlationId: correlationId, gatewayAccountId: accountId }) - return res.redirect(303, formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id)) + return res.redirect(303, router.paths.yourPsp.index) } 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 a2ccd713d9..f0a5c84b83 100644 --- a/app/controllers/your-psp/post-flex.controller.js +++ b/app/controllers/your-psp/post-flex.controller.js @@ -3,7 +3,6 @@ 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') @@ -18,9 +17,8 @@ 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() @@ -34,7 +32,7 @@ module.exports = async (req, res) => { orgUnitId: orgUnitId, issuer: issuer }) - return res.redirect(303, flexUrl) + return res.redirect(303, paths.yourPsp.flex) } try { @@ -60,7 +58,7 @@ module.exports = async (req, res) => { orgUnitId: orgUnitId, issuer: issuer }) - return res.redirect(303, flexUrl) + return res.redirect(303, paths.yourPsp.flex) } } @@ -70,7 +68,7 @@ module.exports = async (req, res) => { await connector.post3dsFlexAccountCredentials(flexParams) req.flash('generic', 'Your Worldpay 3DS Flex settings have been updated') - return res.redirect(indexUrl) + return res.redirect(paths.yourPsp.index) } 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 68933109e9..c04ad73f18 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,7 +1,6 @@ '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) @@ -9,7 +8,6 @@ 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' @@ -18,7 +16,7 @@ module.exports = async function toggleWorldpay3dsFlex (req, res) { try { await connector.updateIntegrationVersion3ds(accountId, integrationVersion3ds, req.correlationId) req.flash('generic', message) - return res.redirect(303, indexUrl) + return res.redirect(303, paths.yourPsp.index) } 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 9c0c86e62d..5d0483ef11 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,8 +14,7 @@ describe('Toggle Worldpay 3DS Flex controller', () => { req = { correlationId: 'correlation-id', account: { - gateway_account_id: '1', - external_id: gatewayAccountExternalId + gateway_account_id: '1' }, flash: sinon.spy(), body: {} @@ -37,7 +36,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, `/account/${gatewayAccountExternalId}/your-psp`) + sinon.assert.calledWith(res.redirect, 303, paths.yourPsp.index) }) it('should toggle 3DS Flex off by setting 3DS integration version to 1', async () => { @@ -49,7 +48,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, `/account/${gatewayAccountExternalId}/your-psp`) + sinon.assert.calledWith(res.redirect, 303, paths.yourPsp.index) }) it('should render an error if problem calling connector', async () => { diff --git a/app/paths.js b/app/paths.js index 609d58e56a..6b624dee12 100644 --- a/app/paths.js +++ b/app/paths.js @@ -12,13 +12,6 @@ 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' @@ -51,10 +44,12 @@ module.exports = { cardNumber: '/moto-hide-card-number', securityCode: '/moto-hide-security-code' }, - yourPsp: { - index: '/your-psp', - flex: '/your-psp/flex', - worldpay3dsFlex: '/your-psp/worldpay-3ds-flex' + apiKeys: { + index: '/api-keys', + revoked: '/api-keys/revoked', + create: '/api-keys/create', + revoke: '/api-keys/revoke', + update: '/api-keys/update' } }, transactions: { @@ -68,6 +63,11 @@ 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 8d94c52724..b8fcf8c4a4 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, - allServiceTransactions, payouts + yourPsp, allServiceTransactions, payouts } = paths const { apiKeys, @@ -100,8 +100,7 @@ const { settings, toggle3ds, toggleBillingAddress, - toggleMotoMaskCardNumberAndSecurityCode, - yourPsp + toggleMotoMaskCardNumberAndSecurityCode } = paths.account // Exports @@ -181,6 +180,7 @@ 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,6 +193,7 @@ 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 @@ -284,6 +285,11 @@ 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 a23528ecef..deff51746d 100644 --- a/app/utils/nav-builder.js +++ b/app/utils/nav-builder.js @@ -16,7 +16,7 @@ const mainSettingsPaths = [ ] const yourPspPaths = [ - paths.account.yourPsp, + paths.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: formatAccountPathsFor(paths.account.yourPsp.index, account.external_id), + url: paths.yourPsp.index, 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 ff7b825a29..f1ec6a8e7e 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 84d57a60d0..c95a312dd7 100644 --- a/app/views/your-psp/_worldpay-flex.njk +++ b/app/views/your-psp/_worldpay-flex.njk @@ -29,7 +29,7 @@ actions: { items: [ { - href: formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) + "?change=organisationalUnitId", + href: routes.yourPsp.flex + "?change=organisationalUnitId", text: "Change", visuallyHiddenText: "3DS Flex credentials", attributes: { @@ -50,7 +50,7 @@ actions: { items: [ { - href: formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) + "?change=issuer", + href: routes.yourPsp.flex + "?change=issuer", text: "Change", visuallyHiddenText: "3DS Flex credentials" } @@ -68,7 +68,7 @@ actions: { items: [ { - href: formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) + "?change=password", + href: routes.yourPsp.flex + "?change=password", text: "Change", visuallyHiddenText: "3DS Flex credentials" } @@ -80,7 +80,7 @@ }} {% if (is3dsEnabled and isWorldpay3dsFlexCredentialsConfigured) or isWorldpay3dsFlexEnabled %} -