Skip to content

Commit 848d27d

Browse files
authored
Fix: [AEA-0000] - remove uuid (#1367)
## Summary - Routine Change ### Details - remove uuid
1 parent ad71cf4 commit 848d27d

File tree

18 files changed

+67
-73
lines changed

18 files changed

+67
-73
lines changed

.vscode/eps-prescription-tracker-ui.code-workspace

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@
176176
"Truststore",
177177
"URID",
178178
"URPID",
179-
"uuidv4",
180179
"vars",
181180
"venv",
182181
"versionable",

package-lock.json

Lines changed: 38 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cognito/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
"aws-lambda": "^1.0.7",
2727
"axios": "^1.12.2",
2828
"jsonwebtoken": "^9.0.2",
29-
"jwks-rsa": "^3.2.0",
30-
"uuid": "11.1.0"
29+
"jwks-rsa": "^3.2.0"
3130
},
3231
"devDependencies": {
3332
"@types/aws-lambda": "^8.10.152",

packages/cognito/src/helpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Logger} from "@aws-lambda-powertools/logger"
22
import jwt from "jsonwebtoken"
33
import {ParsedUrlQuery} from "querystring"
4-
import {v4 as uuidv4} from "uuid"
54

65
export function rewriteRequestBody(
76
logger: Logger,
@@ -23,7 +22,7 @@ export function rewriteRequestBody(
2322
"aud": idpTokenPath,
2423
"iat": current_time,
2524
"exp": expiration_time,
26-
"jti": uuidv4()
25+
"jti": crypto.randomUUID()
2726
}
2827

2928
const signOptions: jwt.SignOptions = {

packages/cognito/src/tokenMock.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {PrivateKey} from "jsonwebtoken"
1111
import {exchangeTokenForApigeeAccessToken, fetchUserInfo, initializeOidcConfig} from "@cpt-ui-common/authFunctions"
1212
import {insertTokenMapping, getSessionState, tryGetTokenMapping} from "@cpt-ui-common/dynamoFunctions"
1313
import {MiddyErrorHandler} from "@cpt-ui-common/middyErrorHandler"
14-
import {v4 as uuidv4} from "uuid"
1514
import jwt from "jsonwebtoken"
1615
import axios from "axios"
1716

@@ -122,7 +121,7 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro
122121
const current_time = Math.floor(Date.now() / 1000)
123122
const expirationTime = current_time + 600
124123
const baseUsername = userInfoResponse.user_details.sub
125-
const sessionId = uuidv4()
124+
const sessionId = crypto.randomUUID()
126125

127126
const jwtClaims = {
128127
exp: expirationTime,

packages/common/authFunctions/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"@middy/core": "^6.4.5",
2626
"aws-lambda": "^1.0.7",
2727
"jsonwebtoken": "^9.0.2",
28-
"jwks-rsa": "^3.2.0",
29-
"uuid": "^11.1.0"
28+
"jwks-rsa": "^3.2.0"
3029
}
3130
}

packages/common/authFunctions/src/apigee.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {Logger} from "@aws-lambda-powertools/logger"
22
import jwt from "jsonwebtoken"
3-
import {v4 as uuidv4} from "uuid"
43
import axios, {AxiosInstance} from "axios"
54
import {ParsedUrlQuery, stringify} from "querystring"
65
import {handleAxiosError} from "./errorUtils"
@@ -13,7 +12,7 @@ export function buildApigeeHeaders(apigeeAccessToken: string, roleId: string, or
1312
return {
1413
Authorization: `Bearer ${apigeeAccessToken}`,
1514
"nhsd-session-urid": roleId,
16-
"x-request-id": uuidv4(),
15+
"x-request-id": crypto.randomUUID(),
1716
"nhsd-session-jobrole": roleId,
1817
"nhsd-identity-uuid": roleId, //TODO potentially remove this line
1918
"nhsd-organization-uuid": orgCode,
@@ -50,7 +49,7 @@ export function constructSignedJWTBody(
5049
aud: idpTokenPath,
5150
iat: current_time,
5251
exp: expiration_time,
53-
jti: uuidv4()
52+
jti: crypto.randomUUID()
5453
}
5554

5655
const signOptions: jwt.SignOptions = {

packages/common/authFunctions/tests/test_apigeeUtils.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import {Logger} from "@aws-lambda-powertools/logger"
66

77
jest.mock("axios")
88
jest.mock("jsonwebtoken")
9-
jest.unstable_mockModule("uuid", () => ({
10-
v4: jest.fn(() => "test-uuid")
11-
}))
129

1310
const mockGetTokenMapping = jest.fn()
1411
const mockUpdateTokenMapping = jest.fn()
@@ -33,7 +30,13 @@ const {exchangeTokenForApigeeAccessToken,
3330
describe("apigeeUtils", () => {
3431
const mockAxiosPost = jest.fn();
3532
(axios.post as unknown as jest.Mock) = mockAxiosPost
33+
beforeAll(() => {
34+
jest.spyOn(global.crypto, "randomUUID").mockReturnValue("test-uuid-in-uuid-format")
35+
})
3636

37+
afterAll(() => {
38+
jest.restoreAllMocks()
39+
})
3740
beforeEach(() => {
3841
jest.clearAllMocks()
3942
})
@@ -52,7 +55,7 @@ describe("apigeeUtils", () => {
5255
"nhsd-identity-uuid": roleId,
5356
"nhsd-session-jobrole": roleId,
5457
"x-correlation-id": correlationId,
55-
"x-request-id": "test-uuid"
58+
"x-request-id": "test-uuid-in-uuid-format"
5659
}
5760

5861
const headers = buildApigeeHeaders(apigeeAccessToken, roleId, orgCode, correlationId)

packages/common/lambdaUtils/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"@aws-lambda-powertools/logger": "^2.27.0",
1818
"@cpt-ui-common/common-types": "^1.0.0",
1919
"aws-lambda": "^1.0.7",
20-
"axios": "^1.12.2",
21-
"uuid": "^11.1.0"
20+
"axios": "^1.12.2"
2221
}
2322
}

packages/common/lambdaUtils/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {APIGatewayProxyEvent} from "aws-lambda"
2-
import {v4 as uuidv4} from "uuid"
32
import {Logger} from "@aws-lambda-powertools/logger"
43
import {Headers} from "@cpt-ui-common/common-types"
54

@@ -18,7 +17,7 @@ export type InboundEventValues = {
1817
correlationId: string
1918
}
2019
export const extractInboundEventValues = (event: APIGatewayProxyEvent): InboundEventValues => {
21-
const correlationId = event.headers["x-correlation-id"] || uuidv4()
20+
const correlationId = event.headers["x-correlation-id"] || crypto.randomUUID()
2221
return {
2322
loggerKeys: {
2423
"apigw-request-id": event.requestContext?.requestId,

0 commit comments

Comments
 (0)