-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(GAP-1984) Adds Navbar for authenticated users #71
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a197def
initial
john-tco 95288dc
import
john-tco 6249ffd
amend import
john-tco 160e455
add a couple of mocks
john-tco 09eda8b
rm
john-tco c5b3819
add logout tests
john-tco 85432eb
assert on axios
john-tco 6c73279
add back button, rm breadcrumbs
john-tco a5ea5e1
run prettier
john-tco b24ee11
rm
john-tco b9f5127
setup auth context, mock next-config in all tests
john-tco 34dd6ea
hide sign out when OL disabled
john-tco c44534d
useauth
john-tco f941e1c
fix predicate
john-tco 8c17c0a
get ol from runtimeConfig
john-tco 34d3a08
refactor env vars - use useContext
john-tco 19a4a4c
merge develop
john-tco 383ad73
update env example
john-tco 0fe5053
update env example
john-tco e2ff713
update env example
john-tco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import '@testing-library/jest-dom'; | ||
import { merge } from 'lodash'; | ||
import Logout from '../../../pages/api/logout'; | ||
import { getSessionIdFromCookies } from '../../../src/utils/session'; | ||
import axios from 'axios'; | ||
|
||
jest.mock('../../../src/utils/session'); | ||
jest.mock('axios'); | ||
|
||
const mockedRedirect = jest.fn(); | ||
const mockedSetHeader = jest.fn(); | ||
const mockedSend = jest.fn(); | ||
|
||
const req = (overrides = {}) => | ||
merge( | ||
{ | ||
headers: { | ||
referer: `/referer`, | ||
}, | ||
cookies: { sessionCookieName: 'testSessionId' }, | ||
}, | ||
overrides, | ||
); | ||
|
||
const res = (overrides = {}) => | ||
merge( | ||
{ | ||
redirect: mockedRedirect, | ||
setHeader: mockedSetHeader, | ||
send: mockedSend, | ||
}, | ||
overrides, | ||
); | ||
|
||
describe('Logout page', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
process.env.ONE_LOGIN_ENABLED = 'false'; | ||
process.env.LOGOUT = 'http://localhost:8082/logout'; | ||
}); | ||
|
||
it('Should clear back-end authentication session if there is session_id cookie available', async () => { | ||
(getSessionIdFromCookies as jest.Mock).mockReturnValue('testSessionId'); | ||
await Logout(req(), res()); | ||
|
||
expect(axios.delete).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Should NOT try to clear back-end authentication session if session_id cookie not available', async () => { | ||
(getSessionIdFromCookies as jest.Mock).mockReturnValue(''); | ||
await Logout(req(), res()); | ||
|
||
expect(axios.delete).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it('Should clear session_id cookie', async () => { | ||
await Logout(req(), res()); | ||
|
||
expect(mockedSetHeader).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Should redirect to login page', async () => { | ||
process.env.V2_LOGOUT_URL = 'http://localhost:8082/logout'; | ||
process.env.LOGOUT_URL = 'http://localhost:8082/logout'; | ||
|
||
await Logout(req(), res()); | ||
|
||
expect(mockedRedirect).toHaveBeenNthCalledWith( | ||
1, | ||
302, | ||
'http://localhost:8082/logout', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,6 @@ jest.mock('../../../src/utils/jwt', () => ({ | |
})), | ||
})); | ||
|
||
jest.mock('next/config', () => { | ||
return jest.fn().mockImplementation(() => { | ||
return { serverRuntimeConfig: {} }; | ||
}); | ||
}); | ||
|
||
const req = { | ||
body: { | ||
email: '[email protected]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,6 @@ module.exports = { | |
sassOptions: { | ||
includePaths: [path.join(__dirname, 'styles')], | ||
}, | ||
|
||
output: 'standalone', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
import { getSessionIdFromCookies } from '../../../src/utils/session'; | ||
import axios from 'axios'; | ||
|
||
const Logout = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const sessionCookie = getSessionIdFromCookies(req); | ||
if (sessionCookie) await logoutAdmin(sessionCookie); | ||
|
||
res.setHeader( | ||
'Set-Cookie', | ||
`session_id=deleted; Path=/; secure; HttpOnly; SameSite=Strict; expires=Thu, 01 Jan 2003 00:00:00 GMT`, | ||
); | ||
res.redirect(302, process.env.V2_LOGOUT_URL); | ||
}; | ||
|
||
const axiosSessionConfig = (sessionId: string) => ({ | ||
withCredentials: true, | ||
headers: { | ||
Cookie: `SESSION=${sessionId};`, | ||
}, | ||
}); | ||
|
||
const logoutAdmin = async (sessionCookie: string) => | ||
axios.delete( | ||
`${process.env.ADMIN_BACKEND_HOST}/logout`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also needs to go in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all fair |
||
axiosSessionConfig(sessionCookie), | ||
); | ||
|
||
export default Logout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add this to
.env.example
as well