-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PP-12395: Revoke key functionality #4400
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/controllers/simplified-account/settings/api-keys/revoke/revoke.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const paths = require('@root/paths') | ||
const formatSimplifiedAccountPathsFor = require('@utils/simplified-account/format/format-simplified-account-paths-for') | ||
const { response } = require('@utils/response') | ||
const { getKeyByTokenLink, revokeKey } = require('@services/api-keys.service') | ||
|
||
async function get (req, res) { | ||
const tokenLink = req.params.tokenLink | ||
const apiKey = await getKeyByTokenLink(req.account.id, tokenLink) | ||
return response(req, res, 'simplified-account/settings/api-keys/revoke', { | ||
description: apiKey.description, | ||
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.apiKeys.index, req.service.externalId, req.account.type) | ||
}) | ||
} | ||
|
||
async function post (req, res) { | ||
if (req.body.revokeApiKey === 'Yes') { // pragma: allowlist secret | ||
await revokeKey(req.account.id, req.params.tokenLink) | ||
} | ||
res.redirect(formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.apiKeys.index, req.service.externalId, req.account.type)) | ||
} | ||
|
||
module.exports = { get, post } |
121 changes: 121 additions & 0 deletions
121
app/controllers/simplified-account/settings/api-keys/revoke/revoke.controller.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
const ControllerTestBuilder = require('@test/test-helpers/simplified-account/controllers/ControllerTestBuilder.class') | ||
const sinon = require('sinon') | ||
const { expect } = require('chai') | ||
const formatSimplifiedAccountPathsFor = require('@utils/simplified-account/format/format-simplified-account-paths-for') | ||
const paths = require('@root/paths') | ||
const GatewayAccount = require('@models/GatewayAccount.class') | ||
|
||
const ACCOUNT_TYPE = 'live' | ||
const SERVICE_ID = 'service-id-123abc' | ||
const TOKEN_LINK = '550e8400-e29b-41d4-a716-446655440000' | ||
const GATEWAY_ACCOUNT_ID = 1 | ||
const mockResponse = sinon.spy() | ||
const token = { | ||
description: 'token description', | ||
token_link: TOKEN_LINK | ||
} | ||
const apiKeysService = { | ||
getKeyByTokenLink: sinon.stub().resolves(token), | ||
revokeKey: sinon.stub().resolves() | ||
} | ||
|
||
const { | ||
req, | ||
res, | ||
nextRequest, | ||
call | ||
} = new ControllerTestBuilder('@controllers/simplified-account/settings/api-keys/revoke/revoke.controller') | ||
.withServiceExternalId(SERVICE_ID) | ||
.withAccount(new GatewayAccount({ | ||
type: ACCOUNT_TYPE, | ||
gateway_account_id: GATEWAY_ACCOUNT_ID | ||
})) | ||
.withStubs({ | ||
'@utils/response': { response: mockResponse }, | ||
'@services/api-keys.service': apiKeysService | ||
}) | ||
.build() | ||
|
||
describe('Controller: settings/api-keys/revoke', () => { | ||
describe('get', () => { | ||
before(() => { | ||
nextRequest({ | ||
params: { | ||
tokenLink: TOKEN_LINK | ||
} | ||
}) | ||
call('get') | ||
}) | ||
|
||
it('should call apiKeysService.getKeyByTokenLink', () => { | ||
expect(apiKeysService.getKeyByTokenLink).to.have.been.calledWith(GATEWAY_ACCOUNT_ID, TOKEN_LINK) | ||
}) | ||
|
||
it('should call the response method', () => { | ||
expect(mockResponse).to.have.been.calledOnce // eslint-disable-line | ||
}) | ||
|
||
it('should pass req, res, template path and context to the response method', () => { | ||
expect(mockResponse).to.have.been.calledWith( | ||
{ ...req, params: { tokenLink: TOKEN_LINK } }, | ||
res, | ||
'simplified-account/settings/api-keys/revoke', | ||
{ | ||
description: token.description, | ||
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.apiKeys.index, SERVICE_ID, ACCOUNT_TYPE) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('post', () => { | ||
describe('when No is selected', () => { | ||
before(() => { | ||
nextRequest({ | ||
body: { | ||
revokeApiKey: 'No' | ||
}, | ||
params: { | ||
tokenLink: TOKEN_LINK | ||
} | ||
}) | ||
call('post') | ||
}) | ||
|
||
it('should not call apiKeysService.revokeKey', () => { | ||
sinon.assert.notCalled(apiKeysService.revokeKey) | ||
}) | ||
|
||
it('should redirect to the api keys index page', () => { | ||
expect(res.redirect.calledOnce).to.be.true // eslint-disable-line | ||
expect(res.redirect.args[0][0]).to.include( | ||
formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.apiKeys.index, SERVICE_ID, ACCOUNT_TYPE) | ||
) | ||
}) | ||
}) | ||
|
||
describe('when Yes is selected', () => { | ||
before(() => { | ||
nextRequest({ | ||
body: { | ||
revokeApiKey: 'Yes' // pragma: allowlist secret | ||
}, | ||
params: { | ||
tokenLink: TOKEN_LINK | ||
} | ||
}) | ||
call('post') | ||
}) | ||
|
||
it('should call apiKeysService.revokeKey', () => { | ||
expect(apiKeysService.revokeKey).to.have.been.calledWith(GATEWAY_ACCOUNT_ID, TOKEN_LINK) | ||
}) | ||
|
||
it('should redirect to the api keys index page', () => { | ||
expect(res.redirect.calledOnce).to.be.true // eslint-disable-line | ||
expect(res.redirect.args[0][0]).to.include( | ||
formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.apiKeys.index, SERVICE_ID, ACCOUNT_TYPE) | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ | |
text: 'Change name' | ||
}, | ||
{ | ||
href: '#', | ||
href: key.revokeKeyLink, | ||
text: 'Revoke' | ||
} | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% extends "../settings-layout.njk" %} | ||
|
||
{% block settingsPageTitle %} | ||
API keys - revoke key | ||
{% endblock %} | ||
|
||
{% block settingsContent %} | ||
<form id="revoke-api-key" method="post" novalidate> | ||
<input id="csrf" name="csrfToken" type="hidden" value="{{ csrf }}"/> | ||
|
||
{{ govukRadios({ | ||
name: 'revokeApiKey', | ||
fieldset: { | ||
legend: { | ||
text: 'Are you sure you want to revoke ' + description, | ||
isPageHeading: true, | ||
classes: 'govuk-fieldset__legend--l govuk-!-font-weight-bold' | ||
} | ||
}, | ||
hint: { | ||
text: 'The key will stop working immediately. Any integration you’ve created will no longer work.' | ||
}, | ||
items: [ | ||
{ | ||
value: 'Yes', | ||
text: 'Yes' | ||
}, | ||
{ | ||
value: 'No', | ||
text: 'No' | ||
} | ||
] | ||
}) }} | ||
{{ govukButton({ | ||
text: 'Save changes' | ||
}) }} | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The figma says there should be a success notification if the key is revoked so something like [this] maybe?(
pay-selfservice/app/controllers/simplified-account/settings/team-members/invite/invite.controller.js
Line 55 in ebdea77