diff --git a/serverless/src/samlCallback/__tests__/handler.test.js b/serverless/src/samlCallback/__tests__/handler.test.js index d12d15c1d..cd67a5358 100644 --- a/serverless/src/samlCallback/__tests__/handler.test.js +++ b/serverless/src/samlCallback/__tests__/handler.test.js @@ -84,8 +84,7 @@ describe('samlCallback', () => { apiHost: 'https://mmt.localtest.earthdata.nasa.gov/dev', graphQlHost: 'http://localhost:3013/dev/api', cmrHost: 'http://localhost:4000', - version: 'sit', - env: 'development' + version: 'sit' })) const response = await samlCallback(event) @@ -120,8 +119,7 @@ describe('samlCallback', () => { mmtHost: 'https://mmt.localtest.earthdata.nasa.gov', apiHost: 'https://mmt.localtest.earthdata.nasa.gov/dev', graphQlHost: 'http://localhost:3013/dev/api', - cmrHost: 'http://localhost:4000', - env: 'development' + cmrHost: 'http://localhost:4000' })) const response = await samlCallback(event) diff --git a/serverless/src/samlRefreshToken/__tests__/handler.test.js b/serverless/src/samlRefreshToken/__tests__/handler.test.js index ede35b259..b929a4686 100644 --- a/serverless/src/samlRefreshToken/__tests__/handler.test.js +++ b/serverless/src/samlRefreshToken/__tests__/handler.test.js @@ -7,8 +7,7 @@ vi.spyOn(getConfig, 'getApplicationConfig').mockImplementation(() => ({ apiHost: 'https://mmt.localtest.earthdata.nasa.gov/dev', graphQlHost: 'http://localhost:3013/dev/api', cmrHost: 'http://localhost:4000', - version: 'sit', - env: 'development' + version: 'sit' })) vi.mock('jsonwebtoken', async () => ({ diff --git a/serverless/src/utils/__tests__/createCookie.test.js b/serverless/src/utils/__tests__/createCookie.test.js index f8ef4142e..c36801a80 100644 --- a/serverless/src/utils/__tests__/createCookie.test.js +++ b/serverless/src/utils/__tests__/createCookie.test.js @@ -1,12 +1,5 @@ import createCookie from '../createCookie' -vi.mock('../../../../../../sharedUtils/getConfig', async () => ({ - ...await vi.importActual('../../../../../../sharedUtils/getConfig'), - getApplicationConfig: vi.fn(() => ({ - env: 'development' - })) -})) - describe('createCookie', () => { const OLD_ENV = process.env diff --git a/serverless/src/utils/createCookie.js b/serverless/src/utils/createCookie.js index ef929f7fc..4e5ee74e4 100644 --- a/serverless/src/utils/createCookie.js +++ b/serverless/src/utils/createCookie.js @@ -1,19 +1,17 @@ -import { getApplicationConfig } from '../../../sharedUtils/getConfig' +import MMT_COOKIE from '../../../static/src/js/constants/mmtCookie' /** * Returns the cookie string with the provided JWT * @param {String} jwt JWT to use for the cookie value */ const createCookie = (jwt) => { - const { env } = getApplicationConfig() - const { COOKIE_DOMAIN, IS_OFFLINE, JWT_VALID_TIME } = process.env - let cookie = `_mmt_jwt_${env}=${jwt}; SameSite=Strict; Path=/; Domain=${COOKIE_DOMAIN}; Max-Age=${JWT_VALID_TIME};` + let cookie = `${MMT_COOKIE}=${jwt}; SameSite=Strict; Path=/; Domain=${COOKIE_DOMAIN}; Max-Age=${JWT_VALID_TIME};` if (!IS_OFFLINE) { cookie += ' Secure;' } diff --git a/static/src/js/components/TemplateForm/__tests__/TemplateForm.test.jsx b/static/src/js/components/TemplateForm/__tests__/TemplateForm.test.jsx index c2db32e48..d8ac73099 100644 --- a/static/src/js/components/TemplateForm/__tests__/TemplateForm.test.jsx +++ b/static/src/js/components/TemplateForm/__tests__/TemplateForm.test.jsx @@ -563,7 +563,7 @@ describe('TemplateForm', () => { }, nativeId: 'MMT_mock-uuid', providerId: 'MMT_2', - ummVersion: '1.18.2' + ummVersion: `${ummCVersion}` } }, error: new Error('An error occurred') diff --git a/static/src/js/components/TemplateList/__tests__/TemplateList.test.jsx b/static/src/js/components/TemplateList/__tests__/TemplateList.test.jsx index 24dee0233..65ce63b63 100644 --- a/static/src/js/components/TemplateList/__tests__/TemplateList.test.jsx +++ b/static/src/js/components/TemplateList/__tests__/TemplateList.test.jsx @@ -11,12 +11,8 @@ import deleteTemplate from '@/js/utils/deleteTemplate' import NotificationsContext from '@/js/context/NotificationsContext' import MMT_COOKIE from '@/js/constants/mmtCookie' -import { getApplicationConfig } from '../../../../../../sharedUtils/getConfig' - import TemplateList from '../TemplateList' -const { env } = getApplicationConfig() - vi.mock('@/js/utils/deleteTemplate') vi.mock('@/js/utils/errorLogger') vi.mock('@/js/utils/getTemplates') @@ -25,7 +21,7 @@ vi.mock('react-cookie', async () => ({ ...await vi.importActual('react-cookie'), useCookies: vi.fn().mockImplementation(() => ([ { - [`${MMT_COOKIE}_${env}`]: 'mock-jwt' + [MMT_COOKIE]: 'mock-jwt' }, vi.fn(), vi.fn() diff --git a/static/src/js/constants/mmtCookie.js b/static/src/js/constants/mmtCookie.js index 64ca71d20..ef0843e2e 100644 --- a/static/src/js/constants/mmtCookie.js +++ b/static/src/js/constants/mmtCookie.js @@ -1,6 +1,10 @@ +import { getApplicationConfig } from '../../../../sharedUtils/getConfig' + /** * This is the name of the cookie that MMT uses. */ -const MMT_COOKIE = '_mmt_jwt' +const { env } = getApplicationConfig() + +const MMT_COOKIE = `_mmt_jwt_${env}` export default MMT_COOKIE diff --git a/static/src/js/hooks/useMMTCookie.js b/static/src/js/hooks/useMMTCookie.js index 46fb1840f..1dd79f170 100644 --- a/static/src/js/hooks/useMMTCookie.js +++ b/static/src/js/hooks/useMMTCookie.js @@ -2,21 +2,17 @@ import { useCookies } from 'react-cookie' import MMT_COOKIE from '../constants/mmtCookie' -import { getApplicationConfig } from '../../../../sharedUtils/getConfig' - /** * Returns the cookie value for the MMT auth cookie */ const useMMTCookie = () => { - const { env } = getApplicationConfig() - const [ cookies, setCookie, removeCookie ] = useCookies([MMT_COOKIE]) - const { [`${MMT_COOKIE}_${env}`]: mmtJwt } = cookies + const { [MMT_COOKIE]: mmtJwt } = cookies return { mmtJwt, diff --git a/static/src/js/providers/AuthContextProvider/__tests__/AuthContextProvider.test.jsx b/static/src/js/providers/AuthContextProvider/__tests__/AuthContextProvider.test.jsx index 86dbca85e..2835fa548 100644 --- a/static/src/js/providers/AuthContextProvider/__tests__/AuthContextProvider.test.jsx +++ b/static/src/js/providers/AuthContextProvider/__tests__/AuthContextProvider.test.jsx @@ -26,8 +26,7 @@ vi.mock('../../../../../../sharedUtils/getConfig', async () => ({ getApplicationConfig: vi.fn(() => ({ apiHost: 'http://test.com/dev', cookieDomain: 'example.com', - tokenValidTime: '900', - env: 'development' + tokenValidTime: '900' })) })) @@ -124,7 +123,7 @@ describe('AuthContextProvider component', () => { test('shows the name', async () => { useCookies.mockImplementation(() => ([ { - [`${MMT_COOKIE}_development`]: 'mock-jwt' + [MMT_COOKIE]: 'mock-jwt' }, vi.fn(), vi.fn() @@ -153,7 +152,7 @@ describe('AuthContextProvider component', () => { const setCookie = vi.fn() useCookies.mockImplementation(() => ([ { - [`${MMT_COOKIE}_development`]: 'mock-jwt' + [MMT_COOKIE]: 'mock-jwt' }, setCookie, vi.fn() @@ -178,7 +177,7 @@ describe('AuthContextProvider component', () => { const setCookie = vi.fn() useCookies.mockImplementation(() => ([ { - [`${MMT_COOKIE}_development`]: 'mock-jwt' + [MMT_COOKIE]: 'mock-jwt' }, setCookie, vi.fn() @@ -211,7 +210,7 @@ describe('AuthContextProvider component', () => { jwt.decode.mockImplementation(() => { throw new Error('Error decoding jwt') }) useCookies.mockImplementation(() => ([ { - [`${MMT_COOKIE}_development`]: 'mock-jwt' + [MMT_COOKIE]: 'mock-jwt' }, vi.fn(), vi.fn()