Skip to content

Commit

Permalink
Mmt 3936: URS Login/Token Refresh Results in Blank Page (#1327)
Browse files Browse the repository at this point in the history
* MMT-3936: Adding env to cookie

* MMT-3936: Changing to env

* MMT-3936: Made env change on constant

* MMT-3936: Little fixes

* MMT-3936: Moving MMT_COOKIE to sharedConstants

* MMT-3936: Creating new relative path
  • Loading branch information
mandyparson authored Dec 9, 2024
1 parent 94ad25e commit 0aaea5c
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"import/resolver": {
"alias": {
"map": [
[ "@", "./static/src" ]
[ "@", "./static/src" ],
[ "sharedConstants", "./sharedConstants"]
],
"extensions": [
".js",
Expand Down
5 changes: 3 additions & 2 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["static/src/*"]
"@/*": ["static/src/*"],
"sharedConstants/*": ["sharedConstants/*"]
}
},
"include": ["static/src/**/*"]
"include": ["static/src/**/*", "sharedConstants/*"]
}
6 changes: 3 additions & 3 deletions serverless/src/samlCallback/__tests__/handler.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions serverless/src/samlRefreshToken/__tests__/handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('samlRefreshToken', () => {
const { 'Set-Cookie': setCookie } = headers

expect(statusCode).toBe(200)
expect(setCookie).toEqual('_mmt_jwt=new-mock-jwt; SameSite=Strict; Path=/; Domain=.example.com; Max-Age=900; Secure;')
expect(setCookie).toEqual('_mmt_jwt_development=new-mock-jwt; SameSite=Strict; Path=/; Domain=.example.com; Max-Age=900; Secure;')

expect(createJwt).toHaveBeenCalledTimes(1)
expect(createJwt).toHaveBeenCalledWith('refresh_token', { mock: 'profile' })
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('samlRefreshToken', () => {
const { 'Set-Cookie': setCookie } = headers

expect(statusCode).toBe(200)
expect(setCookie).toEqual('_mmt_jwt=new-mock-jwt; SameSite=Strict; Path=/; Domain=.example.com; Max-Age=900;')
expect(setCookie).toEqual('_mmt_jwt_development=new-mock-jwt; SameSite=Strict; Path=/; Domain=.example.com; Max-Age=900;')

expect(createJwt).toHaveBeenCalledTimes(1)
expect(createJwt).toHaveBeenCalledWith('mock-token', { mock: 'profile' })
Expand Down
4 changes: 2 additions & 2 deletions serverless/src/utils/__tests__/createCookie.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ describe('createCookie', () => {

describe('when not running locally', () => {
test('returns the cookie string', () => {
expect(createCookie('mock-jwt')).toEqual('_mmt_jwt=mock-jwt; SameSite=Strict; Path=/; Domain=.example.com; Max-Age=900; Secure;')
expect(createCookie('mock-jwt')).toEqual('_mmt_jwt_development=mock-jwt; SameSite=Strict; Path=/; Domain=.example.com; Max-Age=900; Secure;')
})
})

describe('when running locally', () => {
test('returns the cookie string', () => {
process.env.IS_OFFLINE = true

expect(createCookie('mock-jwt')).toEqual('_mmt_jwt=mock-jwt; SameSite=Strict; Path=/; Domain=.example.com; Max-Age=900;')
expect(createCookie('mock-jwt')).toEqual('_mmt_jwt_development=mock-jwt; SameSite=Strict; Path=/; Domain=.example.com; Max-Age=900;')
})
})
})
4 changes: 3 additions & 1 deletion serverless/src/utils/createCookie.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import MMT_COOKIE from 'sharedConstants/mmtCookie'

/**
* Returns the cookie string with the provided JWT
* @param {String} jwt JWT to use for the cookie value
Expand All @@ -9,7 +11,7 @@ const createCookie = (jwt) => {
JWT_VALID_TIME
} = process.env

let cookie = `_mmt_jwt=${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;'
}
Expand Down
10 changes: 10 additions & 0 deletions sharedConstants/mmtCookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getApplicationConfig } from '../sharedUtils/getConfig'

/**
* This is the name of the cookie that MMT uses.
*/
const { env } = getApplicationConfig()

const MMT_COOKIE = `_mmt_jwt_${env}`

export default MMT_COOKIE
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ describe('TemplateForm', () => {
},
nativeId: 'MMT_mock-uuid',
providerId: 'MMT_2',
ummVersion: '1.18.1'
ummVersion: `${ummCVersion}`
}
},
error: new Error('An error occurred')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import errorLogger from '@/js/utils/errorLogger'
import getTemplates from '@/js/utils/getTemplates'
import deleteTemplate from '@/js/utils/deleteTemplate'
import NotificationsContext from '@/js/context/NotificationsContext'
import MMT_COOKIE from '@/js/constants/mmtCookie'
import MMT_COOKIE from 'sharedConstants/mmtCookie'

import TemplateList from '../TemplateList'

Expand Down
6 changes: 0 additions & 6 deletions static/src/js/constants/mmtCookie.js

This file was deleted.

2 changes: 1 addition & 1 deletion static/src/js/hooks/useMMTCookie.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCookies } from 'react-cookie'

import MMT_COOKIE from '../constants/mmtCookie'
import MMT_COOKIE from 'sharedConstants/mmtCookie'

/**
* Returns the cookie value for the MMT auth cookie
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { useIdle } from '@uidotdev/usehooks'

import AuthContext from '@/js/context/AuthContext'

import MMT_COOKIE from '@/js/constants/mmtCookie'

import useMMTCookie from '@/js/hooks/useMMTCookie'

import errorLogger from '@/js/utils/errorLogger'
import refreshToken from '@/js/utils/refreshToken'

import MMT_COOKIE from 'sharedConstants/mmtCookie'

import { getApplicationConfig } from '../../../../../sharedUtils/getConfig'

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import refreshToken from '@/js/utils/refreshToken'

import NotificationsContextProvider from '@/js/providers/NotificationsContextProvider/NotificationsContextProvider'

import MMT_COOKIE from '@/js/constants/mmtCookie'

import MMT_COOKIE from 'sharedConstants/mmtCookie'
import AuthContextProvider from '../AuthContextProvider'

vi.mock('@/js/utils/errorLogger')
Expand Down
4 changes: 4 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default defineConfig({
{
find: '@',
replacement: path.resolve(__dirname, 'static/src')
},
{
find: 'sharedConstants',
replacement: path.resolve(__dirname, 'sharedConstants')
}
]
},
Expand Down

0 comments on commit 0aaea5c

Please sign in to comment.