generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Haar 1905 create new base client journey (#29)
* add tests for list base clients page * add view base client page * Fix errors in template * basic view for create new base client screen * post new base client with error loop * added controller tests * add tests for presenter * add test for expiry today * correct test comments and refactor time functions
- Loading branch information
1 parent
6d13bd5
commit 9880e45
Showing
21 changed files
with
856 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// For guidance on how to add JavaScript see: | ||
// https://prototype-kit.service.gov.uk/docs/adding-css-javascript-and-images | ||
// | ||
function showDiv(divId, element, val) { | ||
document.getElementById(divId).style.display = element.value === val ? 'block' : 'none' | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function (event) { | ||
const select = document.getElementById('access-token-validity') | ||
select.onchange = () => showDiv('custom-access-token-validity-element', select, 'custom') | ||
showDiv('custom-access-token-validity-element', select, 'custom') | ||
}) |
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import { BaseClient } from '../../interfaces/baseClientApi/baseClient' | ||
import { AddBaseClientRequest } from '../../interfaces/baseClientApi/baseClientRequestBody' | ||
import { daysRemaining } from '../../utils/utils' | ||
|
||
export default (baseClient: BaseClient): AddBaseClientRequest => { | ||
// valid days is calculated from expiry date | ||
const expiryDate = baseClient.config.expiryDate ? new Date(baseClient.config.expiryDate) : null | ||
|
||
return { | ||
clientId: baseClient.baseClientId, | ||
scopes: ['read', 'write'], | ||
authorities: ['ROLE_CLIENT_CREDENTIALS'], | ||
ips: [], | ||
scopes: baseClient.scopes, | ||
authorities: baseClient.clientCredentials.authorities, | ||
ips: baseClient.config.allowedIPs, | ||
jiraNumber: baseClient.audit, | ||
databaseUserName: baseClient.clientCredentials.databaseUserName, | ||
validDays: expiryDate ? Math.ceil(expiryDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24) : null, | ||
validDays: baseClient.config.expiryDate ? daysRemaining(baseClient.config.expiryDate) : null, | ||
accessTokenValidityMinutes: baseClient.accessTokenValidity ? baseClient.accessTokenValidity / 60 : null, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import { BaseClient } from '../../interfaces/baseClientApi/baseClient' | ||
import { UpdateBaseClientRequest } from '../../interfaces/baseClientApi/baseClientRequestBody' | ||
import { daysRemaining } from '../../utils/utils' | ||
|
||
export default (baseClient: BaseClient): UpdateBaseClientRequest => { | ||
// valid days is calculated from expiry date | ||
const expiryDate = baseClient.config.expiryDate ? new Date(baseClient.config.expiryDate) : null | ||
|
||
return { | ||
scopes: ['read', 'write'], | ||
authorities: ['ROLE_CLIENT_CREDENTIALS'], | ||
ips: [], | ||
jiraNumber: baseClient.audit, | ||
databaseUserName: baseClient.clientCredentials.databaseUserName, | ||
validDays: expiryDate ? Math.ceil(expiryDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24) : null, | ||
validDays: baseClient.config.expiryDate ? daysRemaining(baseClient.config.expiryDate) : null, | ||
accessTokenValidityMinutes: baseClient.accessTokenValidity ? baseClient.accessTokenValidity / 60 : null, | ||
} | ||
} |
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,73 @@ | ||
import type { Request } from 'express' | ||
import { BaseClient } from '../../interfaces/baseClientApi/baseClient' | ||
import { multiSeparatorSplit } from '../../utils/utils' | ||
|
||
function getDayOfExpiry(daysRemaining: string) { | ||
const daysRemainingInt = parseIntWithDefault(daysRemaining, 0) | ||
const timeOfExpiry: Date = new Date(Date.now() + daysRemainingInt * 24 * 60 * 60 * 1000) | ||
return timeOfExpiry.toISOString().split('T')[0] | ||
} | ||
|
||
function getAccessTokenValiditySeconds(accessTokenValidity: string, customAccessTokenValidity?: string) { | ||
if (accessTokenValidity === 'custom' && customAccessTokenValidity) { | ||
return parseIntWithDefault(customAccessTokenValidity, 0) | ||
} | ||
return parseIntWithDefault(accessTokenValidity, 0) | ||
} | ||
|
||
function parseIntWithDefault(value: string, defaultValue: number) { | ||
const parsed = parseInt(value, 10) | ||
return Number.isNaN(parsed) ? defaultValue : parsed | ||
} | ||
|
||
export default (request: Request): BaseClient => { | ||
// valid days is calculated from expiry date | ||
const data = request.body | ||
|
||
const { accessTokenValidity, customAccessTokenValidity } = data | ||
const accessTokenValiditySeconds = getAccessTokenValiditySeconds(accessTokenValidity, customAccessTokenValidity) | ||
const dayOfExpiry = data.expiry ? getDayOfExpiry(data.expiryDays) : null | ||
|
||
return { | ||
baseClientId: data.baseClientId, | ||
clientType: data.clientType, | ||
accessTokenValidity: accessTokenValiditySeconds, | ||
scopes: multiSeparatorSplit(data.approvedScopes, [',', '\r\n', '\n']), | ||
audit: data.audit, | ||
count: 1, | ||
grantType: data.grant, | ||
clientCredentials: { | ||
authorities: multiSeparatorSplit(data.authorities, [',', '\r\n', '\n']), | ||
databaseUserName: data.databaseUserName, | ||
}, | ||
authorisationCode: { | ||
registeredRedirectURIs: [], | ||
jwtFields: '', | ||
azureAdLoginFlow: false, | ||
}, | ||
service: { | ||
serviceName: '', | ||
description: '', | ||
authorisedRoles: [], | ||
url: '', | ||
contact: '', | ||
status: '', | ||
}, | ||
deployment: { | ||
team: '', | ||
teamContact: '', | ||
teamSlack: '', | ||
hosting: '', | ||
namespace: '', | ||
deployment: '', | ||
secretName: '', | ||
clientIdKey: '', | ||
secretKey: '', | ||
deploymentInfo: '', | ||
}, | ||
config: { | ||
allowedIPs: multiSeparatorSplit(data.allowedIPs, [',', '\r\n', '\n']), | ||
expiryDate: dayOfExpiry, | ||
}, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Factory } from 'fishery' | ||
import { faker } from '@faker-js/faker' | ||
import { ClientSecrets } from '../../interfaces/baseClientApi/baseClient' | ||
|
||
export default Factory.define<ClientSecrets>(() => ({ | ||
clientId: faker.string.uuid(), | ||
clientSecret: faker.string.uuid(), | ||
base64ClientId: faker.string.uuid(), | ||
base64ClientSecret: faker.string.uuid(), | ||
})) |
Oops, something went wrong.