Merged PR 2318: auth stabilisation: extract shared myportal auth guard helper
auth stabilisation: extract shared myportal auth guard helper ntroduces a small shared SSR helper (resolveMyPortalAuthContext) to standardize common myportal auth/session guards (session presence, session user identity, and pinsUser cookie) with preserved reason-coded diagnostics and signin redirect behavior. Migrates exactly two loaders (pages/myportal/searchresults.js, pages/myportal/addresssearchresults.js) to use the helper while keeping loader-specific UPSTREAM_FAILURE and CONTACT_LOOKUP_FAILED logic unchanged. Related work items: #23020
This commit is contained in:
@@ -48,6 +48,11 @@ const loadMyPortalAddressSearchResultsPage = (overrides = {}) => {
|
||||
setWatchedCases: () => ({}),
|
||||
setWatchedCasesDetails: () => ({}),
|
||||
setLoggedInUserId: () => ({}),
|
||||
resolveMyPortalAuthContext: async (ctx) => ({
|
||||
ok: true,
|
||||
session: { user: { id: "u-1", email: "x@y.z" } },
|
||||
pinsUser: ctx?.req?.cookies?.pinsUser
|
||||
}),
|
||||
wrapper: {
|
||||
getServerSideProps: (factory) => async (ctx) => {
|
||||
const store = { dispatch: () => {} };
|
||||
@@ -65,7 +70,10 @@ const loadMyPortalAddressSearchResultsPage = (overrides = {}) => {
|
||||
|
||||
test("addresssearchresults redirects to signin when session is missing", async () => {
|
||||
const mod = loadMyPortalAddressSearchResultsPage({
|
||||
getSession: async () => null
|
||||
resolveMyPortalAuthContext: async () => ({
|
||||
ok: false,
|
||||
redirect: { destination: "/auth/signin", permanent: false }
|
||||
})
|
||||
});
|
||||
const result = await mod.getServerSideProps({
|
||||
query: { q: "CAS" },
|
||||
@@ -76,7 +84,10 @@ test("addresssearchresults redirects to signin when session is missing", async (
|
||||
|
||||
test("addresssearchresults redirects to signin when session user identity is missing", async () => {
|
||||
const mod = loadMyPortalAddressSearchResultsPage({
|
||||
getSession: async () => ({ user: { id: "u-1" } })
|
||||
resolveMyPortalAuthContext: async () => ({
|
||||
ok: false,
|
||||
redirect: { destination: "/auth/signin", permanent: false }
|
||||
})
|
||||
});
|
||||
const result = await mod.getServerSideProps({
|
||||
query: { q: "CAS" },
|
||||
@@ -86,7 +97,12 @@ test("addresssearchresults redirects to signin when session user identity is mis
|
||||
});
|
||||
|
||||
test("addresssearchresults redirects to signin when pinsUser cookie is missing", async () => {
|
||||
const mod = loadMyPortalAddressSearchResultsPage();
|
||||
const mod = loadMyPortalAddressSearchResultsPage({
|
||||
resolveMyPortalAuthContext: async () => ({
|
||||
ok: false,
|
||||
redirect: { destination: "/auth/signin", permanent: false }
|
||||
})
|
||||
});
|
||||
const result = await mod.getServerSideProps({
|
||||
query: { q: "CAS" },
|
||||
req: { cookies: {} }
|
||||
|
||||
@@ -46,6 +46,11 @@ const loadMyPortalSearchResultsPage = (overrides = {}) => {
|
||||
setWatchedCasesDetails: () => ({}),
|
||||
setLoggedInUserId: () => ({}),
|
||||
setContainerID: () => ({}),
|
||||
resolveMyPortalAuthContext: async (ctx) => ({
|
||||
ok: true,
|
||||
session: { user: { id: "u-1", email: "test@example.com" } },
|
||||
pinsUser: ctx?.req?.cookies?.pinsUser
|
||||
}),
|
||||
wrapper: {
|
||||
getServerSideProps: (factory) => async (ctx) => {
|
||||
const store = { dispatch: () => {} };
|
||||
@@ -62,7 +67,12 @@ const loadMyPortalSearchResultsPage = (overrides = {}) => {
|
||||
};
|
||||
|
||||
test("myportal searchresults redirects to signin when session is missing", async () => {
|
||||
const mod = loadMyPortalSearchResultsPage({ getSession: async () => null });
|
||||
const mod = loadMyPortalSearchResultsPage({
|
||||
resolveMyPortalAuthContext: async () => ({
|
||||
ok: false,
|
||||
redirect: { destination: "/auth/signin", permanent: false }
|
||||
})
|
||||
});
|
||||
const result = await mod.getServerSideProps({
|
||||
query: { q: "CAS" },
|
||||
req: { cookies: { pinsUser: "contact-1" } }
|
||||
@@ -72,7 +82,10 @@ test("myportal searchresults redirects to signin when session is missing", async
|
||||
|
||||
test("myportal searchresults redirects to signin when session user identity is missing", async () => {
|
||||
const mod = loadMyPortalSearchResultsPage({
|
||||
getSession: async () => ({ user: { id: "u-1" } })
|
||||
resolveMyPortalAuthContext: async () => ({
|
||||
ok: false,
|
||||
redirect: { destination: "/auth/signin", permanent: false }
|
||||
})
|
||||
});
|
||||
const result = await mod.getServerSideProps({
|
||||
query: { q: "CAS" },
|
||||
@@ -82,7 +95,12 @@ test("myportal searchresults redirects to signin when session user identity is m
|
||||
});
|
||||
|
||||
test("myportal searchresults redirects to signin when pinsUser cookie is missing", async () => {
|
||||
const mod = loadMyPortalSearchResultsPage();
|
||||
const mod = loadMyPortalSearchResultsPage({
|
||||
resolveMyPortalAuthContext: async () => ({
|
||||
ok: false,
|
||||
redirect: { destination: "/auth/signin", permanent: false }
|
||||
})
|
||||
});
|
||||
const result = await mod.getServerSideProps({
|
||||
query: { q: "CAS" },
|
||||
req: { cookies: {} }
|
||||
|
||||
Reference in New Issue
Block a user