Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const authenticationConcurrentAwareMiddleware = (
logger.info("A session is active but does not match the requestors sessionId", {username, sessionId})
invalidSessionCause = "ConcurrentSession"
} else {
logger.error("Request token invalid. No matching session found.", {
logger.warn("Request token invalid. No matching session found.", {
tokenMappingSessionId,
sessionManagementSessionId
})
Expand All @@ -88,6 +88,7 @@ export const authenticationConcurrentAwareMiddleware = (
}
} catch (error) {
logger.error("Authentication failed returning restart login prompt", {error})
invalidSessionCause = "InvalidSession"
}

// Handle timeout responses
Expand Down
8 changes: 2 additions & 6 deletions packages/common/authFunctions/src/authenticationMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,13 @@ export const authenticationMiddleware = ({
invalidSessionCause = "Timeout"
authenticatedResult = null
}
} else if (tokenMappingItem !== undefined) {
} else {
logger.info("A session is active but does not match the requestors sessionId", {username, sessionId})
invalidSessionCause = "ConcurrentSession"
} else {
logger.error("Request token invalid. No matching session found.", {
tokenMappingSessionId
})
invalidSessionCause = "InvalidSession"
}
} catch (error) {
logger.error("Authentication failed returning restart login prompt", {error})
invalidSessionCause = "InvalidSession"
}
if (!authenticatedResult || "isTimeout" in authenticatedResult) {
request.earlyResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ describe("authenticationConcurrentAwareMiddleware", () => {
statusCode: 401,
body: JSON.stringify({
message: "Session expired or invalid. Please log in again.",
restartLogin: true
restartLogin: true,
invalidSessionCause: "InvalidSession"
})
})
expect(result).toEqual(mockRequest.earlyResponse)
Expand Down Expand Up @@ -483,7 +484,8 @@ describe("authenticationConcurrentAwareMiddleware", () => {
statusCode: 401,
body: JSON.stringify({
message: "Session expired or invalid. Please log in again.",
restartLogin: true
restartLogin: true,
invalidSessionCause: "InvalidSession"
})
})
expect(result).toEqual(mockRequest.earlyResponse)
Expand Down Expand Up @@ -516,7 +518,8 @@ describe("authenticationConcurrentAwareMiddleware", () => {
statusCode: 401,
body: JSON.stringify({
message: "Session expired or invalid. Please log in again.",
restartLogin: true
restartLogin: true,
invalidSessionCause: "InvalidSession"
})
})
expect(result).toEqual(mockRequest.earlyResponse)
Expand Down Expand Up @@ -553,7 +556,8 @@ describe("authenticationConcurrentAwareMiddleware", () => {
statusCode: 401,
body: JSON.stringify({
message: "Session expired or invalid. Please log in again.",
restartLogin: true
restartLogin: true,
invalidSessionCause: "InvalidSession"
})
})
expect(result).toEqual(mockRequest.earlyResponse)
Expand Down Expand Up @@ -585,7 +589,8 @@ describe("authenticationConcurrentAwareMiddleware", () => {
statusCode: 401,
body: JSON.stringify({
message: "Session expired or invalid. Please log in again.",
restartLogin: true
restartLogin: true,
invalidSessionCause: "InvalidSession"
})
})
expect(result).toEqual(mockRequest.earlyResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ describe("authenticationMiddleware", () => {
expect(result).toEqual(mockRequest.earlyResponse)
})

it("should return 401 when token mapping is undefined", async () => {
it("should return 401 when getTokenMapping throws an error", async () => {
// Arrange
const username = "test-user"
const sessionId = "test-session-id"

mockGetUsernameFromEvent.mockReturnValue(username)
mockGetSessionIdFromEvent.mockReturnValue(sessionId)
mockGetTokenMapping.mockResolvedValue(undefined)
mockGetTokenMapping.mockRejectedValue(new Error("No matching session found"))

const middleware = authenticationMiddleware({axiosInstance, ddbClient, authOptions, logger})

Expand Down Expand Up @@ -230,7 +230,8 @@ describe("authenticationMiddleware", () => {
statusCode: 401,
body: JSON.stringify({
message: "Session expired or invalid. Please log in again.",
restartLogin: true
restartLogin: true,
invalidSessionCause: "InvalidSession"
})
})
expect(result).toEqual(mockRequest.earlyResponse)
Expand Down Expand Up @@ -301,7 +302,8 @@ describe("authenticationMiddleware", () => {
statusCode: 401,
body: JSON.stringify({
message: "Session expired or invalid. Please log in again.",
restartLogin: true
restartLogin: true,
invalidSessionCause: "InvalidSession"
})
})
expect(result).toEqual(mockRequest.earlyResponse)
Expand Down Expand Up @@ -331,7 +333,8 @@ describe("authenticationMiddleware", () => {
statusCode: 401,
body: JSON.stringify({
message: "Session expired or invalid. Please log in again.",
restartLogin: true
restartLogin: true,
invalidSessionCause: "InvalidSession"
})
})
expect(result).toEqual(mockRequest.earlyResponse)
Expand Down Expand Up @@ -364,7 +367,8 @@ describe("authenticationMiddleware", () => {
statusCode: 401,
body: JSON.stringify({
message: "Session expired or invalid. Please log in again.",
restartLogin: true
restartLogin: true,
invalidSessionCause: "InvalidSession"
})
})
expect(result).toEqual(mockRequest.earlyResponse)
Expand Down
5 changes: 2 additions & 3 deletions packages/cpt-ui/__tests__/PrescriptionListPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,8 @@ describe("PrescriptionListPage", () => {
expect(mockNavigate).toHaveBeenCalledWith(FRONTEND_PATHS.NO_PRESCRIPTIONS_FOUND)
})

expect(logger.error).toHaveBeenCalledWith(
"A patient was returned, but they do not have any prescriptions.",
emptyResponse
expect(logger.info).toHaveBeenCalledWith(
"A patient was returned, but they do not have any prescriptions."
)
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/cpt-ui/src/helpers/userInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const getTrackerUserInfo = async (): Promise<TrackerUserInfoResult> => {
}

if (!invalidSessionCause) {
logger.error("Error fetching tracker user info:", err)
logger.warn("Error fetching tracker user info:", err)
} else {
logger.warn("trackerUserInfo triggered restart login due to:", invalidSessionCause)
}
Expand Down
5 changes: 2 additions & 3 deletions packages/cpt-ui/src/pages/PrescriptionListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ export default function PrescriptionListPage() {
searchResults.pastPrescriptions.length === 0 &&
searchResults.futurePrescriptions.length === 0
) {
logger.error(
"A patient was returned, but they do not have any prescriptions.",
searchResults
logger.info(
"A patient was returned, but they do not have any prescriptions."
)
setPatientDetails(searchResults.patient)
setPatientFallback(searchResults.patientFallback)
Expand Down
Loading