-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebdea77
commit 08c4dba
Showing
11 changed files
with
148 additions
and
4 deletions.
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
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
const paths = require('@root/paths') | ||
const formatSimplifiedAccountPathsFor = require('@utils/simplified-account/format/format-simplified-account-paths-for') | ||
const { response } = require('@utils/response') | ||
const { getKeyByTokenLink } = 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) | ||
}) | ||
} | ||
|
||
module.exports = { get } |
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
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 ACCOUNT_TYPE = 'live' | ||
const SERVICE_ID = 'service-id-123abc' | ||
const mockResponse = sinon.spy() | ||
const TOKEN_LINK = '550e8400-e29b-41d4-a716-446655440000' | ||
const token = { | ||
description: 'token description', | ||
token_link: TOKEN_LINK | ||
} | ||
const apiKeysService = { | ||
getKeyByTokenLink: sinon.stub().resolves(token) | ||
} | ||
|
||
const { | ||
req, | ||
res, | ||
nextRequest, | ||
call | ||
} = new ControllerTestBuilder('@controllers/simplified-account/settings/api-keys/revoke/revoke.controller') | ||
.withServiceExternalId(SERVICE_ID) | ||
.withAccountType(ACCOUNT_TYPE) | ||
.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 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) | ||
}) | ||
}) | ||
}) | ||
}) |
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